- * %PATTERN% this method's pattern - * %TYPE% this method's type - * %PARAMNAME- */ - String body; - /** true if body matching should be done against method body stripped of comments. */ - boolean ignoreComments; - /** - * value of "parent property", which is the property of the field or method executing this rule. - * If this is the top level rule (not being called by another rule to associate methods matching this - * rule with the parent), then there is no parent property. - */ - final String parentProperty; - - public MethodSpec(String parentProperty) { - this.parentProperty = parentProperty; - } - - public String getPropertyPattern() { - return propertyPattern; - } - - public void setPropertyPattern(String propertyPattern) { - this.propertyPattern = propertyPattern; - } - - public int getPropertyGroup() { - return propertyGroup; - } - - public void setPropertyGroup(int propertyGroup) { - this.propertyGroup = propertyGroup; - } - - public boolean isLowercaseFirstLetterOfProperty() { - return lowercaseFirstLetterOfProperty; - } - - public void setLowercaseFirstLetterOfProperty(boolean lowercaseFirstLetterOfProperty) { - this.lowercaseFirstLetterOfProperty = lowercaseFirstLetterOfProperty; - } - - public boolean isPropertyMustMatchField() { - return propertyMustMatchField; - } - - public void setPropertyMustMatchField(boolean propertyMustMatchField) { - this.propertyMustMatchField = propertyMustMatchField; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public boolean isIgnoreComments() { - return ignoreComments; - } - - public void setIgnoreComments(boolean ignoreComments) { - this.ignoreComments = ignoreComments; - } - - boolean isMatch() { - return false; // todo - } - - private JFormattedTextField getIntField(int initialValue) { - final NumberFormat integerInstance = NumberFormat.getIntegerInstance(); - integerInstance.setMaximumIntegerDigits(2); - integerInstance.setMinimumIntegerDigits(1); - final JFormattedTextField intField = new JFormattedTextField(integerInstance); - intField.setValue(new Integer("88")); - final Dimension d = intField.getPreferredSize(); - d.width += 3; - intField.setPreferredSize(d); - intField.setValue(initialValue); - intField.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); - return intField; - } - - public JPanel getPanel() { - JPanel panel = new JPanel(new GridBagLayout()); - Constraints constraints = new Constraints(); - constraints.insets = new Insets(3, 3, 3, 3); - JLabel propertyPatternLabel = new JLabel("Property pattern:"); - propertyPatternLabel.setToolTipText("Regex pattern which method name must match; " + - "parenthesize portion which will be regarded as the method's property" + - ", e.g. \"(get|is|has)([A-Z]\\w*)\""); - panel.add(propertyPatternLabel, constraints.firstCol()); - constraints.fill = GridBagConstraints.HORIZONTAL; - final JTextField propertyPatternField = new JTextField(this.propertyPattern); - propertyPatternField.getDocument().addDocumentListener( - new DocumentAdapter() { - protected void textChanged(DocumentEvent event) { - propertyPattern = propertyPatternField.getText(); - } - } - ); - panel.add(propertyPatternField, constraints.weightedLastCol(0.5)); - constraints.newRow(); - constraints.fill = GridBagConstraints.NONE; - final JLabel propertyGroupLabel = new JLabel("Property group number:"); - propertyGroupLabel.setToolTipText("Regular expression parenthesized group corresponding to the property name"); - panel.add(propertyGroupLabel, constraints.firstCol()); - final JFormattedTextField propertyGroupField = getIntField(propertyGroup); - panel.add(propertyGroupField, constraints.nextCol()); - constraints.newRow(); - JCheckBox lowerCase = new JCheckBox("Lowercase first letter of property"); - lowerCase.setToolTipText("If selected, lower cases the first letter of the property found in the regular expression"); - panel.add(lowerCase, constraints.lastCol()); - constraints.newRow(); - JCheckBox mustMatch = new JCheckBox("Property must match field name"); - mustMatch.setToolTipText("If selected, the property name derived from the regular expression must match the " + - "name of a field in the same class as the method; if no such field exists, the " + - "method will not match the rule"); - panel.add(mustMatch, constraints.lastCol()); -// propertyGroupField.get - constraints.newRow(); - JLabel bodyLabel = new JLabel("Body:"); - bodyLabel.setToolTipText("Regex pattern for method body (excluding comments);\n" + - "use \"%FN%\" for field name, \"%P1%\" for param 1, etc."); - constraints.fill = GridBagConstraints.NONE; - panel.add(bodyLabel, constraints.firstCol()); - JCheckBox stripComments = new JCheckBox("Strip comments"); - stripComments.setToolTipText("If selected, comments will be stripped from the method body before attempting" + - " to match the supplied expression"); - panel.add(stripComments, constraints.lastCol()); - constraints.weightedLastRow(); - constraints.fill = GridBagConstraints.BOTH; - JTextArea body = new JTextArea(4, 40); - JScrollPane sp = new JScrollPane(body); - panel.add(sp, constraints.weightedLastCol()); - - return panel; - } - - public MethodSpec deepcopy() { - MethodSpec result = new MethodSpec(parentProperty); - result.body = body; - result.ignoreComments = ignoreComments; - result.lowercaseFirstLetterOfProperty = lowercaseFirstLetterOfProperty; - result.propertyGroup = propertyGroup; - result.propertyMustMatchField = propertyMustMatchField; - result.propertyPattern = propertyPattern; - result.body = body; - return result; - } - - public static void main(String[] args) { - MethodSpec ms = new MethodSpec(null); - final JDialog frame = new JDialog((Frame)null, "SwingApplication"); - final GridBagConstraints constraints = new GridBagConstraints(); - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.fill = GridBagConstraints.BOTH; - constraints.weightx = 1.0d; - constraints.weighty = 1.0d; - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.gridx = 0; - constraints.gridy = 0; - frame.getContentPane().setLayout(new GridBagLayout()); - frame.getContentPane().add(ms.getPanel(), constraints); - //Finish setting up the frame, and show it. - frame.pack(); - frame.setResizable(true); - frame.setModal(true); - frame.setVisible(true); - } -} \ No newline at end of file diff --git a/plugins/rearranger/src/com/wrq/rearranger/configuration/RearrangerSettingsPanel.java b/plugins/rearranger/src/com/wrq/rearranger/configuration/RearrangerSettingsPanel.java deleted file mode 100644 index 75a340fa150f..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/configuration/RearrangerSettingsPanel.java +++ /dev/null @@ -1,566 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.configuration; - -import com.wrq.rearranger.Rearranger; -import com.wrq.rearranger.settings.CommentRule; -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.settings.attributeGroups.AttributeGroup; -import com.wrq.rearranger.settings.attributeGroups.RegexUtil; -import com.wrq.rearranger.util.CommentUtil; -import com.wrq.rearranger.util.Constraints; - -import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.border.TitledBorder; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.PatternSyntaxException; - -/** Code for top level configuration panel. */ -public final class RearrangerSettingsPanel - extends JPanel -{ -// ------------------------------ FIELDS ------------------------------ - - public RearrangerSettings settings; - -// --------------------------- CONSTRUCTORS --------------------------- - - // ---------- START Level 1 ---------- - public RearrangerSettingsPanel(final RearrangerSettings externalSettings) { - RearrangerSettings settings = externalSettings.deepCopy(); - setLayout(new GridBagLayout()); - createSettingsPanel(settings); - } - -// ---------- START Level 2 ---------- - - private void createSettingsPanel(RearrangerSettings settings) { - this.settings = settings; - final Constraints constraints = new Constraints(GridBagConstraints.NORTHWEST); - constraints.fill = GridBagConstraints.BOTH; - constraints.weightedLastRow(); - while (getComponents().length > 0) { - remove(0); - } - add(getSettingsPanel(), constraints.weightedLastCol()); - validate(); - } - -// ---------- START Level 3 ---------- - - private JPanel getSettingsPanel() { - final JPanel containerPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(GridBagConstraints.NORTHWEST); - constraints.fill = GridBagConstraints.BOTH; - constraints.weightedLastRow(); - final JTabbedPane pane = new JTabbedPane(); - final SettingsPane classMemberSettingsPane = new ClassMemberSettingsPane(settings); - final SettingsPane classOrderSettingsPane = new ClassOrderSettingsPane(settings); - final SpacingPane spacingPane = new SpacingPane(settings); - final ExtractedMethodsPane extractedMethodsSettings = new ExtractedMethodsPane(); - final JPanel generalSettingsPane = getGeneralSettingsPane(); - final RelatedByNamePane rbnp = new RelatedByNamePane(settings.getExtractedMethodsSettings().getRbnms()); - pane.addTab( - "Class Member Order", - null, - classMemberSettingsPane.getPane(), - "Options controlling arrangement of fields, methods and inner classes" - ); - pane.addTab( - "Outer Class Order", - null, - classOrderSettingsPane.getPane(), - "Options controlling arrangement of outer classes" - ); - pane.addTab( - "Extracted Methods", - null, - extractedMethodsSettings.getExtractedMethodsPane(settings.getExtractedMethodsSettings()), - "Options controlling arrangement of extracted methods" - ); - pane.addTab( - "General", - null, - generalSettingsPane, - "General options" - ); - pane.addTab( - "Spacing", - null, - spacingPane.getPane(), - "Options controlling number of blank lines before and after braces" - ); - pane.addTab( - "Configuration", - null, - getConfigurationPane(), - "Load, save, clear configuration, or set to default" - ); -// pane.addTab("Related By Name", null, // todo - add when ready; replace "Extracted Methods" pane above -// rbnp.getPane(), "Global definitions for methods related by name (\"getters/setters\")"); - pane.setSelectedIndex(0); - containerPanel.add(pane, constraints.weightedLastCol()); - return containerPanel; - } - -// ---------- START Level 4 ---------- - - private JPanel getGeneralSettingsPane() { - final JPanel gsPanel = new JPanel(new GridBagLayout()); - final Border border = BorderFactory.createEtchedBorder(); - gsPanel.setBorder(border); - final GridBagConstraints constraints = new GridBagConstraints(); - - constraints.fill = GridBagConstraints.BOTH; - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.gridwidth = 1; - constraints.gridheight = 1; - constraints.weightx = 0; - constraints.weighty = 0; - constraints.gridx = constraints.gridy = 0; - constraints.insets = new Insets(5, 5, 0, 0); - final JCheckBox getterSetterBox = new JCheckBox("Keep getters/setters together"); - getterSetterBox.setSelected(settings.isKeepGettersSettersTogether()); - final JCheckBox gettersSettersWithPropertyBox = new JCheckBox("Keep getters/setters with property"); - gettersSettersWithPropertyBox.setSelected(settings.isKeepGettersSettersWithProperty()); - gettersSettersWithPropertyBox.setEnabled(settings.isKeepGettersSettersTogether()); - final JCheckBox overloadedMethodsBox = new JCheckBox("Keep overloaded methods/constructors together"); - overloadedMethodsBox.setSelected(settings.isKeepOverloadedMethodsTogether()); - final JLabel overloadOrderLabel = new JLabel("Ordering of constructors and overloaded methods:"); - final JComboBox overloadOrderBox = new JComboBox( - new String[]{ - "Retain original order", - "Order by number of parameters (ascending)", - "Order by number of parameters (descending)" - } - ); - overloadOrderLabel.setEnabled(settings.isKeepOverloadedMethodsTogether()); - overloadOrderBox.setEnabled(settings.isKeepOverloadedMethodsTogether()); - overloadOrderBox.setSelectedIndex(settings.getOverloadedOrder()); - overloadedMethodsBox.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - settings.setKeepOverloadedMethodsTogether(overloadedMethodsBox.isSelected()); - overloadOrderLabel.setEnabled(settings.isKeepOverloadedMethodsTogether()); - overloadOrderBox.setEnabled(settings.isKeepOverloadedMethodsTogether()); - } - } - ); - final JCheckBox confirmBox = new JCheckBox("Confirm before rearranging"); - confirmBox.setSelected(settings.isAskBeforeRearranging()); - confirmBox.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - settings.setAskBeforeRearranging(confirmBox.isSelected()); - } - } - ); - - final JCheckBox rearrangeInnerClasses = new JCheckBox("Rearrange contents of inner classes"); - rearrangeInnerClasses.setSelected(settings.isRearrangeInnerClasses()); - rearrangeInnerClasses.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - settings.setRearrangeInnerClasses(rearrangeInnerClasses.isSelected()); - } - }); - gsPanel.add(getterSetterBox, constraints); - constraints.gridy++; - gsPanel.add(gettersSettersWithPropertyBox, constraints); - constraints.gridy++; -// constraints.insets = new Insets(0, 0, 0, 0); - gsPanel.add(overloadedMethodsBox, constraints); - constraints.gridy++; - constraints.insets = new Insets(0, 30, 3, 0); - gsPanel.add(overloadOrderLabel, constraints); - constraints.gridy++; - constraints.insets = new Insets(0, 30, 10, 0); - constraints.fill = GridBagConstraints.NONE; - gsPanel.add(overloadOrderBox, constraints); - constraints.fill = GridBagConstraints.BOTH; - constraints.gridy++; - constraints.insets = new Insets(5, 5, 0, 0); - gsPanel.add(confirmBox, constraints); - constraints.gridy++; - gsPanel.add(rearrangeInnerClasses, constraints); - constraints.gridy++; - // - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.fill = GridBagConstraints.BOTH; - constraints.weightx = 1.0d; - constraints.weighty = 0.0d; - final JPanel gsDefaultPane = settings.getDefaultGSDefinition().getGSDefinitionPanel(); - constraints.insets = new Insets(5, 5, 0, 5); - constraints.gridx = 1; - int oldGridy = constraints.gridy; - constraints.gridheight = constraints.gridy; - constraints.gridy = 0; - Border b = gsDefaultPane.getBorder(); - TitledBorder tb = BorderFactory.createTitledBorder(b, "Default Getter/Setter Definition"); - gsDefaultPane.setBorder(tb); - gsPanel.add(gsDefaultPane, constraints); - constraints.gridy = oldGridy; - // - constraints.gridx = 0; - constraints.gridwidth = 1; - constraints.gridheight = 1; - constraints.gridy++; - constraints.weightx = 0; // was 1 - constraints.insets = new Insets(5, 5, 0, 0); - final JLabel commentLabel = new JLabel("Comment pattern:"); - final JButton createPatternButton = new JButton("Generate pattern"); - final JButton verifyCommentsButton = new JButton("Verify comments against pattern"); - gsPanel.add(commentLabel, constraints); - constraints.gridx++; - constraints.anchor = GridBagConstraints.NORTH; - gsPanel.add(createPatternButton, constraints); - constraints.anchor = GridBagConstraints.NORTHEAST; - constraints.gridx++; - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.weightx = 1; // was 0 - constraints.insets = new Insets(5, 0, 0, 5); - constraints.fill = GridBagConstraints.NONE; // new line - gsPanel.add(verifyCommentsButton, constraints); - constraints.fill = GridBagConstraints.BOTH; - constraints.gridx = 0; - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.insets = new Insets(5, 5, 5, 5); - constraints.gridy++; - constraints.weighty = 1.0d; - constraints.gridheight = GridBagConstraints.REMAINDER; - final JTextArea commentArea = new JTextArea(4, 40); - commentArea.setText(settings.getGlobalCommentPattern()); - constraints.gridheight = GridBagConstraints.REMAINDER; - final JScrollPane scrollPane = new JScrollPane(commentArea); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - gsPanel.add(scrollPane, constraints); - - getterSetterBox.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent e) { - settings.setKeepGettersSettersTogether(getterSetterBox.isSelected()); - gettersSettersWithPropertyBox.setEnabled(settings.isKeepGettersSettersTogether()); - } - } - ); - - gettersSettersWithPropertyBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - settings.setKeepGettersSettersWithProperty(gettersSettersWithPropertyBox.isSelected()); - } - }); - - overloadOrderBox.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - settings.setOverloadedOrder(overloadOrderBox.getSelectedIndex()); - } - } - ); - - commentArea.getDocument().addDocumentListener( - new DocumentListener() { - public void changedUpdate(final DocumentEvent e) { - settings.setGlobalCommentPattern(commentArea.getText()); - } - - public void insertUpdate(final DocumentEvent e) { - settings.setGlobalCommentPattern(commentArea.getText()); - } - - public void removeUpdate(final DocumentEvent e) { - settings.setGlobalCommentPattern(commentArea.getText()); - } - } - ); - - createPatternButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - String t = commentArea.getText(); - if (t.length() > 0) { - int result = JOptionPane.showConfirmDialog( - null, "This will replace the existing comment pattern with the generated pattern." + - " Are you sure?", - "Replace existing pattern", - JOptionPane.YES_NO_CANCEL_OPTION - ); - if (result != 0) return; - } - String s = generateCommentPattern(settings); - commentArea.setText(s); - } - } - ); - - verifyCommentsButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkCommentsAgainstGlobalPattern(settings); - } - } - ); - return gsPanel; - } - -// ---------- START Level 5 ---------- - - private String generateCommentPattern(RearrangerSettings settings) { - new CommentUtil(settings); - String result = RegexUtil.combineExpressions(CommentUtil.getCommentStrings()); - return result; - } - - /** - * Compare all comments specified by the user against the global comment pattern. If all match, then - * the global pattern will catch all the user's comments and remove them before rearranging and inserting - * new ones. If any don't match, bring up a dialog box listing them. - * - * @param settings current Rearranger settings. - */ - public void checkCommentsAgainstGlobalPattern(RearrangerSettings settings) { - String pattern = settings.getGlobalCommentPattern(); - if (pattern == null || pattern.trim().length() == 0) { - JOptionPane.showMessageDialog( - null, "No global comment pattern exists!" - , "Verify Comments Against Pattern", - JOptionPane.WARNING_MESSAGE - ); - return; - } - try { - " ".matches(pattern); - } - catch (PatternSyntaxException pse) { - JOptionPane.showMessageDialog( - null, - "Invalid global pattern:" + pse.toString(), - "Verify Comments Against Pattern", - JOptionPane.ERROR_MESSAGE - ); - return; - } - int nCommentsSeen = 0; - List% name of parameter , = 1, 2, 3, ... - * $PARAMTYPE % type of parameter , = 1, 2, 3, ... - * $PARENT% parent's property - *
JTree method getClosestPathForLocation. The
- * insertion itself will either be before, after, or in the node at the end
- * of the path. This method also calculates the rectangle which can be used
- * to draw the appropriate indicator for the insertion point.
- *
- * @param row the row number of the tree corresponding to the drop target.
- */
- public void computeInsertionPoint(int row) {
- JTree tree = targetTree;
-
- Rectangle rowBounds = tree.getRowBounds(row);
- if (row < srcRow) {
- // Insertion point is immediately before the node.
- this.lastRowRect.setBounds(rowBounds.x, rowBounds.y, rowBounds.width, 0);
- }
- else if (row > srcRow) {
- // Insertion point is immediately after the node.
- this.lastRowRect.setBounds(
- rowBounds.x, rowBounds.y + rowBounds.height - 1,
- rowBounds.width, 0
- );
- }
- else {
- // Insertion point is on the node - dropped data will be appended to the
- // nodes child list. Draw nothing in this case.
- this.lastRowRect.setBounds(rowBounds.x, rowBounds.y, 0, 0);
- }
- }
-}
diff --git a/plugins/rearranger/src/com/wrq/rearranger/rearrangement/Emitter.java b/plugins/rearranger/src/com/wrq/rearranger/rearrangement/Emitter.java
deleted file mode 100644
index 77287d0d9a13..000000000000
--- a/plugins/rearranger/src/com/wrq/rearranger/rearrangement/Emitter.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2003, 2010, Dave Kriewall
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
- * following conditions are met:
- *
- * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
- * disclaimer.
- *
- * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.wrq.rearranger.rearrangement;
-
-import com.intellij.openapi.editor.Document;
-import com.intellij.psi.PsiFile;
-import com.wrq.rearranger.ruleinstance.RuleInstance;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/** Emits a new document from the rearranged entries. */
-public final class Emitter {
-
- @NotNull private final StringBuilder myStringBuffer = new StringBuilder();
- @NotNull private final List- * %FT% field type - *- */ - String methodTypePattern; - /** - * regular expression pattern of the attributes of the method. - * In the case of a traditional getter method, this is ".*public.*" (i.e., any public method). - */ - String methodAttributePattern; - /** - * pattern of method body (excluding comments and newline characters). Substitutions are available as follows: - *
- * %FN% field name - * %FT% field type (if field is valid field, else empty string) - * %MT% method return type - * %P1% parameter 1 name (%P2%, %P3% etc for additional parameters) - * %T1% parameter 1 type name - *- */ - String body; - /** list of secondary method configurations, e.g. for "set" and "is". */ - ArrayList
- * %FN% field name - *- */ - String methodNamePattern; - /** number of parameters the secondary method must have. In the case of a traditional setter method, this is one. */ - int numParameters; - /** - * regular expression pattern of the type which the secondary method must return. - * In the case of a traditional getter method, this is the field type. One substitution is available: - *
- * %FT% field type - *- */ - String methodTypePattern; - /** - * regular expression pattern of the attributes of the method. - * In the case of a traditional getter method, this is ".*public.*" (i.e., any public method). - */ - String methodAttributePattern; - /** - * pattern of method body (excluding comments and newline characters). Substitutions are available as follows: - *
- * %FN% field name - * %FT% field type (if field is valid field, else empty string) - * %MT% method return type - * %P1% parameter 1 name (%P2%, %P3% etc for additional parameters) - * %T1% parameter 1 type name - *- */ - String body; - - public SecondaryMethodSetting() { - methodNamePattern = "set%FN%"; - numParameters = 1; - methodTypePattern = "void"; - methodAttributePattern = ".*public.*"; - body = "{\\s*return\\s*%FN%;\\s*}"; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getMethodNamePattern() { - return methodNamePattern; - } - - public void setMethodNamePattern(String methodNamePattern) { - this.methodNamePattern = methodNamePattern; - } - - public int getNumParameters() { - return numParameters; - } - - public void setNumParameters(int numParameters) { - this.numParameters = numParameters; - } - - public String getMethodTypePattern() { - return methodTypePattern; - } - - public void setMethodTypePattern(String methodTypePattern) { - this.methodTypePattern = methodTypePattern; - } - - public String getMethodAttributePattern() { - return methodAttributePattern; - } - - public void setMethodAttributePattern(String methodAttributePattern) { - this.methodAttributePattern = methodAttributePattern; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public String toString() { - return description; - } - - public com.wrq.rearranger.configuration.IListManagerObject deepcopy() { - SecondaryMethodSetting pms = new SecondaryMethodSetting(); - pms.description = getDescription(); - pms.methodNamePattern = getMethodNamePattern(); - pms.numParameters = getNumParameters(); - pms.methodTypePattern = getMethodTypePattern(); - pms.methodAttributePattern = getMethodAttributePattern(); - pms.body = getBody(); - return pms; - } - - public boolean equals(Object obj) { - if (!(obj instanceof PrimaryMethodSetting)) return false; - PrimaryMethodSetting pms = (PrimaryMethodSetting)obj; - if (!pms.description.equals(description)) return false; - if (!pms.methodNamePattern.equals(methodNamePattern)) return false; - if (pms.numParameters != numParameters) return false; - if (!pms.methodTypePattern.equals(methodTypePattern)) return false; - if (!pms.methodAttributePattern.equals(methodAttributePattern)) return false; - if (!pms.body.equals(body)) return false; - return true; - } - - public JPanel getPanel() { - JPanel panel = new JPanel(new GridBagLayout()); - panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), - "Matching Method (\"Setter\") Criteria")); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.anchor = GridBagConstraints.NORTHWEST; - constraints.fill = GridBagConstraints.NONE; - constraints.gridwidth = 1; - constraints.gridheight = 1; - constraints.weightx = 0.0d; - constraints.weighty = 0.0d; - constraints.gridy = constraints.gridx = 0; - constraints.insets = new Insets(3, 3, 3, 3); - JLabel methodNamePatternLabel = new JLabel("Method name:"); - methodNamePatternLabel.setToolTipText( - "Regular expression which method name must match. " + - "If the method is to be matched to a field, there must be\n" + - " at least one capture group (parenthesized subexpression) which will be treated as the field.\n" + - " In the case of a traditional setter method, this pattern is \"set%FN%\".\n" + - " One substitution is available:\n" + - " %FN% field name"); - panel.add(methodNamePatternLabel, constraints); - constraints.gridx++; - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.weightx = .5; - StringTextField primaryPrefixText = new StringTextField() { - public void setValue(String value) { - setMethodNamePattern(value); - } - - public String getValue() { - return getMethodNamePattern(); - } - }; - panel.add(primaryPrefixText, constraints); - constraints.fill = GridBagConstraints.NONE; - constraints.weightx = 0; - constraints.gridx++; - JLabel nParamLabel = new JLabel("Number of parameters:"); - nParamLabel.setToolTipText( - "number of parameters the secondary method must have.\n" + - "In the case of a traditional setter method, this is 1."); - panel.add(nParamLabel, constraints); - constraints.gridx++; - IntTextField nParamText = new IntTextField( - new IntTextField.IGetSet() { - public int get() { - return numParameters; - } - - public void set(int value) { - numParameters = value; - } - }, null, null - ); - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.gridwidth = GridBagConstraints.REMAINDER; - panel.add(nParamText, constraints); - - constraints.gridx = 0; - constraints.gridy++; - constraints.gridwidth = 1; - constraints.weightx = 0; - constraints.fill = GridBagConstraints.NONE; - JLabel returnTypeLabel = new JLabel("Return type:"); - returnTypeLabel.setToolTipText( - "regular expression pattern of the type which the secondary method must return.\n" + - " In the case of a traditional setter method, this is void. One substitution is available:\n" + - " * %FT% field type"); - panel.add(returnTypeLabel, constraints); - constraints.gridx++; - constraints.weightx = .5; - constraints.fill = GridBagConstraints.HORIZONTAL; - StringTextField returnTypeField = new StringTextField() { - public void setValue(String value) { - methodTypePattern = value; - } - - public String getValue() { - return methodTypePattern; - } - }; - panel.add(returnTypeField, constraints); - constraints.fill = GridBagConstraints.NONE; - constraints.gridx++; - constraints.weightx = 0; - JLabel methodAttributeLabel = new JLabel("Method attributes:"); - methodAttributeLabel.setToolTipText("Protection level or other attributes for the method.\n" + - "In the case of a getter method, this is usually \".*public.*\"."); - panel.add(methodAttributeLabel, constraints); - StringTextField methodAttributeField = new StringTextField() { - public void setValue(String value) { - methodAttributePattern = value; - } - - public String getValue() { - return methodAttributePattern; - } - }; - constraints.gridx++; - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.weightx = .5; - constraints.fill = GridBagConstraints.HORIZONTAL; - panel.add(methodAttributeField, constraints); - constraints.gridx++; - constraints.weightx = 0; - constraints.fill = GridBagConstraints.NONE; - constraints.gridy++; - constraints.gridx = 0; - JLabel bodyLabel = new JLabel("Body:"); - bodyLabel.setToolTipText("regular expression pattern of method body (excluding comments and newline characters).\n" + - "Substitutions are available as follows:\n" + - " %FN% field name\n" + - " %FT% field type (if field is valid field, else empty string)\n" + - " %MT% method return type\n" + - " %P1% parameter 1 name (%P2%, %P3% etc for additional parameters)\n" + - " %T1% parameter 1 type name"); - constraints.gridwidth = 1; - constraints.weightx = 0; - constraints.fill = GridBagConstraints.NONE; - panel.add(bodyLabel, constraints); - constraints.gridx++; - StringTextArea bodyField = new StringTextArea() { - public void setValue(String value) { - body = value; - } - - public String getValue() { - return body; - } - }; - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.weightx = 1; - constraints.weighty = .35; - constraints.fill = GridBagConstraints.BOTH; - JScrollPane sp = new JScrollPane(bodyField); - panel.add(sp, constraints); - constraints.gridx = 0; - constraints.gridy++; - constraints.gridheight = GridBagConstraints.REMAINDER; - constraints.fill = GridBagConstraints.NONE; - constraints.fill = GridBagConstraints.BOTH; - constraints.weightx = 1; - constraints.weighty = .65; - return panel; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AbstractAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AbstractAttribute.java deleted file mode 100644 index 82f3608a656b..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AbstractAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Common routines for 'abstract' modifier. */ -public final class AbstractAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static AbstractAttribute readExternal(final Element item) { - final AbstractAttribute result = new AbstractAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public AbstractAttribute() { - super("abstract", Modifier.ABSTRACT); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*AbstractAttribute*/AtomicAttribute deepCopy() { - final AbstractAttribute aba = new AbstractAttribute(); - aba.value = value; - aba.invert = invert; - return aba; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AndNotAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AndNotAttribute.java deleted file mode 100644 index 28c033e05725..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AndNotAttribute.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.util.Constraints; -import org.jdom.Element; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** Base class for all boolean attributes. */ -abstract public class AndNotAttribute extends AtomicAttribute { -// ------------------------------ FIELDS ------------------------------ - - boolean value; - boolean invert; - private final String valueName; - private final int modifierBit; - -// --------------------------- CONSTRUCTORS --------------------------- - - AndNotAttribute(final String s, final int modifierBit) { - valueName = s; - this.modifierBit = modifierBit; - } - -// --------------------- GETTER / SETTER METHODS --------------------- - - public final JPanel getAndNotPanel() { - final JPanel andNotPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(GridBagConstraints.WEST); - final JCheckBox andBox = new JCheckBox("And"); - andBox.setSelected(isValue()); - final JCheckBox notBox = new JCheckBox("not"); - notBox.setSelected(isInvert()); - notBox.setEnabled(andBox.isSelected()); - notBox.setForeground(notBox.isSelected() ? Color.BLACK : Color.GRAY); - final JLabel nameLabel = new JLabel(getName()); - nameLabel.setEnabled(andBox.isSelected()); - andNotPanel.add(andBox, constraints.firstCol()); - andNotPanel.add(notBox, constraints.nextCol()); - constraints.insets = new Insets(0, 0, 0, 4); - andNotPanel.add(nameLabel, constraints.weightedLastCol()); - andBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setValue(andBox.isSelected()); - notBox.setEnabled(andBox.isSelected()); - nameLabel.setEnabled(andBox.isSelected()); - } - }); - notBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setInvert(notBox.isSelected()); - notBox.setForeground(notBox.isSelected() ? Color.BLACK : Color.GRAY); - } - }); - return andNotPanel; - } - - private String getName() { - return valueName; - } - - public final boolean isInvert() { - return invert; - } - - public final void setInvert(final boolean invert) { - this.invert = invert; - } - - public final boolean isValue() { - return value; - } - - public final void setValue(final boolean value) { - this.value = value; - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public final boolean equals(final Object obj) { - if (!(obj instanceof AndNotAttribute)) return false; - final AndNotAttribute ana = (AndNotAttribute)obj; - return (value == ana.value && - invert == ana.invert && - valueName.equals(ana.valueName) && - modifierBit == ana.modifierBit); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final void appendAttributes(final Element me) { - final Element stElement = new Element(getElementName()); - me.getChildren().add(stElement); - stElement.setAttribute("value", Boolean.valueOf(value).toString()); - stElement.setAttribute("invert", Boolean.valueOf(invert).toString()); - } - - final String getElementName() { - final StringBuffer sb = new StringBuffer(valueName.length()); - sb.append(valueName); - sb.replace(0, 1, new String("" + sb.charAt(0)).toUpperCase()); - for (int i = 1; i < sb.length(); i++) { - if (sb.charAt(i) == ' ') { - sb.deleteCharAt(i); - sb.replace(i, i + 1, new String("" + sb.charAt(i)).toUpperCase()); - } - } - return sb.toString(); - } - - public final String getDescriptiveString() { - return (isValue() ? - isInvert() ? "non-" + valueName + " " : valueName + " " - : ""); - } - - public final boolean isMatch(final int modifiers) { - return (!isValue()) ? true : ((modifiers & modifierBit) > 0) ^ isInvert(); - } - - public final void loadAttributes(final Element item) { - value = RearrangerSettings.getBooleanAttribute(item, "value"); - invert = RearrangerSettings.getBooleanAttribute(item, "invert"); - } -} - diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AtomicAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AtomicAttribute.java deleted file mode 100644 index 994fc492cda2..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AtomicAttribute.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - - -/** base class for all individual attributes that a field, method or class may have. */ -abstract public class AtomicAttribute { - - /** - * All subclasses will implement a static public AtomicAttribute readExternal(final Element item) method. - * However, because it is static, the interface can't contain it. - */ -// abstract public AtomicAttribute readExternal(final Element item); -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/EnumAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/EnumAttribute.java deleted file mode 100644 index a58bdc2aa8c0..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/EnumAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - -/** Routines to handle 'enum' class attribute. */ -public class EnumAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static EnumAttribute readExternal(final Element item) { - final EnumAttribute result = new EnumAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public EnumAttribute() { - super("enum", ModifierConstants.ENUM); - } - -// -------------------------- OTHER METHODS -------------------------- - - /** final attribute. */ - public final /*EnumAttribute*/AtomicAttribute deepCopy() { - final EnumAttribute result = new EnumAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java deleted file mode 100644 index 87ec094d411b..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Routines to handle the 'final' modifier. */ -public final class FinalAttribute extends AndNotAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static FinalAttribute readExternal(final Element item) { - final FinalAttribute result = new FinalAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public FinalAttribute() { - super("final", Modifier.FINAL); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*FinalAttribute*/AtomicAttribute deepCopy() { - final FinalAttribute result = new FinalAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementedAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementedAttribute.java deleted file mode 100644 index 92b48ae79f48..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementedAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - - -public final class ImplementedAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static ImplementedAttribute readExternal(final Element item) { - final ImplementedAttribute result = new ImplementedAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public ImplementedAttribute() { - super("implemented", ModifierConstants.IMPLEMENTED); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*ImplementedAttribute*/AtomicAttribute deepCopy() { - final ImplementedAttribute result = new ImplementedAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementingAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementingAttribute.java deleted file mode 100644 index 77059d784ba9..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementingAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - -public final class ImplementingAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static ImplementingAttribute readExternal(final Element item) { - final ImplementingAttribute result = new ImplementingAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public ImplementingAttribute() { - super("implementing", ModifierConstants.IMPLEMENTING); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*ImplementingAttribute*/AtomicAttribute deepCopy() { - final ImplementingAttribute result = new ImplementingAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitialisedByAnonymousClassAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitialisedByAnonymousClassAttribute.java deleted file mode 100644 index 31834a6d1d48..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitialisedByAnonymousClassAttribute.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - -public final class InitialisedByAnonymousClassAttribute extends AndNotAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static InitialisedByAnonymousClassAttribute readExternal(final Element item) { - final InitialisedByAnonymousClassAttribute result = new InitialisedByAnonymousClassAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public InitialisedByAnonymousClassAttribute() { - super("initialized to anonymous class", ModifierConstants.INIT_TO_ANON_CLASS); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*InitToAnonClassAttribute*/AtomicAttribute deepCopy() { - final InitialisedByAnonymousClassAttribute result = new InitialisedByAnonymousClassAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitializerAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitializerAttribute.java deleted file mode 100644 index 11951b82de8c..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitializerAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - -/** Routines to handle a static initializer method. */ -public final class InitializerAttribute extends AndNotAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static InitializerAttribute readExternal(final Element item) { - final InitializerAttribute result = new InitializerAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public InitializerAttribute() { - super("initializer", ModifierConstants.INITIALIZER); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*InitializerAttribute*/AtomicAttribute deepCopy() { - final InitializerAttribute result = new InitializerAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} - diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/IntegerAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/IntegerAttribute.java deleted file mode 100644 index ddbc7361f745..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/IntegerAttribute.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiMethod; -import com.wrq.rearranger.configuration.IntTextField; -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.util.Constraints; -import com.wrq.rearranger.util.MethodUtil; -import org.jdom.Element; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** Allow item selection by comparison with an integer attribute. */ -abstract public class IntegerAttribute extends AtomicAttribute { - public static final int OP_GE = 0; - public static final int OP_LE = 1; - - // ------------------------------ FIELDS ------------------------------ - protected int value; - protected int opType; - protected boolean match; // when true, condition applies - private final String attributeDisplayName; // should be plural - private final String storageName; - -// --------------------------- CONSTRUCTORS --------------------------- - - IntegerAttribute(final String attributeDisplayName, - final String storageName, - final int opType) - { - this.attributeDisplayName = attributeDisplayName; - this.storageName = storageName; - this.opType = opType; - } - - // --------------------- GETTER / SETTER METHODS --------------------- - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - public int getOpType() { - return opType; - } - - public final boolean isMatch() { - return match; - } - - public final void setMatch(final boolean match) { - this.match = match; - } - - public final JPanel getIntegerPanel() { - final JPanel intPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(); - constraints.weightedLastRow(); - final JCheckBox enableBox = new JCheckBox(opType == OP_GE ? "with at least" : "with at most"); - intPanel.add(enableBox, constraints.firstCol()); - final IntTextField intField = new IntTextField( - new IntTextField.IGetSet() { - public int get() { - return value; - } - - public void set(int v) { - value = v; - } - }, - 0, 99); - - constraints.insets = new Insets(0, 3, 0, 0); - intPanel.add(intField, constraints.nextCol()); - final JLabel attribLabel = new JLabel(attributeDisplayName + "s"); - intPanel.add(attribLabel, constraints.weightedLastCol()); - enableBox.setSelected(match); - enableBox.setForeground(enableBox.isSelected() ? Color.BLACK : Color.GRAY); - intField.setEnabled(match); - attribLabel.setEnabled(match); - enableBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setMatch(enableBox.isSelected()); - intPanel.setEnabled(enableBox.isSelected()); - enableBox.setSelected(match); - enableBox.setForeground(enableBox.isSelected() ? Color.BLACK : Color.GRAY); - intField.setEnabled(match); - attribLabel.setEnabled(match); - } - }); - return intPanel; - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public boolean equals(final Object obj) { - if (!(obj instanceof IntegerAttribute)) return false; - final IntegerAttribute na = (IntegerAttribute)obj; - return match == na.match && - opType == na.opType && - value == na.value; - } - -// -------------------------- OTHER METHODS -------------------------- - - public final void appendAttributes(final Element me) { - final Element stElement = new Element(storageName); - - me.getChildren().add(stElement); - stElement.setAttribute("match", Boolean.valueOf(match).toString()); - stElement.setAttribute("opType", "" + opType); - stElement.setAttribute("value", "" + value); - } - - protected final void deepCopy(IntegerAttribute result) { - result.match = match; - result.opType = opType; - result.value = value; - } - - public final String getDescriptiveString() { - return (match ? - (opType == OP_GE ? "with at least " : "with at most ") + - value + " " + attributeDisplayName + (value != 1 ? "s" : "") - : ""); - } - - public final boolean isMatch(PsiElement value) { - if (!match) return true; - if (!(value instanceof PsiMethod)) return false; - PsiMethod method = (PsiMethod)value; - int n = MethodUtil.nofParameters(method); - if (opType == OP_GE) { - return n >= this.value; - } - else { - return n <= this.value; - } - } - - public final void loadAttributes(final Element item) { - match = RearrangerSettings.getBooleanAttribute(item, "match", false); - // opType = RearrangerSettings.getIntAttribute(item, "opType", opType); -- never load opType, it is immutable - value = RearrangerSettings.getIntAttribute(item, "value", 0); - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MaxParamsAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MaxParamsAttribute.java deleted file mode 100644 index e6c1194557bb..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MaxParamsAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -/** Common routines for 'maximum number of params' modifier. */ -public class MaxParamsAttribute - extends IntegerAttribute -{ - private static final String PROPNAME = "MAX_PARAMS"; - // -------------------------- STATIC METHODS -------------------------- - - public static MaxParamsAttribute readExternal(final Element item) { - final MaxParamsAttribute result = new MaxParamsAttribute(); - result.loadAttributes(item.getChild(PROPNAME)); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public MaxParamsAttribute() { - super("parameter", PROPNAME, IntegerAttribute.OP_LE); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*AbstractAttribute*/AtomicAttribute deepCopy() { - final MaxParamsAttribute mpa = new MaxParamsAttribute(); - mpa.value = value; - mpa.match = match; - return mpa; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MinParamsAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MinParamsAttribute.java deleted file mode 100644 index 4d3f301007f1..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MinParamsAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -/** Common routines for 'minimum number of params' modifier. */ -public class MinParamsAttribute - extends IntegerAttribute -{ - private static final String PROPNAME = "MIN_PARAMS"; - // -------------------------- STATIC METHODS -------------------------- - - public static MinParamsAttribute readExternal(final Element item) { - final MinParamsAttribute result = new MinParamsAttribute(); - result.loadAttributes(item.getChild(PROPNAME)); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public MinParamsAttribute() { - super("parameter", PROPNAME, IntegerAttribute.OP_GE); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*AbstractAttribute*/AtomicAttribute deepCopy() { - final MinParamsAttribute mpa = new MinParamsAttribute(); - mpa.value = value; - mpa.match = match; - return mpa; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NameAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NameAttribute.java deleted file mode 100644 index d77f755ab4a8..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NameAttribute.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -/** Allows item selection by matching its name to a regular expression. */ -public final class NameAttribute extends StringAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static NameAttribute readExternal(final Element item) { - final NameAttribute result = new NameAttribute(); - result.loadAttributes(item.getChild("NameMatch")); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public NameAttribute() { - super("names", "NameMatch"); - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public final boolean equals(final Object object) { - if (!(object instanceof NameAttribute)) return false; - return super.equals(object); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*NameAttribute*/AtomicAttribute deepCopy() { - final NameAttribute result = new NameAttribute(); - super.deepCopy(result); - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NativeAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NativeAttribute.java deleted file mode 100644 index e36af5c7fe3b..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NativeAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Handles the 'native' modifier. */ -public final class NativeAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static NativeAttribute readExternal(final Element item) { - final NativeAttribute result = new NativeAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public NativeAttribute() { - super("native", Modifier.NATIVE); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*NativeAttribute*/AtomicAttribute deepCopy() { - final NativeAttribute result = new NativeAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverriddenAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverriddenAttribute.java deleted file mode 100644 index e922cc316a34..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverriddenAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - - -public final class OverriddenAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static OverriddenAttribute readExternal(final Element item) { - final OverriddenAttribute result = new OverriddenAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public OverriddenAttribute() { - super("overridden", ModifierConstants.OVERRIDDEN); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*OverriddenAttribute*/AtomicAttribute deepCopy() { - final OverriddenAttribute result = new OverriddenAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverridingAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverridingAttribute.java deleted file mode 100644 index 3e3af6a95909..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverridingAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.ModifierConstants; -import org.jdom.Element; - -public final class OverridingAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static OverridingAttribute readExternal(final Element item) { - final OverridingAttribute result = new OverridingAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public OverridingAttribute() { - super("overriding", ModifierConstants.OVERRIDING); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*OverridingAttribute*/AtomicAttribute deepCopy() { - final OverridingAttribute result = new OverridingAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} \ No newline at end of file diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ProtectionLevelAttributes.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ProtectionLevelAttributes.java deleted file mode 100644 index 9ff8cfc8b3c8..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ProtectionLevelAttributes.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.util.Constraints; -import org.jdom.Element; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.lang.reflect.Modifier; - -/** Routines to handle the four protection level modifiers. */ -public final class ProtectionLevelAttributes - extends AtomicAttribute -{ - -// ------------------------------ FIELDS ------------------------------ - - /** protection levels. */ - private boolean plPublic; - private boolean plPrivate; - private boolean plProtected; - private boolean plPackage; - private boolean invertProtectionLevel; - -// -------------------------- STATIC METHODS -------------------------- - - public static ProtectionLevelAttributes readExternal(final Element item) { - final ProtectionLevelAttributes result = new ProtectionLevelAttributes(); - final Element me = item.getChild("ProtectionLevel"); - result.loadAttributes(me); - return result; - } - - private void loadAttributes(final Element me) { - plPublic = RearrangerSettings.getBooleanAttribute(me, "public"); - plPrivate = RearrangerSettings.getBooleanAttribute(me, "private"); - plProtected = RearrangerSettings.getBooleanAttribute(me, "protected"); - plPackage = RearrangerSettings.getBooleanAttribute(me, "package"); - invertProtectionLevel = RearrangerSettings.getBooleanAttribute(me, "invert"); - } - -// --------------------- GETTER / SETTER METHODS --------------------- - - private boolean isInvertProtectionLevel() { - return invertProtectionLevel; - } - - public final void setInvertProtectionLevel(final boolean invertProtectionLevel) { - this.invertProtectionLevel = invertProtectionLevel; - } - - private boolean isPlPackage() { - return plPackage; - } - - public final void setPlPackage(final boolean plPackage) { - this.plPackage = plPackage; - } - - private boolean isPlPrivate() { - return plPrivate; - } - - public void setPlPrivate(final boolean plPrivate) { - this.plPrivate = plPrivate; - } - - private boolean isPlProtected() { - return plProtected; - } - - public final void setPlProtected(final boolean plProtected) { - this.plProtected = plProtected; - } - - private boolean isPlPublic() { - return plPublic; - } - - public final void setPlPublic(final boolean plPublic) { - this.plPublic = plPublic; - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public boolean equals(final Object obj) { - if (!(obj instanceof ProtectionLevelAttributes)) return false; - final ProtectionLevelAttributes pla = (ProtectionLevelAttributes)obj; - return plPublic == pla.plPublic && - plPrivate == pla.plPrivate && - plProtected == pla.plProtected && - plPackage == pla.plPackage && - invertProtectionLevel == pla.invertProtectionLevel; - } - -// -------------------------- OTHER METHODS -------------------------- - - public final void appendAttributes(final Element me) { - final Element plElement = new Element("ProtectionLevel"); - me.getChildren().add(plElement); - plElement.setAttribute("public", Boolean.valueOf(plPublic).toString()); - plElement.setAttribute("private", Boolean.valueOf(plPrivate).toString()); - plElement.setAttribute("protected", Boolean.valueOf(plProtected).toString()); - plElement.setAttribute("package", Boolean.valueOf(plPackage).toString()); - plElement.setAttribute("invert", Boolean.valueOf(invertProtectionLevel).toString()); - } - - public final /*ProtectionLevelAttributes*/AtomicAttribute deepCopy() { - final ProtectionLevelAttributes pla = new ProtectionLevelAttributes(); - pla.plPublic = plPublic; - pla.plPrivate = plPrivate; - pla.plProtected = plProtected; - pla.plPackage = plPackage; - pla.invertProtectionLevel = invertProtectionLevel; - return pla; - } - - public final JPanel getProtectionLevelPanel() { - final JPanel plPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(); - constraints.weightedLastRow(); - constraints.fill = GridBagConstraints.BOTH; - final JCheckBox notBox = new JCheckBox("not"); - notBox.setSelected(isInvertProtectionLevel()); - notBox.setForeground(notBox.isSelected() ? Color.BLACK : Color.GRAY); - plPanel.add(notBox, constraints.firstCol()); - final JPanel plLevels = getProtLevels(); - plPanel.add(plLevels, constraints.weightedLastCol()); - notBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setInvertProtectionLevel(notBox.isSelected()); - notBox.setForeground(notBox.isSelected() ? Color.BLACK : Color.GRAY); - } - }); - - return plPanel; - } - - private JPanel getProtLevels() { - final JPanel plPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(); - final JCheckBox publicBox = new JCheckBox("public or"); - publicBox.setSelected(isPlPublic()); - final JCheckBox privateBox = new JCheckBox("private or"); - privateBox.setSelected(isPlPrivate()); - final JCheckBox protectedBox = new JCheckBox("protected or"); - protectedBox.setSelected(isPlProtected()); - final JCheckBox packageBox = new JCheckBox("package"); - packageBox.setSelected(isPlPackage()); - plPanel.add(publicBox, constraints.weightedLastCol()); - constraints.newRow(); - plPanel.add(privateBox, constraints.weightedLastCol()); - constraints.newRow(); - plPanel.add(protectedBox, constraints.weightedLastCol()); - constraints.weightedLastRow(); - plPanel.add(packageBox, constraints.weightedLastCol()); - publicBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setPlPublic(publicBox.isSelected()); - } - }); - privateBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setPlPrivate(privateBox.isSelected()); - } - }); - protectedBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setPlProtected(protectedBox.isSelected()); - } - }); - packageBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setPlPackage(packageBox.isSelected()); - } - }); - return plPanel; - } - - public final String getProtectionLevelString() { - final StringBuffer sb = new StringBuffer(60); - final int nProtLevels = (isPlPublic() ? 1 : 0) + - (isPlPrivate() ? 1 : 0) + - (isPlProtected() ? 1 : 0) + - (isPlPackage() ? 1 : 0); - - int nProtLevelsSeen = 0; - if (isPlPublic()) { - sb.append(isInvertProtectionLevel() ? "non-public" : "public"); - nProtLevelsSeen++; - if (nProtLevelsSeen < nProtLevels) { - sb.append("/"); - } - } - if (isPlPrivate()) { - sb.append(isInvertProtectionLevel() ? "non-private" : "private"); - nProtLevelsSeen++; - if (nProtLevelsSeen < nProtLevels) { - sb.append("/"); - } - } - if (isPlProtected()) { - sb.append(isInvertProtectionLevel() ? "non-protected" : "protected"); - nProtLevelsSeen++; - if (nProtLevelsSeen < nProtLevels) { - sb.append("/"); - } - } - if (isPlPackage()) { - sb.append(isInvertProtectionLevel() ? "non-package" : "package"); - nProtLevelsSeen++; - if (nProtLevelsSeen < nProtLevels) { - sb.append("/"); - } - } - if (nProtLevels > 0) { - sb.append(' '); - } - return sb.toString(); - } - - /** - * @param modifiers Java modifiers for the field, method or class. - * @return true if the supplied protection level modifiers match this object's modifier requirements. - */ - public final boolean isMatch(final int modifiers) { - boolean result; - if (!plPublic && !plPrivate && !plProtected && !plPackage) { - return true; // nothing selected, so don't take protection level into account. - } - result = - (plPublic && Modifier.isPublic(modifiers)) || - (plPrivate && Modifier.isPrivate(modifiers)) || - (plProtected && Modifier.isProtected(modifiers)) || - (plPackage && !(Modifier.isPublic(modifiers) || - Modifier.isPrivate(modifiers) || - Modifier.isProtected(modifiers))); - result ^= invertProtectionLevel; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ReturnTypeAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ReturnTypeAttribute.java deleted file mode 100644 index 645d5e422d33..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ReturnTypeAttribute.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -/** Allows method selection by matching its return type to a regular expression. */ -public final class ReturnTypeAttribute extends StringAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static ReturnTypeAttribute readExternal(final Element item) { - final ReturnTypeAttribute result = new ReturnTypeAttribute(); - result.loadAttributes(item.getChild("ReturnTypeMatch")); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public ReturnTypeAttribute() { - super("return types", "ReturnTypeMatch"); - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public final boolean equals(final Object object) { - if (!(object instanceof ReturnTypeAttribute)) return false; - return super.equals(object); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*ReturnTypeAttribute*/AtomicAttribute deepCopy() { - final ReturnTypeAttribute result = new ReturnTypeAttribute(); - super.deepCopy(result); - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SortOptions.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SortOptions.java deleted file mode 100644 index 1b1f43b26ce9..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SortOptions.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.entry.RangeEntry; -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.util.Constraints; -import org.jdom.Element; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * Contains sorting attributes (part of common attributes; applies to fields, methods, inner and outer classes). - * - * Originally, methods and classes could only be sorted alphabetically by name (case sensitive). Fields could be - * sorted by type (optionally ignoring case), by name (case sensitive), or both. - * - * Beginning with release 4.4, all of these types (fields, methods and classes) can be sorted optionally by - * modifiers, optionally by type (optionally ignoring case), and by name (optionally ignoring case). This covers - * all permutations. Modifiers are always lower case so no need to ask about whether to ignore case. - */ -public class SortOptions - extends AtomicAttribute -{ - private boolean byModifiers; - private boolean byType; - private boolean isTypeCaseInsensitive; - private boolean byName; - private boolean isNameCaseInsensitive; - - public SortOptions() { - byModifiers = false; - byType = false; - isTypeCaseInsensitive = false; - byName = false; - isNameCaseInsensitive = false; - } - - public boolean isByModifiers() { - return byModifiers; - } - - public void setByModifiers(boolean byModifiers) { - this.byModifiers = byModifiers; - } - - public boolean isByName() { - return byName; - } - - public void setByName(boolean byName) { - this.byName = byName; - } - - public boolean isByType() { - return byType; - } - - public void setByType(boolean byType) { - this.byType = byType; - } - - public boolean isNameCaseInsensitive() { - return isNameCaseInsensitive; - } - - public void setNameCaseInsensitive(boolean nameCaseInsensitive) { - isNameCaseInsensitive = nameCaseInsensitive; - } - - public boolean isTypeCaseInsensitive() { - return isTypeCaseInsensitive; - } - - public void setTypeCaseInsensitive(boolean typeCaseInsensitive) { - isTypeCaseInsensitive = typeCaseInsensitive; - } - - public final boolean equals(final Object obj) { - if (!(obj instanceof SortOptions)) return false; - SortOptions so = (SortOptions)obj; - return byModifiers == so.byModifiers && - byType == so.byType && - isTypeCaseInsensitive == so.isTypeCaseInsensitive && - byName == so.byName && - isNameCaseInsensitive == so.isNameCaseInsensitive; - } - - public static SortOptions readExternal(final Element item) { - SortOptions result = new SortOptions(); - final Element me = item.getChild("SortOptions"); - result.loadAttributes(me); - // support old settings - result.byName |= RearrangerSettings.getBooleanAttribute(item, "alphabetize"); - result.byType |= RearrangerSettings.getBooleanAttribute(item, "sortByType", false); - result.isTypeCaseInsensitive |= RearrangerSettings.getBooleanAttribute(item, "ignoreTypeCase", false); - return result; - } - - private void loadAttributes(final Element me) { - byModifiers = RearrangerSettings.getBooleanAttribute(me, "byModifiers"); - byType = RearrangerSettings.getBooleanAttribute(me, "byType"); - isTypeCaseInsensitive = RearrangerSettings.getBooleanAttribute(me, "isTypeCaseInsensitive"); - byName = RearrangerSettings.getBooleanAttribute(me, "byName"); - isNameCaseInsensitive = RearrangerSettings.getBooleanAttribute(me, "isNameCaseInsensitive"); - } - - public final /*SortOptions*/ AtomicAttribute deepCopy() { - final SortOptions result = new SortOptions(); - result.byModifiers = byModifiers; - result.byType = byType; - result.isTypeCaseInsensitive = isTypeCaseInsensitive; - result.byName = byName; - result.isNameCaseInsensitive = isNameCaseInsensitive; - return result; - } - - public final void appendAttributes(final Element me) { - final Element plElement = new Element("SortOptions"); - me.getChildren().add(plElement); - plElement.setAttribute("byModifiers", Boolean.valueOf(byModifiers).toString()); - plElement.setAttribute("byType", Boolean.valueOf(byType).toString()); - plElement.setAttribute("isTypeCaseInsensitive", Boolean.valueOf(isTypeCaseInsensitive).toString()); - plElement.setAttribute("byName", Boolean.valueOf(byName).toString()); - plElement.setAttribute("isNameCaseInsensitive", Boolean.valueOf(isNameCaseInsensitive).toString()); - } - - public final String getDescriptiveString() { - StringBuilder sb = new StringBuilder(80); - if (byName && !isNameCaseInsensitive && !byModifiers && !byType) { - return " (alphabetized)"; - } - if (byModifiers || byType || byName) { - sb.append(" (sorted by"); - boolean needComma = false; - if (byModifiers) { - sb.append(" modifiers"); - needComma = true; - } - if (byType) { - if (needComma) { - sb.append(','); - } - sb.append(" type"); - if (isTypeCaseInsensitive) { - sb.append("(CI)"); - } - needComma = true; - } - if (byName) { - if (needComma) { - sb.append(','); - } - sb.append(" name"); - if (isNameCaseInsensitive) { - sb.append("(CI)"); - } - } - sb.append(")"); - } - return sb.toString(); - } - - public final JPanel getSortOptionsPanel() { - final JPanel abPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(); - final JLabel sortLabel = new JLabel("Sort"); - constraints.insets = new Insets(0, 5, 0, 5); - abPanel.add(sortLabel, constraints.firstCol()); - final JCheckBox byModifiersBox = new JCheckBox("by modifiers"); - final JCheckBox byTypeBox = new JCheckBox("by type"); - final JCheckBox typeCIBox = new JCheckBox("case insensitive"); - final JCheckBox byNameBox = new JCheckBox("by name"); - final JCheckBox nameCIBox = new JCheckBox("case insensitive"); - constraints.insets = new Insets(0, 0, 0, 0); - abPanel.add(byModifiersBox, constraints.weightedLastCol()); - constraints.newRow(); - constraints.nextCol(); - abPanel.add(byTypeBox, constraints.nextCol()); - abPanel.add(typeCIBox, constraints.weightedLastCol()); - constraints.weightedLastRow(); - constraints.nextCol(); - abPanel.add(byNameBox, constraints.nextCol()); - abPanel.add(nameCIBox, constraints.weightedLastCol()); - - byModifiersBox.setSelected(isByModifiers()); - byTypeBox.setSelected(isByType()); - typeCIBox.setSelected(isTypeCaseInsensitive()); - byNameBox.setSelected(isByName()); - nameCIBox.setSelected(isNameCaseInsensitive()); - - byModifiersBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setByModifiers(byModifiersBox.isSelected()); - } - }); - byTypeBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setByType(byTypeBox.isSelected()); - } - }); - typeCIBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setTypeCaseInsensitive(typeCIBox.isSelected()); - } - }); - byNameBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setByName(byNameBox.isSelected()); - } - }); - nameCIBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setNameCaseInsensitive(nameCIBox.isSelected()); - } - }); - - return abPanel; - } - - public String generateSortString(RangeEntry entry) { - String modifiers = entry.getModifierString(); - String type = entry.getType(); - String name = entry.getName(); - StringBuilder sb = new StringBuilder(modifiers.length() + type.length() + name.length()); - if (byModifiers) { - sb.append(modifiers); - } - if (byType) { - sb.append(isTypeCaseInsensitive ? type.toLowerCase() : type); - } - if (byName) { - sb.append(isNameCaseInsensitive ? name.toLowerCase() : name); - } - return sb.toString(); - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StaticAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StaticAttribute.java deleted file mode 100644 index 45af998af32b..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StaticAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Routines to handle the 'static' modifier. */ -public final class StaticAttribute extends AndNotAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static StaticAttribute readExternal(final Element item) { - final StaticAttribute result = new StaticAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public StaticAttribute() { - super("static", Modifier.STATIC); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*StaticAttribute*/AtomicAttribute deepCopy() { - final StaticAttribute result = new StaticAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StringAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StringAttribute.java deleted file mode 100644 index 147c9b75b5f7..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StringAttribute.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.util.Constraints; -import org.jdom.Attribute; -import org.jdom.Element; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** Allows item selection by matching a string attribute to a regular expression. */ -abstract public class StringAttribute extends AtomicAttribute { - -// ------------------------------ FIELDS ------------------------------ - - private String expression; - private boolean match; - private boolean invert; - private final String attributeDisplayName; // should be plural - private final String storageName; - -// --------------------------- CONSTRUCTORS --------------------------- - - StringAttribute(String attributeDisplayName, String storageName) { - this.attributeDisplayName = attributeDisplayName; - this.storageName = storageName; - } - -// --------------------- GETTER / SETTER METHODS --------------------- - - public final String getExpression() { - return expression; - } - - public final void setExpression(final String expression) { - this.expression = expression; - } - - public final JPanel getStringPanel() { - final JPanel stringPanel = new JPanel(new GridBagLayout()); - final Constraints constraints = new Constraints(); - constraints.weightedLastRow(); - final JCheckBox enableBox = new JCheckBox("whose " + attributeDisplayName); - stringPanel.add(enableBox, constraints.firstCol()); - final JComboBox invertBox = new JComboBox(new Object[]{"match", "do not match"}); - invertBox.setSelectedIndex(isInvert() ? 1 : 0); - final JTextField patternField = new JTextField(20); - stringPanel.add(invertBox, constraints.nextCol()); - stringPanel.add(patternField, constraints.weightedLastCol()); - enableBox.setSelected(isMatch()); - invertBox.setEnabled(isMatch()); - patternField.setEnabled(isMatch()); - patternField.setText(getExpression()); - enableBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setMatch(enableBox.isSelected()); - invertBox.setEnabled(enableBox.isSelected()); - patternField.setEnabled(enableBox.isSelected()); - } - }); - invertBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setInvert(invertBox.getSelectedIndex() == 1); - } - }); - patternField.getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(final DocumentEvent e) { - setExpression(patternField.getText()); - } - - public void insertUpdate(final DocumentEvent e) { - setExpression(patternField.getText()); - } - - public void removeUpdate(final DocumentEvent e) { - setExpression(patternField.getText()); - } - }); - return stringPanel; - } - - public final boolean isInvert() { - return invert; - } - - private void setInvert(final boolean invert) { - this.invert = invert; - } - - public final boolean isMatch() { - return match; - } - - public final void setMatch(final boolean match) { - this.match = match; - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public boolean equals(final Object object) { - if (!(object instanceof StringAttribute)) return false; - final StringAttribute na = (StringAttribute)object; - return match == na.match && - (expression == null || na.expression == null ? - expression == null && na.expression == null : expression.equals(na.expression)) && - invert == na.invert; - } - -// -------------------------- OTHER METHODS -------------------------- - - public final void appendAttributes(final Element me) { - final Element stElement = new Element(storageName); - if (expression == null) { - expression = ""; - } - me.getChildren().add(stElement); - stElement.setAttribute("match", Boolean.valueOf(match).toString()); - stElement.setAttribute("invert", Boolean.valueOf(invert).toString()); - stElement.setAttribute("pattern", expression); - } - - protected final void deepCopy(StringAttribute result) { - result.match = match; - result.expression = expression; - result.invert = invert; - } - - public final String getDescriptiveString() { - return (match ? "whose " + - attributeDisplayName + - (invert ? " do not match '" : " match '") + - expression + "'" - : ""); - } - - public final boolean isMatch(final String string) { - return !match || string.matches(expression) ^ invert; - } - - public final void loadAttributes(final Element item) { - match = RearrangerSettings.getBooleanAttribute(item, "match", false); - invert = RearrangerSettings.getBooleanAttribute(item, "invert", false); - final Attribute attr = RearrangerSettings.getAttribute(item, "pattern"); - expression = (attr == null ? "" : ((java.lang.String)attr.getValue())); - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SynchronizedAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SynchronizedAttribute.java deleted file mode 100644 index 8e166fc6ae63..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SynchronizedAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Handles the 'synchronized' modifier. */ -public final class SynchronizedAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static SynchronizedAttribute readExternal(final Element item) { - final SynchronizedAttribute result = new SynchronizedAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public SynchronizedAttribute() { - super("synchronized", Modifier.SYNCHRONIZED); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*SynchronizedAttribute*/AtomicAttribute deepCopy() { - final SynchronizedAttribute result = new SynchronizedAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TransientAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TransientAttribute.java deleted file mode 100644 index 2f48fb93cdc4..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TransientAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Handles the 'transient' modifier. */ -public final class TransientAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static TransientAttribute readExternal(final Element item) { - final TransientAttribute result = new TransientAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public TransientAttribute() { - super("transient", Modifier.TRANSIENT); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*TransientAttribute*/AtomicAttribute deepCopy() { - final TransientAttribute result = new TransientAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TypeAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TypeAttribute.java deleted file mode 100644 index 0627b20ff8ea..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TypeAttribute.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -/** Allows field selection by matching its type to a regular expression. */ - -public class TypeAttribute extends StringAttribute { - -// -------------------------- STATIC METHODS -------------------------- - - public static TypeAttribute readExternal(final Element item) { - final TypeAttribute result = new TypeAttribute(); - result.loadAttributes(item.getChild("TypeMatch")); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public TypeAttribute() { - super("types", "TypeMatch"); - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public final boolean equals(final Object object) { - if (!(object instanceof TypeAttribute)) return false; - return super.equals(object); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*TypeAttribute*/AtomicAttribute deepCopy() { - final TypeAttribute result = new TypeAttribute(); - super.deepCopy(result); - return result; - } -} \ No newline at end of file diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/VolatileAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/VolatileAttribute.java deleted file mode 100644 index 6bc6a05c17d9..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/VolatileAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.atomicAttributes; - -import org.jdom.Element; - -import java.lang.reflect.Modifier; - -/** Handles the 'volatile' modifier. */ -public final class VolatileAttribute - extends AndNotAttribute -{ - -// -------------------------- STATIC METHODS -------------------------- - - public static VolatileAttribute readExternal(final Element item) { - final VolatileAttribute result = new VolatileAttribute(); - result.loadAttributes(item.getChild(result.getElementName())); - return result; - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public VolatileAttribute() { - super("volatile", Modifier.VOLATILE); - } - -// -------------------------- OTHER METHODS -------------------------- - - public final /*VolatileAttribute*/AtomicAttribute deepCopy() { - final VolatileAttribute result = new VolatileAttribute(); - result.value = value; - result.invert = invert; - return result; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/AttributeGroup.java b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/AttributeGroup.java deleted file mode 100644 index a9b278f586e9..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/AttributeGroup.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.attributeGroups; - -import org.jdom.Element; -import org.jetbrains.annotations.NotNull; - -/** Methods implemented by rule objects, which are saved in configuration. */ -public interface AttributeGroup extends Rule { - -// -------------------------- OTHER METHODS -------------------------- - - @NotNull - AttributeGroup deepCopy(); - - void writeExternal(final @NotNull Element parent); -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/ClassAttributes.java b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/ClassAttributes.java deleted file mode 100644 index 41559ecda682..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/ClassAttributes.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.attributeGroups; - -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiJavaToken; -import com.wrq.rearranger.entry.RangeEntry; -import com.wrq.rearranger.settings.CommentRule; -import com.wrq.rearranger.settings.atomicAttributes.AbstractAttribute; -import com.wrq.rearranger.settings.atomicAttributes.EnumAttribute; -import com.wrq.rearranger.util.Constraints; -import org.jdom.Element; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.Border; -import java.awt.*; - -/** Routines to handle class modifiers other than those already handled by CommonAttributes. */ -public final class ClassAttributes - extends CommonAttributes - implements AttributeGroup -{ - -// ------------------------------ FIELDS ------------------------------ - - private AbstractAttribute abAttr; - private EnumAttribute enumAttr; - -// -------------------------- STATIC METHODS -------------------------- - - @Nullable - public static AttributeGroup readExternal(final Element element) { - if (element.getName().equals("Class")) { - final ClassAttributes result = new ClassAttributes(); - CommonAttributes.readExternal(result, element); - result.abAttr = AbstractAttribute.readExternal(element); - result.enumAttr = EnumAttribute.readExternal(element); - return result; - } - else if (element.getName().equals("Comment")) { - return CommentRule.readExternal(element); - } - else { - return null; - } - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public ClassAttributes() { - abAttr = new AbstractAttribute(); - enumAttr = new EnumAttribute(); - } - -// --------------------- GETTER / SETTER METHODS --------------------- - - private AbstractAttribute getAbAttr() { - return abAttr; - } - - public EnumAttribute getEnumAttr() { - return enumAttr; - } -// ------------------------ CANONICAL METHODS ------------------------ - - public final String toString() { - final StringBuilder sb = new StringBuilder(70); - sb.append(abAttr.getDescriptiveString()); - sb.append(getProtectionLevelAttributes().getProtectionLevelString()); - sb.append(getStaticAttribute().getDescriptiveString()); - sb.append(getFinalAttribute().getDescriptiveString()); - sb.append(enumAttr.getDescriptiveString()); - if (sb.length() == 0) { - sb.append("all classes"); - } - else { - sb.append("classes"); - } - if (getNameAttribute().isMatch()) { - sb.append(' '); - sb.append(getNameAttribute().getDescriptiveString()); - } - sb.append(getSortOptions().getDescriptiveString()); - return sb.toString(); - } - -// ------------------------ INTERFACE METHODS ------------------------ - - -// --------------------- Interface AttributeGroup --------------------- - - @NotNull - public final /*ClassAttributes*/AttributeGroup deepCopy() { - final ClassAttributes result = new ClassAttributes(); - deepCopyCommonItems(result); - result.abAttr = (AbstractAttribute)abAttr.deepCopy(); - result.enumAttr = (EnumAttribute)enumAttr.deepCopy(); - return result; - } - - @SuppressWarnings("unchecked") - public final void writeExternal(@NotNull final Element parent) { - final Element me = new Element("Class"); - writeExternalCommonAttributes(me); - abAttr.appendAttributes(me); - enumAttr.appendAttributes(me); - parent.getChildren().add(me); - } - -// -------------------------- OTHER METHODS -------------------------- - - public boolean equals(final Object obj) { - if (!(obj instanceof ClassAttributes)) { - return false; - } - final ClassAttributes ca = (ClassAttributes)obj; - return super.equals(ca) && - abAttr.equals(ca.abAttr) && - enumAttr.equals(ca.enumAttr); - } - - public final JPanel getClassAttributesPanel() { - final JPanel caPanel = new JPanel(new GridBagLayout()); - final Border border = BorderFactory.createEtchedBorder(); - caPanel.setBorder(border); - final Constraints constraints = new Constraints(GridBagConstraints.NORTHWEST); - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.gridheight = 4; - constraints.weightx = 1.0d; - constraints.weighty = 0.0d; - constraints.insets = new Insets(0, 0, 10, 0); - caPanel.add(getProtectionLevelAttributes().getProtectionLevelPanel(), constraints); - constraints.gridy = 4; - constraints.gridheight = 1; - caPanel.add(getStaticAttribute().getAndNotPanel(), constraints); - constraints.gridy++; - caPanel.add(getAbAttr().getAndNotPanel(), constraints); - constraints.gridy++; - caPanel.add(getFinalAttribute().getAndNotPanel(), constraints); - constraints.gridy++; - caPanel.add(getEnumAttr().getAndNotPanel(), constraints); - constraints.gridy++; - caPanel.add(getNameAttribute().getStringPanel(), constraints); - constraints.gridy++; - constraints.gridheight = GridBagConstraints.REMAINDER; - constraints.weighty = 1.0d; - constraints.insets = new Insets(0, 0, 0, 0); - caPanel.add(getSortOptions().getSortOptionsPanel(), constraints); - return caPanel; - } - - public final boolean isMatch(@NotNull RangeEntry entry) - // final int modifiers, final String name, final String returnType) - { - return entry.getEnd().getParent() instanceof PsiClass && - entry.getEnd() instanceof PsiJavaToken && -// ((PsiJavaToken)entry.getEnd()).getTokenType() == PsiJavaToken.LBRACE && - entry.getEnd().getText().equals("{") && - super.isMatch(entry) && - abAttr.isMatch(entry.getModifiers()) && - enumAttr.isMatch(entry.getModifiers()); - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/CommonAttributes.java b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/CommonAttributes.java deleted file mode 100644 index ad8c6c1a64e6..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/CommonAttributes.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.settings.attributeGroups; - -import com.wrq.rearranger.entry.RangeEntry; -import com.wrq.rearranger.ruleinstance.DefaultRuleInstance; -import com.wrq.rearranger.ruleinstance.RuleInstance; -import com.wrq.rearranger.settings.RearrangerSettings; -import com.wrq.rearranger.settings.atomicAttributes.*; -import org.jdom.Element; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * Routines for Java modifiers common to fields, methods and classes, namely: protection levels (public, private, - * protected, package), final modifier, and static modifier. Ability to match the name to a regular - * expression is also supported. - */ -public abstract class CommonAttributes implements AttributeGroup, PrioritizedRule { - -// ------------------------------ FIELDS ------------------------------ - - private ProtectionLevelAttributes myProtectionLevelAttributes; - private FinalAttribute myFinalAttribute; - private StaticAttribute myStaticAttribute; - private NameAttribute myNameAttribute; - private SortOptions mySortOptions; - private int myPriority; // 1 = low priority, > 1 is higher priority - -// -------------------------- STATIC METHODS -------------------------- - - static void readExternal(final CommonAttributes result, final Element item) { - result.myProtectionLevelAttributes = ProtectionLevelAttributes.readExternal(item); - result.myStaticAttribute = StaticAttribute.readExternal(item); - result.myFinalAttribute = FinalAttribute.readExternal(item); - result.myNameAttribute = NameAttribute.readExternal(item); - result.mySortOptions = SortOptions.readExternal(item); - result.myPriority = RearrangerSettings.getIntAttribute(item, "priority", 1); - } - -// --------------------------- CONSTRUCTORS --------------------------- - - public CommonAttributes() { - myProtectionLevelAttributes = new ProtectionLevelAttributes(); - myFinalAttribute = new FinalAttribute(); - myStaticAttribute = new StaticAttribute(); - myNameAttribute = new NameAttribute(); - mySortOptions = new SortOptions(); - myPriority = 1; - } - -// --------------------- GETTER / SETTER METHODS --------------------- - - @NotNull - public final NameAttribute getNameAttribute() { - return myNameAttribute; - } - - @NotNull - final public ProtectionLevelAttributes getProtectionLevelAttributes() { - return myProtectionLevelAttributes; - } - - public int getPriority() { - return myPriority; - } - - public void setPriority(int priority) { - this.myPriority = priority; - } - - @NotNull - final public StaticAttribute getStaticAttribute() { - return myStaticAttribute; - } - - @NotNull - public SortOptions getSortOptions() { - return mySortOptions; - } - -// ------------------------ CANONICAL METHODS ------------------------ - - public boolean equals(final Object obj) { - if (!(obj instanceof CommonAttributes)) { - return false; - } - final CommonAttributes ca = (CommonAttributes)obj; - return myProtectionLevelAttributes.equals(ca.myProtectionLevelAttributes) && - myStaticAttribute.equals(ca.myStaticAttribute) && - myFinalAttribute.equals(ca.myFinalAttribute) && - myNameAttribute.equals(ca.myNameAttribute) && - mySortOptions.equals(ca.mySortOptions) && - myPriority == ca.myPriority; - } - -// ------------------------ INTERFACE METHODS ------------------------ - - -// --------------------- Interface IRule --------------------- - - @NotNull - public RuleInstance createRuleInstance() { - return new DefaultRuleInstance(this); - } - - public boolean isMatch(@NotNull RangeEntry rangeEntry) { - return myProtectionLevelAttributes.isMatch(rangeEntry.getModifiers()) && myStaticAttribute.isMatch(rangeEntry.getModifiers()) - && myFinalAttribute.isMatch(rangeEntry.getModifiers()) && myNameAttribute.isMatch(rangeEntry.getName()); - } - - /** - * Returns a boolean indicating if the comments associated with this rule match a global comment pattern. - * Most rules don't have comments, so by default it returns true. - * - * @param pattern global pattern to which all comments should conform - * @return true if comments conform to pattern - */ - public boolean commentsMatchGlobalPattern(String pattern) { - return true; - } - - public List
- * gridy = 0 - * gridx = 0 - * gridheight = 1 - * gridwidth = 1 - * weightx = 0 - * weighty = 0 - * fill = NONE - * anchor = WEST - *- */ - public Constraints() { - fill = GridBagConstraints.NONE; - gridwidth = 1; - gridheight = 1; - anchor = GridBagConstraints.WEST; - weightx = 0.0d; - weighty = 0.0d; - gridx = gridy = 0; - newRow = true; - newRow(); - } - - /** - * Constructs a new Constraints object and initializes a new row.
- * gridy = 0 - * gridx = 0 - * gridheight = 1 - * gridwidth = 1 - * weightx = 0 - * weighty = 0 - * fill = NONE - * anchor = specified parameter - *- */ - public Constraints(int anchor) { - this(); - this.anchor = anchor; - } - - /** - * Prepares for adding components to a new row.
- * gridy++ (if not already at the beginning of a new row) - * gridx = 0 - * gridheight = 1 - * weighty = 0 - *- */ - public void newRow() { - if (!newRow) { - gridy++; - } - gridx = 0; - gridheight = 1; - weighty = 0; - newRow = true; - } - - /** - * Prepares for adding components to a new row, which is weighted.
- * gridy++ (if not the first row) - * gridx = 0 - * gridheight = 1 - * weighty = supplied parameter - *- */ - public void weightedNewRow(double weight) { - newRow(); - weighty = weight; - } - - /** - * Prepares for adding components to a new row, which is weighted.
- * gridy++ (if not the first row) - * gridx = 0 - * gridheight = 1 - * weighty = 1 - *- */ - public void weightedNewRow() { - weightedNewRow(1); - } - - /** - * Prepares for adding components to a new row which will be the last row.
- * gridy++ (if not the first row) - * gridx = 0 - * gridheight = REMAINDER - * weighty = 0 - *- */ - public void lastRow() { - newRow(); - gridheight = REMAINDER; - } - - /** - * Prepares for adding components to a new weightd row which will be the last row.
- * gridy++ (if not the first row) - * gridx = 0 - * gridheight = REMAINDER - * weighty = supplied parameter - *- */ - public void weightedLastRow(double weight) { - lastRow(); - weighty = weight; - } - - /** - * Prepares for adding components to a new weightd row which will be the last row.
- * gridy++ (if not the first row) - * gridx = 0 - * gridheight = REMAINDER - * weighty = 1 - *- */ - public void weightedLastRow() { - weightedLastRow(1); - } - - /** - * Automatically starts a new row if not explicitly done already or if columns have been added since the last - * newRow() call.
- * gridx = 0 - * newRow = false - * gridwidth = 1 - * weightx = 0 - *- * - * @return this Constraints object - */ - public Constraints firstCol() { - if (!newRow) { - newRow(); - } - gridx = 0; - newRow = false; - gridwidth = 1; - weightx = 0; - return this; - } - - /** - * Automatically starts a new weighted row if not explicitly done already or if columns have been added since the last - * newRow() call.
- * gridx = 0 - * newRow = false - * gridwidth = 1 - * weightx = 1 - *- * - * @return this Constraints object - */ - public Constraints weightedFirstCol() { - firstCol(); - weightx = 1; - return this; - } - - /** - * Prepares to add a component to the next column. If this is the first column in the row, - * gridx will be zero (not one).
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = 1 - * weightx = 0 - *- * - * @return this Constraints object - */ - public Constraints nextCol() { - gridx = newRow ? 0 : gridx + 1; - newRow = false; - gridwidth = 1; - weightx = 0; - return this; - } - - /** - * Prepares to add a weighted component to the next column.
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = 1 - * weightx = supplied parameter - *- * - * @return this Constraints object - */ - public Constraints weightedNextCol(double weight) { - nextCol(); - weightx = weight; - return this; - } - - /** - * Prepares to add a weighted component to the next column.
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = 1 - * weightx = 1 - *- * - * @return this Constraints object - */ - public Constraints weightedNextCol() { - return weightedNextCol(1); - } - - /** - * Prepares to add a component to the last column.
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = REMAINDER - * weightx = 0 - *- * - * @return this Constraints object - */ - public Constraints lastCol() { - nextCol(); - gridwidth = REMAINDER; - return this; - } - - /** - * Prepares to add a weighted component to the last column.
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = REMAINDER - * weightx = supplied parameter - *- * - * @return this Constraints object - */ - public Constraints weightedLastCol(double weight) { - weightedNextCol(weight); - gridwidth = REMAINDER; - return this; - } - - /** - * Prepares to add a weighted component to the last column.
- * gridx = gridx + 1 (or zero, if this is the beginning of a new row) - * newRow = false - * gridwidth = REMAINDER - * weightx = 1 - *- * - * @return this Constraints object - */ - public Constraints weightedLastCol() { - weightedLastCol(1); - gridwidth = REMAINDER; - return this; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/util/IconUtil.java b/plugins/rearranger/src/com/wrq/rearranger/util/IconUtil.java deleted file mode 100644 index 2e5c5437a23d..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/util/IconUtil.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.util; - -import com.intellij.openapi.diagnostic.Logger; -import com.wrq.rearranger.Rearranger; - -import javax.swing.*; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; - -/** Utility methods to obtain an icon from a resource or file. */ -public class IconUtil { -// ------------------------------ FIELDS ------------------------------ - - private static final Logger LOG = Logger.getInstance("#" + IconUtil.class.getName()); - -// -------------------------- STATIC METHODS -------------------------- - - - public static final Icon getIcon(String iconName) { - URL iconURL = Rearranger.class.getClassLoader().getResource("com/wrq/rearranger/" + iconName + ".png"); - if (iconURL == null) { - if (true) { -// // for debugging only; -// // in development, there's no resource (no jar file built), -// // so go to the file directly. - try { - URLClassLoader cl = new URLClassLoader( - new URL[] - {new File("/rearranger/lib/rearranger.jar").toURL(), - new File("/IntelliJ-IDEA-4.0/lib/icons.jar").toURL()} - ); - iconURL = cl.getResource("com/wrq/rearranger/" + iconName + ".png"); - if (iconURL == null) { - iconURL = cl.getResource(iconName + ".png"); - } - } - catch (MalformedURLException e) { - iconURL = null; - } - } - } - if (iconURL != null) { - final ImageIcon imageIcon = new ImageIcon(iconURL, iconName); - return imageIcon; - } - LOG.debug( - "getIcon: getResource() could not locate URL for com/wrq/rearranger/" + - iconName + - ".png or " + - iconName + ".png in icons.jar" - ); - return null; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/util/MethodUtil.java b/plugins/rearranger/src/com/wrq/rearranger/util/MethodUtil.java deleted file mode 100644 index c83ba74f8157..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/util/MethodUtil.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.util; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.codeStyle.JavaCodeStyleManager; -import com.intellij.psi.codeStyle.VariableKind; -import com.wrq.rearranger.settings.attributeGroups.GetterSetterDefinition; - -/** Code to determine if a method is truly a simple getter or setter, courtesy of Alain Ravet. */ -public final class MethodUtil { - - public static boolean isGetter(PsiMethod i_method, - GetterSetterDefinition gsd) - { - if (i_method == null) { - return false; - } - - final boolean hasParameters = 1 <= nofParameters(i_method); - if (hasParameters) { - return false; - } - - - final String name = i_method.getName(); - - if (name.startsWith("get")) return getterNameMatchedReturnedValue(i_method, name, "get", gsd); - if (name.startsWith("is")) return getterNameMatchedReturnedValue(i_method, name, "is", gsd); - if (name.startsWith("has")) return getterNameMatchedReturnedValue(i_method, name, "has", gsd); - - return false; - } - - private static boolean getterNameMatchedReturnedValue(PsiMethod i_method, - String i_name, - String i_prefix, - GetterSetterDefinition gsd) - { - String i_methodNameTrail = i_name.substring(i_prefix.length()); - if (!nameIsWellFormed(i_methodNameTrail)) { - return false; - } - - if (isAbstract(i_method)) { - return false; - } - - boolean nameOK = false, bodyOK = false; - switch (gsd.getGetterNameCriterion()) { - case GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX: - nameOK = true; - break; - case GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD: - final String nameFromBody = nameOfVariableReturnedInBody(i_method); - final String propertyName = propertyNameFromMethodTrail(i_methodNameTrail); - nameOK = nameFromBody.equals(fieldName(propertyName, i_method.getProject())); - break; - } - switch (gsd.getGetterBodyCriterion()) { - case GetterSetterDefinition.GETTER_BODY_IMMATERIAL: - bodyOK = true; - break; - case GetterSetterDefinition.GETTER_BODY_RETURNS: - bodyOK = methodContainsReturnStatementOnly(i_method); - break; - case GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD: - final String nameFromBody = nameOfVariableReturnedInBody(i_method); - final String propertyName = propertyNameFromMethodTrail(i_methodNameTrail); - bodyOK = nameFromBody.equals(fieldName(propertyName, i_method.getProject())); - break; - } - return nameOK && bodyOK; - } - - private static boolean methodContainsReturnStatementOnly(PsiMethod i_method) { - final PsiStatement[] statements = i_method.getBody().getStatements(); - return isReturnStatement(statements[0]); - } - - private static String nameOfVariableReturnedInBody(PsiMethod i_method) { - - final PsiStatement[] statements = i_method.getBody().getStatements(); - - if (nofStatements(i_method) == 0) { - return ""; - } - - int returnIndex = statements.length - 1; - if (!isReturnStatement(statements[returnIndex])) { - return ""; - } - final PsiReturnStatement returnStatement = (PsiReturnStatement)statements[returnIndex]; - final PsiExpression returnValue = returnStatement.getReturnValue(); - if (null == returnValue) { - return ""; - } - String returnValueText = returnValue.getText(); - returnValueText = returnValueText.replaceFirst("this\\.", ""); - return returnValueText; - } - - private static String propertyNameFromMethodTrail(String i_source) { - if (i_source.length() > 0) { - final String left = i_source.substring(0, 1).toLowerCase(); - final String right = i_source.substring(1); - - return left + right; - } - else { - return ""; - } - } - - public static String getPropertyName(PsiMethod i_method) { - final String name = i_method.getName(); - - if (name.startsWith("get") || - name.startsWith("has") || - name.startsWith("set")) - { - return name.substring(3); - } - - if (name.startsWith("is")) return name.substring(2); - return name; - } - - public static boolean isSetter(PsiMethod i_method, - GetterSetterDefinition gsd) - { - if (i_method == null) return false; - if (i_method.getBody() == null) return false; - if (nofParameters(i_method) != 1) return false; - if (!i_method.getName().startsWith("set")) return false; - String i_methodNameTrail = i_method.getName().substring("set".length()); - if (i_methodNameTrail.length() == 0) return false; - /** if setter body is immaterial, it can be empty. Otherwise, it must contain at least one statement. */ - if (nofStatements(i_method) == 0 && - gsd.getSetterBodyCriterion() != GetterSetterDefinition.SETTER_BODY_IMMATERIAL) - { - return false; - } - - boolean nameOK = false, bodyOK = false; - PsiElement psiElement = null; - if (nofStatements(i_method) > 0) { - psiElement = i_method.getBody().getStatements()[nofStatements(i_method) - 1].getChildren()[0]; - } - PsiAssignmentExpression assignment = null; - String lExpression = null; - String parameterName = null; - if (psiElement instanceof PsiAssignmentExpression) { - assignment = (PsiAssignmentExpression)psiElement; - lExpression = ((assignment.getLExpression()).getText()).replaceFirst("this.", ""); - parameterName = (i_method.getParameterList()).getParameters()[0].getName(); - } - - String fieldName = fieldName(propertyNameFromMethodTrail(i_methodNameTrail), i_method.getProject()); - switch (gsd.getSetterNameCriterion()) { - case GetterSetterDefinition.SETTER_NAME_CORRECT_PREFIX: - nameOK = true; - break; - case GetterSetterDefinition.SETTER_NAME_MATCHES_FIELD: - nameOK = lExpression != null && - lExpression.equals(fieldName); - break; - } - switch (gsd.getSetterBodyCriterion()) { - case GetterSetterDefinition.SETTER_BODY_IMMATERIAL: - bodyOK = true; - break; - case GetterSetterDefinition.SETTER_BODY_SETS_FIELD: - if (assignment != null && - nameIsWellFormed(i_methodNameTrail) && - assignment.getOperationSign().getText().equals("=")) -// PsiJavaToken.EQ == assignment.getOperationSign().getTokenType() ) - { - PsiExpression rExpressionRaw = assignment.getRExpression(); - bodyOK = rExpressionRaw != null && - parameterName.equals(rExpressionRaw.getText()) && - lExpression != null && - lExpression.equals(fieldName); - } - break; - } - return nameOK && bodyOK; - } - - private static boolean nameIsWellFormed(String i_methodNameTrail) { - final boolean methodNameIsTooShort = i_methodNameTrail.length() == 0; - if (methodNameIsTooShort) { - return false; - } - - final char firstCandidateMemberChar = i_methodNameTrail.charAt(0); - return !Character.isLowerCase(firstCandidateMemberChar); - } - - - private static String fieldName(String i_propertyName, Project project) { - JavaCodeStyleManager i_codeStyleManager = JavaCodeStyleManager.getInstance(project); - return i_codeStyleManager.propertyNameToVariableName(i_propertyName, VariableKind.FIELD); - } - - public static int nofParameters(PsiMethod i_method) { - return i_method.getParameterList().getParameters().length; - } - - private static int nofStatements(PsiMethod i_method) { - return i_method.getBody().getStatements().length; - } - - private static boolean isAbstract(PsiMethod i_method) { - return null == i_method.getBody(); - } - - private static boolean isReturnStatement(final PsiStatement i_statement) { - return i_statement instanceof PsiReturnStatement; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/util/ModifierUtils.java b/plugins/rearranger/src/com/wrq/rearranger/util/ModifierUtils.java deleted file mode 100644 index 6744718c45fe..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/util/ModifierUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger.util; - -import java.lang.reflect.Modifier; -import java.util.StringTokenizer; - -/** Contains utility functions to parse modifiers. */ -public final class ModifierUtils { - /** - * Converts string form of modifiers into a mask. - * - * @param modifierString modifiers to be parsed. - * @return modifier mask corresponding to modifiers in the supplied string. - */ - public static int getModifierMask(final String modifierString) { - /** - * first, determine the modifier mask for the modifiers in the incoming modifier string. - */ - final StringTokenizer st = new StringTokenizer(modifierString); - int mask = 0; - while (st.hasMoreTokens()) { - final String m = st.nextToken(); - for (int i = 1; i != 0; i <<= 1) { - if (Modifier.toString(i).equals(m)) { - mask |= i; - break; - } - } - } - return mask; - } -} diff --git a/plugins/rearranger/src/com/wrq/rearranger/util/RearrangerConstants.java b/plugins/rearranger/src/com/wrq/rearranger/util/RearrangerConstants.java deleted file mode 100644 index 48784fb9a58b..000000000000 --- a/plugins/rearranger/src/com/wrq/rearranger/util/RearrangerConstants.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.wrq.rearranger.util; - -import org.jetbrains.annotations.NonNls; - -/** - * @author Denis Zhdanov - * @since 5/14/12 12:57 PM - */ -public class RearrangerConstants { - - @NonNls - public static final String DEFAULT_CONFIG_PATH = "com/wrq/rearranger/defaultConfiguration.xml"; - - private RearrangerConstants() { - } -} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java b/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java deleted file mode 100644 index 78865f5de646..000000000000 --- a/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger; - -import com.intellij.testFramework.SkipInHeadlessEnvironment; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import com.wrq.rearranger.settings.RearrangerSettings; - -/** - * @author davek - * Date: Mar 30, 2004 - */ -@SkipInHeadlessEnvironment -public class InteractiveTest extends LightCodeInsightFixtureTestCase { - public static final String DEFAULT_CONFIGURATION = "/src/com/wrq/rearranger/defaultConfiguration.xml"; - private RearrangerSettings mySettings; - - @Override - protected String getBasePath() { - return "/plugins/rearranger/test/testData/com/wrq/rearranger"; - } - - protected final void setUp() throws Exception { - super.setUp(); - - mySettings = new RearrangerSettings(); - mySettings.setAskBeforeRearranging(true); - mySettings.setRearrangeInnerClasses(true); - } - - public final void testLiveRearrangerDialog() throws Exception { - //configureByFile("/com/wrq/rearranger/RearrangementTest28.java"); - //final PsiFile file = getFile(); - //final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); - //final LiveRearrangerActionHandler rah = new LiveRearrangerActionHandler(); - //rah.liveRearrangeDocument(getProject(), file, mySettings, doc, 0); - //super.checkResultByFile("/com/wrq/rearranger/RearrangementTest28.java"); - } - - //public final void testSettingsPanel() throws Exception { - // Rearranger rearranger = new Rearranger(); - // SAXBuilder builder = new SAXBuilder(); - // org.jdom.Document doc = null; - // FileInputStream in = new FileInputStream(new File(DEFAULT_CONFIGURATION)); - // try { - // doc = builder.build(in); - // } - // catch (JDOMException e) { - // e.printStackTrace(); - // } - // catch (FileNotFoundException e) { - // File f = new File(DEFAULT_CONFIGURATION); - // System.out.println(f.getAbsolutePath()); - // e.printStackTrace(); - // } - // catch (IOException e) { - // e.printStackTrace(); - // } - // finally { - // in.close(); - // } - // - // assert doc != null; - // Element appElement = doc.getRootElement(); - // java.util.List componentList = appElement.getChildren(); - // Element rearrangerElement = null; - // if (appElement.getName().equals("component") && - // appElement.getAttributeValue("name").equals(Rearranger.COMPONENT_NAME)) - // { - // rearrangerElement = appElement; - // } - // else { - // for (Object aComponentList : componentList) { - // Element e = (Element)aComponentList; - // if (e.getAttributeValue("name").equals(Rearranger.COMPONENT_NAME)) { - // rearrangerElement = e; - // break; - // } - // } - // } - // if (rearrangerElement != null) { - // rearranger.readExternal(rearrangerElement); - // } - // final JDialog frame = new JDialog((Frame)null, "SwingApplication"); - // final Constraints constraints = new Constraints(GridBagConstraints.NORTHWEST); - // constraints.fill = GridBagConstraints.BOTH; - // constraints.weightedLastRow(); - // RearrangerSettings settings = rearranger.getSettings(); - // final RearrangerSettingsPanel object = new RearrangerSettingsPanel(settings); - // frame.getContentPane().setLayout(new GridBagLayout()); - // frame.getContentPane().add(object, constraints.weightedLastCol()); - // //Finish setting up the frame, and show it. - // frame.pack(); - // frame.setResizable(true); - // frame.setModal(true); - // frame.setVisible(true); - // final RearrangerSettings rs = object.settings.deepCopy(); - // assertTrue("Settings are unequal", rs.equals(object.settings)); - // System.out.println("Class Order"); - // for (Object o : object.settings.getClassOrderAttributeList()) { - // if (o instanceof Rule && o instanceof PrioritizedRule) { - // System.out.println(o + ", pri=" + ((Rule)o).getPriority()); - // } - // else { - // System.out.println(o); - // } - // } - // System.out.println("Item order"); - // for (Object o : object.settings.getItemOrderAttributeList()) { - // if (o instanceof Rule && o instanceof PrioritizedRule) { - // System.out.println(o + ", pri=" + ((Rule)o).getPriority()); - // } - // else { - // System.out.println(o); - // } - // } - // object.checkCommentsAgainstGlobalPattern(object.settings); - //} -} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy deleted file mode 100644 index df55096c0da7..000000000000 --- a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy +++ /dev/null @@ -1,1123 +0,0 @@ -/* - * Copyright (c) 2003, 2010, Dave Kriewall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.wrq.rearranger; - - -import com.intellij.openapi.application.ApplicationManager -import com.intellij.psi.JavaPsiFacade -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiMethod -import com.intellij.psi.PsiModifier -import com.intellij.testFramework.PlatformTestUtil -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import com.wrq.rearranger.settings.CommentRule -import com.wrq.rearranger.settings.RearrangerSettings -import com.wrq.rearranger.settings.RelatedMethodsSettings -import com.wrq.rearranger.settings.attributeGroups.GetterSetterDefinition -import com.wrq.rearranger.settings.attributeGroups.InterfaceAttributes -import com.wrq.rearranger.settings.attributeGroups.RegexUtil -import com.wrq.rearranger.util.CommentRuleBuilder -import com.wrq.rearranger.util.SettingsConfigurationBuilder -import org.jetbrains.annotations.NotNull -import org.jetbrains.annotations.Nullable -import com.wrq.rearranger.util.java.* - -/** JUnit tests for the rearranger plugin. */ -class RearrangerTest extends LightCodeInsightFixtureTestCase { - - private RearrangerSettings mySettings - private SettingsConfigurationBuilder settings - private JavaClassRuleBuilder classRule - private JavaInterfaceRuleBuilder interfaceRule - private JavaInnerClassRuleBuilder innerClassRule - private JavaFieldRuleBuilder fieldRule - private JavaMethodRuleBuilder methodRule - private CommentRuleBuilder commentRule - private JavaSpacingRule spacingRule - - @Override - protected String getBasePath() { - return "/plugins/rearranger/test/testData/com/wrq/rearranger"; - } - - protected final void setUp() throws Exception { - super.setUp(); - - mySettings = new RearrangerSettings(); -// rs.setAskBeforeRearranging(true); // uncomment for debugging file structure popup - mySettings.showFields = true - mySettings.showParameterNames = true - mySettings.showParameterTypes = true - mySettings.showRules = true - mySettings.rearrangeInnerClasses = true - - prepareBuilders(mySettings) - } - - private void prepareBuilders(RearrangerSettings mySettings) { - settings = new SettingsConfigurationBuilder(settings: mySettings) - classRule = new JavaClassRuleBuilder(settings: mySettings) - interfaceRule = new JavaInterfaceRuleBuilder(settings: mySettings) - innerClassRule = new JavaInnerClassRuleBuilder(settings: mySettings) - fieldRule = new JavaFieldRuleBuilder(settings: mySettings) - methodRule = new JavaMethodRuleBuilder(settings: mySettings) - commentRule = new CommentRuleBuilder(settings: mySettings) - spacingRule = new JavaSpacingRule(settings: mySettings) - } - - public final void testNoRearrangement() throws Exception { - doTest('RearrangementTest', 'NoRearrangementResult1') - } - - public final void testPublicFieldRearrangement() throws Exception { - doTest('RearrangementTest', 'RearrangementResult2') { - fieldRule.modifier PsiModifier.PUBLIC - } } - - public final void testNotPublicFieldRearrangement() throws Exception { - doTest('RearrangementTest', 'RearrangementResult3') { - fieldRule.modifier PsiModifier.PUBLIC, invert: true - } } - - public final void testConstructorRearrangement() throws Exception { - doTest('RearrangementTest', 'RearrangementResult4') { - methodRule.create { - modifier([ PsiModifier.PUBLIC, PsiModifier.PACKAGE_LOCAL ]) - target( MethodType.CONSTRUCTOR ) - } } } - - public final void testClassRearrangement() throws Exception { - doTest('RearrangementTest', 'RearrangementResult5') { - classRule.create { - modifier( PsiModifier.PACKAGE_LOCAL ) - } } } - - public final void testPSFRearrangement() throws Exception { - doTest('RearrangementTest2', 'RearrangementResult6') { - fieldRule.create { - modifier([ PsiModifier.FINAL, PsiModifier.STATIC ]) - } } } - - public final void testAnonClassInit() throws Exception { - doTest('RearrangementTest7', 'RearrangementResult7') { - fieldRule.create { - initializer( InitializerType.ANONYMOUS_CLASS ) - } } } - - public final void testNameMatch() throws Exception { - doTest('RearrangementTest', 'RearrangementResult8') { - fieldRule.create { name('.*5') } - methodRule.create { name('.*2') } - } } - - public final void testStaticInitializer() throws Exception { - doTest('RearrangementTest8', 'RearrangementResult8A') { - methodRule.create { modifier( PsiModifier.STATIC ) } - } } - - public final void testAlphabetizingGSMethods() throws Exception { - mySettings.keepGettersSettersTogether = false - doTest('RearrangementTest', 'RearrangementResult9') { - methodRule.create { - target([ MethodType.GETTER_OR_SETTER, MethodType.OTHER ]) - 'sort by'( SortOption.NAME ) - } } } - - public final void testSimpleComment() throws Exception { - doTest('RearrangementTest', 'RearrangementResult10') { - fieldRule.create { modifier( PsiModifier.PUBLIC) } - commentRule.create { - comment( '// simple comment **********', condition: CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE ) - } } } - - /** - * Delete old comment and insert (identical) new one. This tests proper identification and deletion of old - * comments. - * - * @throws Exception test exception - */ - public final void testReplayComment() throws Exception { - doTest('RearrangementResult10', 'RearrangementResult10') { - fieldRule.create { modifier( PsiModifier.PUBLIC) } - commentRule.create { - comment( '// simple comment **********', condition: CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE ) - } } } - - public final void testMultipleRuleCommentMatch() throws Exception { - doTest('RearrangementTest11', 'RearrangementResult11') { - commentRule.create { comment('// FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false) } - commentRule.create { comment('// FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, - 'subsequent rules to match': 1) } - fieldRule.create { modifier(PsiModifier.FINAL) } - commentRule.create { comment('// NON-FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, - 'subsequent rules to match': 1) } - fieldRule.create { modifier(PsiModifier.FINAL, invert: true) } - } } - - public final void testOpsBlockingQueueExample() throws Exception { - testOpsBlockingQueueExampleWorker(false, "OpsBlockingQueue", false, "OpsBlockingQueue"); - } - - public final void testOpsBlockingQueueExampleWithGlobalPattern() throws Exception { - testOpsBlockingQueueExampleWorker(true, "OpsBlockingQueue", false, "OpsBlockingQueue"); - } - - public final void testOpsBlockingQueueExampleWithIndentedComments() throws Exception { - testOpsBlockingQueueExampleWorker(false, "OpsBlockingQueueIndented", true, "OpsBlockingQueueIndentedResult"); - } - - private void testOpsBlockingQueueExampleWorker(boolean doGlobalPattern, - String srcFilename, - boolean doublePublicMethods, - String compareFilename) - throws Exception - { - // submitted by Joe Martinez. - doTest(srcFilename, compareFilename) { - commentRule.create { - comment('//************************************** PUBLIC STATIC FIELDS *************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, - 'subsequent rules to match': 2, 'preceding rules to match': 1) - } - fieldRule.create { - modifier([ PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL ]) - 'sort by'( SortOption.NAME ) - } - fieldRule.create { - modifier([ PsiModifier.PUBLIC, PsiModifier.STATIC ]) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//************************************** PUBLIC FIELDS *****************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - fieldRule.create { - modifier( PsiModifier.PUBLIC ) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//*********************************** PROTECTED/PACKAGE FIELDS **************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, - 'subsequent rules to match': 3, 'preceding rules to match': 1) - } - fieldRule.create { - modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.STATIC, PsiModifier.FINAL ]) - 'sort by'( SortOption.NAME ) - } - fieldRule.create { - modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.STATIC ]) - 'sort by'( SortOption.NAME ) - } - fieldRule.create { - modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL ]) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//************************************** PRIVATE FIELDS *****************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - fieldRule.create { - modifier( PsiModifier.PRIVATE ) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//************************************** CONSTRUCTORS ************************************* ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, - 'subsequent rules to match': 2, 'preceding rules to match': 1) - } - methodRule.create { - modifier( PsiModifier.PUBLIC ) - target( MethodType.CONSTRUCTOR ) - } - methodRule.create { target( MethodType.CONSTRUCTOR ) } - commentRule.create { - comment('//*********************************** GETTERS AND SETTERS ********************************** ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, - 'subsequent rules to match': 2, 'preceding rules to match': 1) - } - methodRule.create { - modifier( PsiModifier.PUBLIC ) - target( MethodType.GETTER_OR_SETTER ) - 'sort by'( SortOption.NAME ) - } - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'sort by'( SortOption.NAME ) - } - def text = '//************************************** PUBLIC METHODS ************************************* ' - if (doublePublicMethods) { - text += "\n// PUBLIC METHODS LINE 2"; - } - commentRule.create { - comment(text, condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - methodRule.create { - modifier( PsiModifier.PUBLIC ) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//********************************* PACKAGE/PROTECTED METHODS ******************************** ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - methodRule.create { - modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL ]) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//************************************** PRIVATE METHODS *************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - methodRule.create { - modifier( PsiModifier.PRIVATE ) - 'sort by'( SortOption.NAME ) - } - commentRule.create { - comment('//************************************** INNER CLASSES ************************************* ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, - 'subsequent rules to match': 1, 'preceding rules to match': 1) - } - innerClassRule.create { 'sort by'(SortOption.NAME ) } - - mySettings.extractedMethodsSettings.moveExtractedMethods = false - if (doGlobalPattern) { - mySettings.globalCommentPattern = "//\\*{20,45}[A-Z /]*\\*{20,45}\n" - } - } - } - - public final void testReturnTypeMatch() throws Exception { - doTest('RearrangementTest12', 'RearrangementResult12') { - methodRule.create { 'return type'( 'void' ) } - fieldRule.create { type( 'int' ) } - methodRule.create { 'return type'( '.*je.*' ) } - methodRule.create { 'return type'( /Integer\[\]/) } - methodRule.create { 'return type'( 'int' ) } - } } - - public final void testRelatedMethodsDepthOriginal() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13DO') { - settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) - } } - - public final void testRelatedMethodsDepthAlphabetical() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13DA') { - settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) - } } - - public final void testRelatedMethodsDepthInvocation() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13DI') { - settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.INVOCATION_ORDER ) - } } - - public final void testRelatedMethodsBreadthOriginal() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13BO') { - settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) - } } - - public final void testRelatedMethodsBreadthAlphabetical() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13BA') { - settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.ALPHABETICAL_ORDER) - } } - - public final void testRelatedMethodsBreadthInvocation() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13BI') { - settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.INVOCATION_ORDER) - } } - - private void doTestEmitComments(args) { - doTest(args.initial?: 'RearrangementTest13', args.expected) { - settings.'extracted methods'( 'depth-first order': args.depthFirst, order: args.orderType, commentType: args.commentType ) - - def precedingCommentRule = new CommentRule() - precedingCommentRule.commentText = '''\ -// Preceding comment: TL=%TL% -// MN=%MN% -// AM=%AM% -// Level %LV%''' - mySettings.extractedMethodsSettings.precedingComment = precedingCommentRule - - def trailingCommentRule = new CommentRule() - trailingCommentRule.commentText = '''\ -// Trailing comment: TL=%TL% -// MN=%MN% -// AM=%AM% -// Level %LV%''' - mySettings.extractedMethodsSettings.trailingComment = trailingCommentRule - } } - - public final void testEmitTLCommentsRelatedMethodsBreadthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13BITLC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL - ) - } - - public final void testEmitEMCommentsRelatedMethodsBreadthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13BIEMC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD - ) - } - - public final void testEmitELCommentsRelatedMethodsBreadthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13BIELC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL - ) - } - - public final void testEmitNFCommentsRelatedMethodsBreadthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13BINFC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY - ) - } - - public final void testEmitTLCommentsRelatedMethodsDepthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13DITLC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL - ) - } - - public final void testEmitEMCommentsRelatedMethodsDepthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13DIEMC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD - ) - } - - public final void testEmitELCommentsRelatedMethodsDepthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13BIELC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL - ) - } - - public final void testEmitNFCommentsRelatedMethodsDepthInvocation() throws Exception { - doTestEmitComments( - expected: 'RearrangementResult13DINFC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY - ) - } - - public final void testRelatedMethodsException() throws Exception { - doTest('RearrangementTest13', 'RearrangementResult13Ex') { - settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) - methodRule.create { name('GF') } - } } - - public final void testKeepOverloadedMethodsTogether() throws Exception { - doTest('RearrangementTest14', 'RearrangementResult14') { - settings.configure { - 'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.INVOCATION_ORDER ) - 'keep together'( 'overloaded' ) - } } } - - public final void testXML() throws Exception { doTest('RearrangementTest17', 'RearrangementTest17', 'xml') } - - public final void testKeepGSTogether() throws Exception { - doTest('RearrangementTest18', 'RearrangementResult18') { - settings.configure { - 'extracted methods'( order: RelatedMethodsSettings.INVOCATION_ORDER ) - 'keep together'( 'getters and setters' ) - } - fieldRule.create {} - methodRule.create { target( MethodType.CONSTRUCTOR ) } - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'sort by'( SortOption.NAME ) - } } } - - public final void testKeepGSWithProperty() throws Exception { - doTest('RearrangementTest18', 'RearrangementResult18A') { - settings.configure { - 'extracted methods'( order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) - 'keep together'([ 'getters and setters', 'getters and setters with property' ]) - } - fieldRule.create { } - methodRule.create { target(MethodType.CONSTRUCTOR) } - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'sort by'( SortOption.NAME ) - } } } - - public final void testKeepGSWithPropertyElseTogether() throws Exception { - doTest('RearrangementTest18B', 'RearrangementResult18B') { - settings.configure { - 'extracted methods'( order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) - 'keep together'([ 'getters and setters', 'getters and setters with property' ]) - } - fieldRule.create { } - commentRule.create { - comment('// Getters/Setters', condition: CommentRule.EMIT_ALWAYS) - } - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.GETTER_BODY_IMMATERIAL - ) - 'setter criteria'( - name: GetterSetterDefinition.SETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.SETTER_BODY_IMMATERIAL - ) - 'sort by'( SortOption.NAME ) - } - commentRule.create { comment('// Other Methods', condition: CommentRule.EMIT_ALWAYS) } - methodRule.create { 'sort by'( SortOption.NAME ) } - } } - - public final void testKeepOverloadsTogetherOriginalOrder() throws Exception { - doTest('RearrangementTest19', 'RearrangementResult19A') { - settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_RETAIN_ORIGINAL ) - } } - - public final void testKeepOverloadsTogetherAscendingOrder() throws Exception { - doTest('RearrangementTest19', 'RearrangementResult19B') { - settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS ) - } } - - public final void testKeepOverloadsTogetherDescendingOrder() throws Exception { - doTest('RearrangementTest19', 'RearrangementResult19C') { - settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_DESCENDING_PARAMETERS ) - } } - - public final void testInnerClassReferenceToChild() throws Exception { - doTest('RearrangementTest20', 'RearrangementResult20') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - } } - - public final void testMultipleFieldDecl() throws Exception { - doTest('RearrangementTest21', 'RearrangementResult21') { - fieldRule.create { 'sort by'( SortOption.NAME ) } - } } - - public final void testRemoveBlankLines() throws Exception { - doTest('SpaceTest1', 'SpaceResult1') { - spacingRule.create { - spacing(anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE, SpacingAnchor.BEFORE_METHOD_RBRACE, - SpacingAnchor.BEFORE_CLASS_RBRACE, SpacingAnchor.AFTER_CLASS_RBRACE ], - lines: 0) - } - spacingRule.create { - spacing( anchor: SpacingAnchor.EOF, lines: 1 ) - } - mySettings.removeBlanksInsideCodeBlocks = true - } } - - public final void testAddBlankLines() throws Exception { - doTest('SpaceTest2', 'SpaceResult2') { - spacingRule.create { - spacing( anchor: [ SpacingAnchor.AFTER_METHOD_RBRACE, SpacingAnchor.EOF ], lines: 1) - spacing(anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE ], lines: 2) - spacing( anchor: SpacingAnchor.AFTER_CLASS_RBRACE, lines: 4) - } - mySettings.removeBlanksInsideCodeBlocks = true - } } - - public final void testInnerClassBlankLines() throws Exception { - doTest('SpaceTest4', 'SpaceResult4') { - spacingRule.create { - spacing(anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE, SpacingAnchor.BEFORE_METHOD_RBRACE ], - lines: 0) - spacing(anchor: [ SpacingAnchor.AFTER_METHOD_RBRACE, SpacingAnchor.EOF ], - lines: 1) - } - mySettings.removeBlanksInsideCodeBlocks = true - } } - - public void testInnerClassSpacing() throws Exception { - doTest('SpaceTest5', 'SpaceResult5') { - spacingRule.create { - spacing( anchor: SpacingAnchor.AFTER_CLASS_RBRACE, lines: 2 ) - spacing( anchor: SpacingAnchor.EOF, lines: 3 ) - } } } - - public void testSpacingWithTrailingWhitespace() throws Exception { - doTest('SpaceTest6', 'SpaceResult6') { - spacingRule.create { spacing( anchor: SpacingAnchor.EOF, lines: 1 ) } - } } - - /** - * Submitted by Brian Buckley. - * - * @throws Exception test exception - */ - public void testSpacingConflictingSettingBug() throws Exception { - doTest('SpaceTest8', 'SpaceResult8') { - spacingRule.create { spacing( anchor: SpacingAnchor.AFTER_CLASS_LBRACE, lines: 0) } - spacingRule.create { - spacing( anchor: [ SpacingAnchor.BEFORE_METHOD_LBRACE, SpacingAnchor.EOF ], lines: 1) - } } } - - public void testGetPrefixImmaterial() throws Exception { - doTest('GetterDefinitionTest', 'GetPrefixImmaterialResult') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.GETTER_BODY_IMMATERIAL - ) } } } - - public void testGetPrefixReturns() throws Exception { - doTest('GetterDefinitionTest', 'GetPrefixReturnsResult') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.GETTER_BODY_RETURNS - ) } } } - - public void testGetPrefixReturnsField() throws Exception { - doTest('GetterDefinitionTest', 'GetPrefixReturnsFieldResult') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD - ) } } } - - public void testGetFieldReturns() throws Exception { - doTest('GetterDefinitionTest', 'GetFieldReturnsResult') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD, - body: GetterSetterDefinition.GETTER_BODY_RETURNS - ) } } } - - public void testGetFieldReturnsField() throws Exception { - doTest('GetterDefinitionTest', 'GetFieldReturnsFieldResult') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD, - body: GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD - ) } } } - - public void testSpecialGS() throws Exception { - doTest('RearrangementTest22', 'RearrangementResult22') { - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - 'getter criteria'( - name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.GETTER_BODY_RETURNS - ) - 'setter criteria'( - name: GetterSetterDefinition.SETTER_NAME_CORRECT_PREFIX, - body: GetterSetterDefinition.SETTER_BODY_IMMATERIAL - ) } - mySettings.keepGettersSettersTogether = true - } } - - public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodAlphabetical() throws Exception { - doTest('RearrangementTest23', 'RearrangementResult23NNNANXMA') { - mySettings.keepGettersSettersTogether = false - interfaceRule.create { - 'preceding comment'( '/**** Interface %IF% Header ****/' ) - 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) - setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_ALPHABETICAL, alphabetize: false ) - } } } - - public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { - doTest('RearrangementTest23', 'RearrangementResult23NNNANXME') { - mySettings.keepGettersSettersTogether = false - interfaceRule.create { - 'preceding comment'( '/**** Interface %IF% Header ****/' ) - 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) - setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, alphabetize: false ) - } } } - - public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodInterfaceOrder() throws Exception { - doTest('RearrangementTest23', 'RearrangementResult23NNNANXMI') { - mySettings.keepGettersSettersTogether = false - interfaceRule.create { - 'preceding comment'( '/**** Interface %IF% Header ****/' ) - 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) - setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_INTERFACE_ORDER, alphabetize: false ) - } } } - - public void testInterfaceByNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { - doTest('RearrangementTest23', 'RearrangementResult23BNNANXME') { - mySettings.keepGettersSettersTogether = false - interfaceRule.setup( "don't group extracted methods": true, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, - alphabetize: false, name : 'IFace1' - ) } } - - public void testInterfaceIsAlphabeticalNoExcludeMethodEncountered() throws Exception { - doTest('RearrangementTest23', 'RearrangementResult23NNIANXME') { - interfaceRule.create { - 'preceding comment'( '/**** Interface %IF% Header ****/' ) - 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) - setup( "don't group extracted methods": true, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, alphabetize: true ) - } } } - - public void testSpacingOptions() throws Exception { - /* - * From Thomas Singer: - * I've enabled - * - Force 0 blank lines before class close brace "}" - * - Force 0 blank lines before method close brace "}" - * - Remove initial and final blank lines inside code block - * but in the code below the blank lines don't get removed when invoking - * Rearranger from editor's context menu: - */ - doTest('RearrangementTest25', 'RearrangementResult25') { - spacingRule.spacing(anchor: [ SpacingAnchor.BEFORE_CLASS_RBRACE, SpacingAnchor.BEFORE_METHOD_RBRACE ], - lines: 0, 'remove blank lines': true - ) } } - - public void testPriority() throws Exception { - doTest('RearrangementTest', 'RearrangementResult1A') { - methodRule.create { priority( 1 ) } - methodRule.create { - priority( 2 ) - name( 'method.*' ) - } - methodRule.create { - priority( 2 ) - name( '.*Method' ) - } } } - - public void testGSRuleWithClassInitializer() throws Exception { - doTest('RearrangementTest26', 'RearrangementResult26') { - mySettings.keepOverloadedMethodsTogether = true - methodRule.create { - target( MethodType.GETTER_OR_SETTER ) - } } } - - public void testKeepGSTogetherAndExtractedMethods() throws Exception { - doTest('RearrangementTest27', 'RearrangementResult27') { - settings.configure { - 'keep together'([ 'getters and setters', 'overloaded' ]) - 'extracted methods' move: true - } } } - - public void testRegexEscape() throws Exception { - String s = "// ********* start of fields *********"; - String result = RegexUtil.escape(s); - assertEquals("sequence reduction failed", "// \\*{9} start of fields \\*{9}", result); - s = "// \\ backslash \n \t \\d [...] (^...\$)"; - result = RegexUtil.escape(s); - assertEquals("special character escape failed", "// \\\\ backslash \\n \\t \\\\d \\[\\.\\.\\.\\]" + - " \\(\\^\\.\\.\\.\\\$\\)", result); - } - - public void testRegexCombine() throws Exception { - String p1 = RegexUtil.escape("// ********* start of fields *********"); - String p2 = RegexUtil.escape("// ********* start of methods *********"); - List
'property id'
- * is expected to be one of the {@link RearrangerTestDsl#getValue()} predefined constants}.
- *
- * Corresponding value is a closure that receives three arguments - target attribute value, attribute customization map
- * and target rule instance .
- */
- @NotNull private def myHandlers = [:].withDefault {
- { key -> Assert.fail("No handler for the rule attribute '${key}'") }
- }
-
- @Override
- protected Object getCurrent() {
- if (!super.current) {
- current = createRule()
- }
- super.current
- }
-
- @Override
- protected void nodeCompleted(Object parent, Object node) {
- if (--depth <= 0) {
- // Top level call on the build object has been reached.
- registerRule(settings, node as T)
- current = null
- }
- }
-
- @Override
- protected void setParent(Object parent, Object child) {
- depth++
- }
-
- @Override
- protected Object createNode(Object name) {
- createNode(name, [:], [])
- }
-
- @Override
- protected Object createNode(Object name, Object value) {
- createNode(name, [:], value)
- }
-
- @Override
- protected Object createNode(Object name, Map attributes) {
- createNode(name, attributes, [])
- }
-
- @Override
- protected Object createNode(Object name, Map attributes, Object value) {
- if (!myHandlers.containsKey(name)) {
- return current
- }
- if (value) {
- for (i in [value].flatten()) {
- myHandlers[name](i, attributes, current)
- }
- }
- else {
- myHandlers[name](null, attributes, current)
- }
-
- current
- }
-
- @Nullable
- protected abstract T createRule()
-
- protected abstract void registerRule(@NotNull RearrangerSettings settings, @NotNull T rule)
-
- /**
- * Registers given handler for the rule customization within the given data.
- *
- * Example:
- *
- * register('modifier', PsiModifier.FINAL, { value, attributes, rule ->
- * rule.finalAttribute.value = value
- * if (attributes.invert) rule.finalAttribute.invert = true
- * })
- *
- *
- * @param specifier target rule attribute specifier used at the test DSL
- * @param handler closure to apply target information to the rule instance. Accepts two values - target rule instance
- * and additional rule attribute information map
- */
- protected void registerHandler(@NotNull RearrangerTestDsl specifier, @NotNull Closure handler) {
- myHandlers[specifier.value] = handler
- true
- }
-
- /**
- * Allows to get a closure with the following properties:
- * - *
{ attributes, rule -> ...}, it configure 'rule.propertyName'
- * according to the 'attributes' argument.
- *
- * @param propertyName name of the target attribute property at the target rule class
- * @return closure to use for updating target attribute
- */
- @NotNull
- protected static Closure createBooleanAttributeHandler(@NotNull final String propertyName) {
- { attributes, T rule ->
- rule."$propertyName".value = true
- if (attributes[RearrangerTestDsl.INVERT.value]) {
- rule."$propertyName".invert = true
- }
- }
- }
-
- /**
- * Very similar to the {@link #createBooleanAttributeHandler(java.lang.String)} but targets boolean property with the given name
- * at the given rule argument.
- *
- * @param propertyName name of the target attribute property at the target rule class
- * @return closure to use for updating target attribute
- */
- @NotNull
- protected static Closure createRawBooleanAttributeHandler(@NotNull final String propertyName) {
- { attributes, T rule -> rule."$propertyName" = true }
- }
-
- protected static Closure createStringAttributeHandler(@NotNull final String propertyName) {
- { value, attributes, T rule ->
- rule."$propertyName".match = true
- rule."$propertyName".expression = value
- }
- }
-}
diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy
deleted file mode 100644
index 0c9b4a4ac17b..000000000000
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.wrq.rearranger.util;
-
-import com.wrq.rearranger.settings.CommentRule;
-import com.wrq.rearranger.settings.RearrangerSettings;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author Denis Zhdanov
- * @since 5/17/12 4:08 PM
- */
-class CommentRuleBuilder extends AbstractRuleBuilder"); - } - if (desc != null && desc.length() > 0) { - tt.append(desc).append("
"); - } - if (filePath != null && filePath.length() > 0) { - tt.append(filePath).append("
"); - } - } - - private void buildGroupToolTip(StringBuilder tt) { - String desc = getDescription(); - if (desc != null && desc.length() > 0) { - tt.append(desc).append("
"); - } - } - - public String getDescription() { - if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) { - return getInstruction(getInstructionItem().getInstructionRef()).getDescription(); - } - return storage.getDescription(); - } - - private void buildInstructionToolTip(StringBuilder tt) { - InstructionItem inst = getInstructionItem(); - if (inst != null) { - String id = inst.getInstructionRef(); - Instruction instruction = getInstruction(id); - tt.append("Command: ").append(instruction.getCommand()).append("
"); - } - tt.append("Parameter: ").append(getParameter()).append("
"); - tt.append("Received: ").append(getReceiptString()).append("
"); - tt.append("Expected: ").append(getExpectedReceiptString()).append("
"); - } - - public InstructionItem getInstructionItem() { - return storage.getInstructionItem(); - } - - public Instruction getInstruction(String id) { - return null; - } - - private void buildRunInfoToolTip(StringBuilder tt) { - tt.append("
"); - tt.append("Pause: ").append(getDelay()).append("
"); - tt.append("State: ").append(getStateText()).append("
"); // todo add state color getStatecolor()... - tt.append("Duration: ").append(getDuration()).append("
"); - tt.append("Executed: ").append(getLastTested()).append("
");
- }
-
- public boolean hasChildren() {
- return childNodes.size() > 0;
- }
-
- public int indexOf(Enum1Test t) {
- return childNodes.indexOf(t);
- }
-
- public boolean isGroup() {
- return getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION);
- }
-
- public void remove(Enum1Test node) {
- childNodes.remove(node);
- // node.setParent(null);
- }
-
- public void setDelay(long delay) {
- long oldDelay = storage.getDelay();
- storage.setDelay(delay);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DELAY, oldDelay, delay, this);
- }
-
- public void setDescription(String description) {
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed for instructions
- }
- String oldDescription = storage.getDescription();
- storage.setDescription(description);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DESC, oldDescription, description, this);
- }
-
- public void setDuration(long duration) {
- if (!getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed anything execept instructions
- }
- long oldDuration = getDuration();
- storage.setDuration(duration);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DURATION, oldDuration, duration, this);
- }
-
- public long getDuration() {
- long durationSum = 0;
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- durationSum += storage.getDuration();
- }
- else {
- for (Enum1Test t : childNodes) {
- durationSum += t.getDuration();
- }
- }
- return durationSum;
- }
-
- public void setExpectedReceipt(byte[] newValue) {
- }
-
- public void setInstructionItem(InstructionItem instruction) {
- InstructionItem oldInstruction = this.getInstructionItem();
- storage.setInstructionItem(instruction);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_INSTRUCTION, oldInstruction, instruction, this);
- }
-
- public void setIterations(int iterations) {
- int oldIterations = storage.getIterations();
- storage.setIterations(iterations);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_ITERATIONS, oldIterations, iterations, this);
- }
-
- public void setLastTested(Date lastTested) {
- Date oldLastTested = getLastTested();
- storage.setLastTested(new Date());
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_LAST_TESTED, oldLastTested, lastTested, this);
- }
-
- public Date getLastTested() {
- Date date = storage.getLastTested();
- return date == null ? null : date;
- }
-
- public void setName(String name) {
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed for instructions
- }
- String oldName = storage.getName();
- storage.setName(name);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_NAME, oldName, name, this);
- }
-
- public void setParameter(String value) {
- }
-
- private void setStereotype(Stereotype type) {
- }
-
- public void setStorage(SuiteItem suiteItem) {
- }
-
-// -------------------------- ENUMERATIONS --------------------------
-
- public enum ExecutionState {
- PASSED, FAILED, UNTESTED
- }
-
- public enum Stereotype {
- STEREOTYPE_ROOT, STEREOTYPE_GROUP, STEREOTYPE_INSTRUCTION
- }
-
- public enum Direction {
- UP, DOWN
- }
-}
-
-class InstructionItem {
-// -------------------------- OTHER METHODS --------------------------
-
- public byte[] getExpectedReceipt() {
- return new byte[0]; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getInstructionRef() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getParameter() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public byte[] getReceipt() {
- return null;
- }
-
- public void setExpectedReceipt(byte[] newValue) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setParameter(String value) {
- //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class Instruction {
-// -------------------------- OTHER METHODS --------------------------
-
- public String getCommand() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getDescription() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getName() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class SuiteModel {
-// ------------------------------ FIELDS ------------------------------
-
- public static final Object EVT_TOPIC_EXPECTED_RECEIPT = "";
- public static final Object EVT_TOPIC_PARAMETER = "";
- public static final Object EVT_TOPIC_PARENT = "";
- public static final Object EVT_TOPIC_DELAY = "";
- public static Object EVT_TOPIC_DESC = "";
- public static Object EVT_TOPIC_DURATION = "";
- public static Object EVT_TOPIC_INSTRUCTION = "";
- public static Object EVT_TOPIC_ITERATIONS = "";
- public static Object EVT_TOPIC_LAST_TESTED = "";
- public static Object EVT_TOPIC_NAME = "";
-
-// -------------------------- OTHER METHODS --------------------------
-
- public void fireChangeEvent(Object p0, Object oldValue, Object newValue, Enum1Test testEnum) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getAuthor() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public DataFlowRunner getInstructionSet() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public File getStorageFile() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public boolean hasStorage() {
- return false; //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class SuiteItem {
-// -------------------------- OTHER METHODS --------------------------
-
- public void addSuiteItem(SuiteItem storage) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public long getDelay() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getDescription() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public long getDuration() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public InstructionItem getInstructionItem() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public int getIterations() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public Date getLastTested() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getName() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getStereotype() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDelay(long delay) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDescription(String description) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDuration(long duration) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setInstructionItem(InstructionItem instruction) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setIterations(int i) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setLastTested(Date date) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setName(String name) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setStereotype(String s) {
- //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class Utilities {
-// -------------------------- STATIC METHODS --------------------------
-
- public static String toString(Object receipt) {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-}
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum1Test.java b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum1Test.java
deleted file mode 100644
index a6c07a06482d..000000000000
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum1Test.java
+++ /dev/null
@@ -1,696 +0,0 @@
-/**
- * $id
- * Author: Dave Kriewall
- * Created: Oct 20, 2005
- * Copyright 2004, WRQ, Inc.
- */
-package com.wrq.rearranger.testClasses;
-
-import com.intellij.codeInspection.dataFlow.DataFlowRunner;
-
-import javax.swing.tree.TreePath;
-import java.io.File;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-/**
- * Created by IntelliJ IDEA. User: JJohnson Date: Aug 30, 2005 Time: 11:06:54 AM To change this template use File |
- * Settings | File Templates.
- */
-public class Enum1Test implements Cloneable {
- private static final String STEREOTYPE_PREFIX = "STEREOTYPE_";
-
- public void setExpectedReceipt(byte[] newValue) {
- }
-
- public void setParameter(String value) {
- }
-
- public void setStorage(SuiteItem suiteItem) {
- }
-
- // ------------------------------ FIELDS ------------------------------
- public enum ExecutionState {
- PASSED, FAILED, UNTESTED
- }
-
- private Enum1Test parent = null;
- private SuiteModel suiteModel;
- private SuiteItem storage;
- private List ");
- tt.append("Pause: ").append(getDelay()).append(" ");
- tt.append("State: ").append(getStateText()).append(" "); // todo add state color getStatecolor()...
- tt.append("Duration: ").append(getDuration()).append(" ");
- tt.append("Executed: ").append(getLastTested()).append(" ");
- }
-
- private void buildInstructionToolTip(StringBuilder tt) {
- InstructionItem inst = getInstructionItem();
- if (inst != null) {
- String id = inst.getInstructionRef();
- Instruction instruction = getInstruction(id);
- tt.append("Command: ").append(instruction.getCommand()).append(" ");
- }
- tt.append("Parameter: ").append(getParameter()).append(" ");
- tt.append("Received: ").append(getReceiptString()).append(" ");
- tt.append("Expected: ").append(getExpectedReceiptString()).append(" ");
- }
-
- private String getExpectedReceiptString() {
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return Utilities.toString(getInstructionItem().getExpectedReceipt());
- }
- return "";
- }
-
- private void buildGroupToolTip(StringBuilder tt) {
- String desc = getDescription();
- if (desc != null && desc.length() > 0) {
- tt.append(desc).append(" ");
- }
- }
-
- private void buildRootToolTip(StringBuilder tt) {
- String author = suiteModel.getAuthor();
- String desc = getDescription();
- String filePath = suiteModel.hasStorage() ? suiteModel.getStorageFile().getAbsolutePath() : null;
- if (author != null && author.length() > 0) {
- tt.append(author).append(" ");
- }
- if (desc != null && desc.length() > 0) {
- tt.append(desc).append(" ");
- }
- if (filePath != null && filePath.length() > 0) {
- tt.append(filePath).append(" ");
- }
- }
-
- public boolean hasChildren() {
- return childNodes.size() > 0;
- }
-
- public int indexOf(Enum1Test t) {
- return childNodes.indexOf(t);
- }
-
- public boolean isGroup() {
- return getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION);
- }
-
- public void remove(Enum1Test node) {
- childNodes.remove(node);
- // node.setParent(null);
- }
-
- public void setDelay(long delay) {
- long oldDelay = storage.getDelay();
- storage.setDelay(delay);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DELAY, oldDelay, delay, this);
- }
-
- public void setDescription(String description) {
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed for instructions
- }
- String oldDescription = storage.getDescription();
- storage.setDescription(description);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DESC, oldDescription, description, this);
- }
-
- public void setDuration(long duration) {
- if (!getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed anything execept instructions
- }
- long oldDuration = getDuration();
- storage.setDuration(duration);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_DURATION, oldDuration, duration, this);
- }
-
- public void setInstructionItem(InstructionItem instruction) {
- InstructionItem oldInstruction = this.getInstructionItem();
- storage.setInstructionItem(instruction);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_INSTRUCTION, oldInstruction, instruction, this);
- }
-
- public void setIterations(int iterations) {
- int oldIterations = storage.getIterations();
- storage.setIterations(iterations);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_ITERATIONS, oldIterations, iterations, this);
- }
-
- public void setLastTested(Date lastTested) {
- Date oldLastTested = getLastTested();
- storage.setLastTested(new Date());
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_LAST_TESTED, oldLastTested, lastTested, this);
- }
-
- public void setName(String name) {
- if (getStereotype().equals(Stereotype.STEREOTYPE_INSTRUCTION)) {
- return; // name is fixed for instructions
- }
- String oldName = storage.getName();
- storage.setName(name);
- suiteModel.fireChangeEvent(SuiteModel.EVT_TOPIC_NAME, oldName, name, this);
- }
-
- // -------------------------- INNER CLASSES --------------------------
- public enum Stereotype {
- STEREOTYPE_ROOT, STEREOTYPE_GROUP, STEREOTYPE_INSTRUCTION
- }
-
- public enum Direction {
- UP, DOWN
- }
-
- public void execute() {
- // Repeat this node -iterations- times
- for (int repeatCount = 0; repeatCount < getIterations(); repeatCount++) {
- if (getStereotype().equals(Enum1Test.Stereotype.STEREOTYPE_INSTRUCTION)) {
- executeInstruction();
- }
- else {
- executeChildren();
- }
- // Pause after each execution this number of milliseconds before continuing
- try {
- Thread.sleep(getDelay());
- }
- catch (InterruptedException e) {
- e.printStackTrace(); // todo - logger
- }
- }
- }
-
- private void executeChildren() {
- Enum1Test[] children = getChildren();
- for (Enum1Test node : children) {
- node.execute(); // recursive execution for nested groups of instructions.
- }
- }
-
- private void executeInstruction() {
- }
-
- private ByteBuffer getPacketToSend(InstructionItem instruction) {
- return null;
- }
-
- public ByteBuffer getPacketToSend() {
- return getPacketToSend(getInstructionItem());
- }
-
- public String getStateText(boolean firstCap) {
- String stateText;
- switch (getState()) {
- case UNTESTED:
- stateText = "untested";
- break;
- case PASSED:
- stateText = "passed";
- break;
- case FAILED:
- stateText = "failed";
- break;
- default:
- stateText = "** unknown **";
- }
- return stateText;
- }
-
- public Instruction getInstruction(String id) {
- return null;
- }
-
- public Instruction getInstruction() {
- String id = this.getInstructionItem().getInstructionRef();
- return getInstruction(id);
- }
-}
-
-class InstructionItem {
- public byte[] getExpectedReceipt() {
- return new byte[0]; //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setExpectedReceipt(byte[] newValue) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getParameter() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setParameter(String value) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getInstructionRef() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public byte[] getReceipt() {
- return null;
- }
-}
-
-class Instruction {
- public String getName() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getDescription() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getCommand() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class SuiteModel {
- public static final Object EVT_TOPIC_EXPECTED_RECEIPT = "";
- public static final Object EVT_TOPIC_PARAMETER = "";
- public static final Object EVT_TOPIC_PARENT = "";
- public static final Object EVT_TOPIC_DELAY = "";
- public static Object EVT_TOPIC_DESC = "";
- public static Object EVT_TOPIC_DURATION = "";
- public static Object EVT_TOPIC_INSTRUCTION = "";
- public static Object EVT_TOPIC_ITERATIONS = "";
- public static Object EVT_TOPIC_LAST_TESTED = "";
- public static Object EVT_TOPIC_NAME = "";
-
- public void fireChangeEvent(Object p0, Object oldValue, Object newValue, Enum1Test testEnum) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getAuthor() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public boolean hasStorage() {
- return false; //To change body of created methods use File | Settings | File Templates.
- }
-
- public File getStorageFile() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public DataFlowRunner getInstructionSet() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class SuiteItem {
- public void setIterations(int i) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setStereotype(String s) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getStereotype() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public long getDelay() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public InstructionItem getInstructionItem() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public int getIterations() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public Date getLastTested() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getName() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public void addSuiteItem(SuiteItem storage) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public String getDescription() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
- public long getDuration() {
- return 0; //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDelay(long delay) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDescription(String description) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setDuration(long duration) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setInstructionItem(InstructionItem instruction) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setLastTested(Date date) {
- //To change body of created methods use File | Settings | File Templates.
- }
-
- public void setName(String name) {
- //To change body of created methods use File | Settings | File Templates.
- }
-}
-
-class Utilities {
- public static String toString(Object receipt) {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-}
\ No newline at end of file
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2AResult.java b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2AResult.java
deleted file mode 100644
index 2b078c110cbf..000000000000
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2AResult.java
+++ /dev/null
@@ -1,26 +0,0 @@
-class Enum2Test {
-// -------------------------- ENUMERATIONS --------------------------
-
- /** Presentation Events. */
- public enum Event {
- barcodeBorder,
- htmlResponse;
- }
-
- public enum Event2 {
- barcodeBorder,
- htmlResponse
- }
-
- ;
-
- enum Coin {
- Nickel(5),
- Dime(10);
- final int value;
-
- Coin(int value) {
- this.value = value;
- }
- }
-}
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Result.java b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Result.java
deleted file mode 100644
index a7326ea7056b..000000000000
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Result.java
+++ /dev/null
@@ -1,31 +0,0 @@
-class Enum2Test {
-// -------------------------- ENUMERATIONS --------------------------
-
- /** Presentation Events. */
- public enum Event {
- barcodeBorder,
- htmlResponse;
- }
-
- public enum Event2 {
- barcodeBorder,
- htmlResponse
- }
-
- ;
-
- enum Coin {
- Nickel(5),
- Dime(10);
-
-// ------------------------------ FIELDS ------------------------------
-
- final int value;
-
-// --------------------------- CONSTRUCTORS ---------------------------
-
- Coin(int value) {
- this.value = value;
- }
- }
-}
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Test.java b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Test.java
deleted file mode 100644
index 3eae2a547765..000000000000
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Test.java
+++ /dev/null
@@ -1,24 +0,0 @@
-class Enum2Test {
- /** Presentation Events. */
- public enum Event {
- barcodeBorder,
- htmlResponse;
- }
-
- public enum Event2 {
- barcodeBorder,
- htmlResponse
- }
-
- ;
-
- enum Coin {
- Nickel(5),
- Dime(10);
- final int value;
-
- Coin(int value) {
- this.value = value;
- }
- }
-}
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/GenericsResult1.java b/plugins/rearranger/test/testData/com/wrq/rearranger/GenericsResult1.java
deleted file mode 100644
index 470d6b51783e..000000000000
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/GenericsResult1.java
+++ /dev/null
@@ -1,9 +0,0 @@
-public class TestGenerics
"); // a divider line
- tt.append("Iterations: ").append(getIterations()).append("