+ * %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 new file mode 100644 index 000000000000..75a340fa150f --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/configuration/RearrangerSettingsPanel.java @@ -0,0 +1,566 @@ +/* + * 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
new file mode 100644
index 000000000000..20e750b47ec9
--- /dev/null
+++ b/plugins/rearranger/src/com/wrq/rearranger/rearrangement/Emitter.java
@@ -0,0 +1,69 @@
+/*
+ * 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.IRuleInstance;
+
+import java.util.List;
+
+/** Emits a new document from the rearranged entries. */
+public final class Emitter {
+ private final PsiFile psiFile;
+ 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 new file mode 100644 index 000000000000..82f3608a656b --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AbstractAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..f3180b76f6a9 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AndNotAttribute.java @@ -0,0 +1,152 @@ +/* + * 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 new file mode 100644 index 000000000000..994fc492cda2 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/AtomicAttribute.java @@ -0,0 +1,33 @@ +/* + * 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 new file mode 100644 index 000000000000..a58bdc2aa8c0 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/EnumAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..acf75802d0de --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..92b48ae79f48 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementedAttribute.java @@ -0,0 +1,54 @@ +/* + * 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 new file mode 100644 index 000000000000..77059d784ba9 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ImplementingAttribute.java @@ -0,0 +1,53 @@ +/* + * 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/InitToAnonClassAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitToAnonClassAttribute.java new file mode 100644 index 000000000000..e3cbef25990b --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitToAnonClassAttribute.java @@ -0,0 +1,53 @@ +/* + * 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 InitToAnonClassAttribute + extends AndNotAttribute +{ + +// -------------------------- STATIC METHODS -------------------------- + + public static InitToAnonClassAttribute readExternal(final Element item) { + final InitToAnonClassAttribute result = new InitToAnonClassAttribute(); + result.loadAttributes(item.getChild(result.getElementName())); + return result; + } + +// --------------------------- CONSTRUCTORS --------------------------- + + public InitToAnonClassAttribute() { + super("initialized to anonymous class", ModifierConstants.INIT_TO_ANON_CLASS); + } + +// -------------------------- OTHER METHODS -------------------------- + + public final /*InitToAnonClassAttribute*/AtomicAttribute deepCopy() { + final InitToAnonClassAttribute result = new InitToAnonClassAttribute(); + 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 new file mode 100644 index 000000000000..8b18576538b1 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/InitializerAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..ddbc7361f745 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/IntegerAttribute.java @@ -0,0 +1,172 @@ +/* + * 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 new file mode 100644 index 000000000000..e6c1194557bb --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MaxParamsAttribute.java @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 000000000000..4d3f301007f1 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/MinParamsAttribute.java @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 000000000000..d77f755ab4a8 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NameAttribute.java @@ -0,0 +1,57 @@ +/* + * 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 new file mode 100644 index 000000000000..e36af5c7fe3b --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/NativeAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..e922cc316a34 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverriddenAttribute.java @@ -0,0 +1,54 @@ +/* + * 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 new file mode 100644 index 000000000000..3e3af6a95909 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/OverridingAttribute.java @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 000000000000..9ff8cfc8b3c8 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ProtectionLevelAttributes.java @@ -0,0 +1,264 @@ +/* + * 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 new file mode 100644 index 000000000000..645d5e422d33 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/ReturnTypeAttribute.java @@ -0,0 +1,57 @@ +/* + * 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 new file mode 100644 index 000000000000..1b1f43b26ce9 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SortOptions.java @@ -0,0 +1,259 @@ +/* + * 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 new file mode 100644 index 000000000000..5c4b5f883f64 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StaticAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..147c9b75b5f7 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/StringAttribute.java @@ -0,0 +1,171 @@ +/* + * 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 new file mode 100644 index 000000000000..8e166fc6ae63 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/SynchronizedAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..2f48fb93cdc4 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TransientAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..0627b20ff8ea --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/TypeAttribute.java @@ -0,0 +1,58 @@ +/* + * 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 new file mode 100644 index 000000000000..6bc6a05c17d9 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/VolatileAttribute.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 000000000000..dc1bd8e3d3c9 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/AttributeGroup.java @@ -0,0 +1,36 @@ +/* + * 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; + +/** Methods implemented by rule objects, which are saved in configuration. */ +public interface AttributeGroup + extends IRule +{ + +// -------------------------- OTHER METHODS -------------------------- + + public AttributeGroup deepCopy(); + + public void writeExternal(final 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 new file mode 100644 index 000000000000..0af457a9d854 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/ClassAttributes.java @@ -0,0 +1,180 @@ +/* + * 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 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 -------------------------- + + 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 StringBuffer sb = new StringBuffer(70); + sb.append(abAttr.getDescriptiveString()); + sb.append(plAttr.getProtectionLevelString()); + sb.append(stAttr.getDescriptiveString()); + sb.append(fAttr.getDescriptiveString()); + sb.append(enumAttr.getDescriptiveString()); + if (sb.length() == 0) { + sb.append("all classes"); + } + else { + sb.append("classes"); + } + if (nameAttr.isMatch()) { + sb.append(' '); + sb.append(nameAttr.getDescriptiveString()); + } + sb.append(sortAttr.getDescriptiveString()); + return sb.toString(); + } + +// ------------------------ INTERFACE METHODS ------------------------ + + +// --------------------- Interface AttributeGroup --------------------- + + public final /*ClassAttributes*/AttributeGroup deepCopy() { + final ClassAttributes result = new ClassAttributes(); + deepCopyCommonItems(result); + result.abAttr = (AbstractAttribute)abAttr.deepCopy(); + result.enumAttr = (EnumAttribute)enumAttr.deepCopy(); + return result; + } + + public final void writeExternal(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(getPlAttr().getProtectionLevelPanel(), constraints); + constraints.gridy = 4; + constraints.gridheight = 1; + caPanel.add(getStAttr().getAndNotPanel(), constraints); + constraints.gridy++; + caPanel.add(getAbAttr().getAndNotPanel(), constraints); + constraints.gridy++; + caPanel.add(getfAttr().getAndNotPanel(), constraints); + constraints.gridy++; + caPanel.add(getEnumAttr().getAndNotPanel(), constraints); + constraints.gridy++; + caPanel.add(getNameAttr().getStringPanel(), constraints); + constraints.gridy++; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.weighty = 1.0d; + constraints.insets = new Insets(0, 0, 0, 0); + caPanel.add(sortAttr.getSortOptionsPanel(), constraints); + return caPanel; + } + + public final boolean isMatch(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 new file mode 100644 index 000000000000..d0f14db787e1 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/attributeGroups/CommonAttributes.java @@ -0,0 +1,184 @@ +/* + * 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.IRuleInstance; +import com.wrq.rearranger.settings.RearrangerSettings; +import com.wrq.rearranger.settings.atomicAttributes.*; +import org.jdom.Element; + +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, IPrioritizableRule +{ +// ------------------------------ FIELDS ------------------------------ + + ProtectionLevelAttributes plAttr; + FinalAttribute fAttr; + StaticAttribute stAttr; + NameAttribute nameAttr; + SortOptions sortAttr; + int priority; // 1 = low priority, > 1 is higher priority + +// -------------------------- STATIC METHODS -------------------------- + + static void readExternal(final CommonAttributes result, final Element item) { + result.plAttr = ProtectionLevelAttributes.readExternal(item); + result.stAttr = StaticAttribute.readExternal(item); + result.fAttr = FinalAttribute.readExternal(item); + result.nameAttr = NameAttribute.readExternal(item); + result.sortAttr = SortOptions.readExternal(item); + result.priority = RearrangerSettings.getIntAttribute(item, "priority", 1); + } + +// --------------------------- CONSTRUCTORS --------------------------- + + public CommonAttributes() { + plAttr = new ProtectionLevelAttributes(); + fAttr = new FinalAttribute(); + stAttr = new StaticAttribute(); + nameAttr = new NameAttribute(); + sortAttr = new SortOptions(); + priority = 1; + } + +// --------------------- GETTER / SETTER METHODS --------------------- + + public final NameAttribute getNameAttr() { + return nameAttr; + } + + final public ProtectionLevelAttributes getPlAttr() { + return plAttr; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + final public StaticAttribute getStAttr() { + return stAttr; + } + + public SortOptions getSortAttr() { + return sortAttr; + } + +// ------------------------ CANONICAL METHODS ------------------------ + + public boolean equals(final Object obj) { + if (!(obj instanceof CommonAttributes)) { + return false; + } + final CommonAttributes ca = (CommonAttributes)obj; + return plAttr.equals(ca.plAttr) && + stAttr.equals(ca.stAttr) && + fAttr.equals(ca.fAttr) && + nameAttr.equals(ca.nameAttr) && + sortAttr.equals(ca.sortAttr) && + priority == ca.priority; + } + +// ------------------------ INTERFACE METHODS ------------------------ + + +// --------------------- Interface IRule --------------------- + + public IRuleInstance createRuleInstance() { + return new DefaultRuleInstance(this); + } + + public boolean isMatch(RangeEntry rangeEntry) { + final boolean result = plAttr.isMatch(rangeEntry.getModifiers()) && + stAttr.isMatch(rangeEntry.getModifiers()) && + fAttr.isMatch(rangeEntry.getModifiers()) && + nameAttr.isMatch(rangeEntry.getName()); + return result; + } + + /** + * 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 new file mode 100644 index 000000000000..2e5c5437a23d --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/util/IconUtil.java @@ -0,0 +1,77 @@ +/* + * 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 new file mode 100644 index 000000000000..c83ba74f8157 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/util/MethodUtil.java @@ -0,0 +1,241 @@ +/* + * 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 new file mode 100644 index 000000000000..a72551d101b8 --- /dev/null +++ b/plugins/rearranger/src/com/wrq/rearranger/util/ModifierUtils.java @@ -0,0 +1,52 @@ +/* + * 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 = mask | i; + break; + } + } + } + return mask; + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java b/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java new file mode 100644 index 000000000000..a8c6653d1ad2 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java @@ -0,0 +1,163 @@ +/* + * 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.editor.Document; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.LightCodeInsightTestCase; +import com.wrq.rearranger.configuration.RearrangerSettingsPanel; +import com.wrq.rearranger.settings.RearrangerSettings; +import com.wrq.rearranger.settings.attributeGroups.IPrioritizableRule; +import com.wrq.rearranger.settings.attributeGroups.IRule; +import com.wrq.rearranger.util.Constraints; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ListIterator; + +/** + * @author davek + * Date: Mar 30, 2004 + */ +public class InteractiveTest + extends LightCodeInsightTestCase +{ + private RearrangerSettings rs; + public static final String DEFAULT_CONFIGURATION_ROOT = ".."; // up one level from test + public static final String DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION_ROOT + "/src/com/wrq/rearranger/defaultConfiguration.xml"; + + @Override + protected String getTestDataPath() { + return "testData"; // run unit tests with effective working directory of "C:\Rearranger\test" + } + + protected final void setUp() throws Exception { + super.setUp(); + Logger logger = Logger.getLogger("com.wrq.rearranger"); +// logger.setAdditivity(false); +// logger.addAppender(new ConsoleAppender(new PatternLayout("[%7r] %6p - %30.30c - %m \n"))); +// logger.setLevel(Level.DEBUG); + logger.setLevel(Level.INFO); + rs = new RearrangerSettings(); + rs.setAskBeforeRearranging(true); + rs.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, rs, 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; + try { + FileInputStream f = new FileInputStream(new File(DEFAULT_CONFIGURATION)); + doc = builder.build(f); + f.close(); + } + catch (JDOMException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + catch (FileNotFoundException e) { + File f = new File(DEFAULT_CONFIGURATION); + System.out.println(f.getAbsolutePath()); + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + 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 { + ListIterator li = componentList.listIterator(); + while (li.hasNext()) +// for (Element e : componentList) + { + Element e = (Element)li.next(); + 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"); + ListIterator li; + for (Object o : object.settings.getClassOrderAttributeList()) { + if (o instanceof IPrioritizableRule) { + System.out.println(o + ", pri=" + ((IRule)o).getPriority()); + } + else { + System.out.println(o); + } + } + System.out.println("Item order"); + for (Object o : object.settings.getItemOrderAttributeList()) { + if (o instanceof IPrioritizableRule) { + System.out.println(o + ", pri=" + ((IRule)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 new file mode 100644 index 000000000000..a0667d6e1593 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy @@ -0,0 +1,2188 @@ +/* + * 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.testFramework.fixtures.LightCodeInsightFixtureTestCase +import com.wrq.rearranger.settings.RearrangerSettings +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable + +/** JUnit tests for the rearranger plugin. */ +class RearrangerTest extends LightCodeInsightFixtureTestCase { + + 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(); +// rs.setAskBeforeRearranging(true); // uncomment for debugging file structure popup + mySettings.showFields = true + mySettings.showParameterNames = true + mySettings.showParameterTypes = true + mySettings.showRules = true + mySettings.rearrangeInnerClasses =true + } + + public final void testNoRearrangement() throws Exception { + doTest('RearrangementTest', 'NoRearrangementResult1') + } + +// public final void testPublicFieldRearrangement() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getPlAttr().setPlPublic(true); +// rs.addItem(fa, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult2.java"); +// } +// +// public final void testNotPublicFieldRearrangement() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getPlAttr().setPlPublic(true); +// fa.getPlAttr().setInvertProtectionLevel(true); +// rs.addItem(fa, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult3.java"); +// } +// +// public final void testConstructorRearrangement() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.getPlAttr().setPlPackage(true); +// ma.getPlAttr().setPlPublic(true); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult4.java"); +// } +// +// public final void testClassRearrangement() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final ClassAttributes ca = new ClassAttributes(); +// ca.getPlAttr().setPlPackage(true); +// rs.addClass(ca, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult5.java"); +// } +// +// public final void testPSFRearrangement() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest2.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getPlAttr().setPlPublic(true); +// fa.getfAttr().setValue(true); +// fa.getStAttr().setValue(true); +// rs.addItem(fa, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult6.java"); +// } +// +// public final void testAnonClassInit() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest7.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getInitToAnonClassAttr().setValue(true); +// rs.addItem(fa, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult7.java"); +// } +// +// public final void testNameMatch() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getNameAttr().setMatch(true); +// fa.getNameAttr().setExpression(".*5"); +// rs.addItem(fa, 0); +// final MethodAttributes ma = new MethodAttributes(); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression(".*2"); +// rs.addItem(ma, 1); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult8.java"); +// } +// +// public final void testStaticInitializer() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest8.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.getStaticInitAttr().setValue(true); +// rs.addItem(ma, 0); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult8A.java"); +// } +// +// public final void testAlphabetizingGSMethods() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// ma.setOtherMethodType(true); +// ma.setConstructorMethodType(false); +// ma.getSortAttr().setByName(true); +// rs.addItem(ma, 0); +// rs.setKeepGettersSettersTogether(false); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult9.java"); +// } +// +// public final void testSimpleComment() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa = new FieldAttributes(); +// fa.getPlAttr().setPlPublic(true); +// rs.addItem(fa, 0); +// final CommentRule c = new CommentRule(); +// c.setCommentText("// simple comment **********"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE); +// rs.addItem(c, 1); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult10.java"); +// } +// +// /** +// * 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 { +// configureByFile("/com/wrq/rearranger/RearrangementResult10.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final FieldAttributes fa = new FieldAttributes(); +// fa.getPlAttr().setPlPublic(true); +// rs.addItem(fa, 0); +// final CommentRule c = new CommentRule(); +// c.setCommentText("// simple comment **********"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE); +// rs.addItem(c, 1); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult10.java"); +// } +// +// public final void testMultipleRuleCommentMatch() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest11.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// CommentRule c; +// FieldAttributes fa; +// +// c = new CommentRule(); +// c.setCommentText("// FIELDS:"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE); +// c.setAllSubsequentRules(false); +// c.setnSubsequentRulesToMatch(3); +// rs.addItem(c, 0); +// +// c = new CommentRule(); +// c.setCommentText("// PROTECTED FIELDS:"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE); +// c.setAllSubsequentRules(false); +// c.setnSubsequentRulesToMatch(1); +// rs.addItem(c, 1); +// +// fa = new FieldAttributes(); +// fa.getPlAttr().setPlProtected(true); +// rs.addItem(fa, 2); +// +// c = new CommentRule(); +// c.setCommentText("// FINAL FIELDS:"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE); +// c.setAllSubsequentRules(true); +// c.setnSubsequentRulesToMatch(1); +// rs.addItem(c, 3); +// +// fa = new FieldAttributes(); +// fa.getfAttr().setValue(true); +// rs.addItem(fa, 4); +// +// c = new CommentRule(); +// c.setCommentText("// NON-FINAL FIELDS:"); +// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE); +// c.setAllSubsequentRules(true); +// c.setnSubsequentRulesToMatch(1); +// rs.addItem(c, 5); +// +// fa = new FieldAttributes(); +// fa.getfAttr().setValue(true); +// fa.getfAttr().setInvert(true); +// rs.addItem(fa, 6); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult11.java"); +// } +// +// public final void testOpsBlockingQueueExample() throws Exception { +// testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueue.java", +// false, "/com/wrq/rearranger/OpsBlockingQueue.java"); +// } +// +// public final void testOpsBlockingQueueExampleWithGlobalPattern() throws Exception { +// testOpsBlockingQueueExampleWorker(true, "/com/wrq/rearranger/OpsBlockingQueue.java", +// false, "/com/wrq/rearranger/OpsBlockingQueue.java"); +// } +// +// public final void testOpsBlockingQueueExampleWithIndentedComments() throws Exception { +// testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueueIndented.java", +// true, "/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java"); +// } +// +// private void testOpsBlockingQueueExampleWorker(boolean doGlobalPattern, +// String srcFilename, +// boolean doublePublicMethods, +// String compareFilename) +// throws Exception +// { +// // submitted by Joe Martinez. +// configureByFile(srcFilename); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// CommentRule c; +// FieldAttributes fa; +// c = new CommentRule(); +// c.setCommentText("//************************************** PUBLIC STATIC FIELDS *************************************"); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(2); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(false); +// rs.addItem(c, 0); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlPublic(true); +// fa.getStAttr().setValue(true); +// fa.getfAttr().setValue(true); +// rs.addItem(fa, 1); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlPublic(true); +// fa.getStAttr().setValue(true); +// rs.addItem(fa, 2); +// c = new CommentRule(); +// c.setCommentText("//************************************** PUBLIC FIELDS *****************************************"); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(true); +// rs.addItem(c, 3); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlPublic(true); +// rs.addItem(fa, 4); +// c = new CommentRule(); +// c.setCommentText("//*********************************** PROTECTED/PACKAGE FIELDS **************************************"); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(3); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(false); +// rs.addItem(c, 5); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlProtected(true); +// fa.getPlAttr().setPlPackage(true); +// fa.getStAttr().setValue(true); +// fa.getfAttr().setValue(true); +// rs.addItem(fa, 6); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlProtected(true); +// fa.getPlAttr().setPlPackage(true); +// fa.getStAttr().setValue(true); +// rs.addItem(fa, 7); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlProtected(true); +// fa.getPlAttr().setPlPackage(true); +// rs.addItem(fa, 8); +// c = new CommentRule(); +// c.setCommentText("//************************************** PRIVATE FIELDS *****************************************"); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(false); +// rs.addItem(c, 9); +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// fa.getPlAttr().setPlPrivate(true); +// rs.addItem(fa, 10); +// c = new CommentRule(); +// c.setCommentText("//************************************** CONSTRUCTORS ************************************* "); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(2); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(false); +// rs.addItem(c, 11); +// MethodAttributes ma = new MethodAttributes(); +// ma.getPlAttr().setPlPublic(true); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, 12); +// ma = new MethodAttributes(); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, 13); +// c = new CommentRule(); +// c.setCommentText("//*********************************** GETTERS AND SETTERS ********************************** "); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(2); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(false); +// rs.addItem(c, 14); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// ma.getPlAttr().setPlPublic(true); +// ma.setGetterSetterMethodType(true); +// rs.addItem(ma, 15); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// ma.setGetterSetterMethodType(true); +// rs.addItem(ma, 16); +// c = new CommentRule(); +// String commentText = +// "//************************************** PUBLIC METHODS ************************************* "; +// if (doublePublicMethods) { +// commentText += "\n// PUBLIC METHODS LINE 2"; +// } +// c.setCommentText(commentText); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(true); +// rs.addItem(c, 17); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// ma.getPlAttr().setPlPublic(true); +// rs.addItem(ma, 18); +// c = new CommentRule(); +// c.setCommentText("//********************************* PACKAGE/PROTECTED METHODS ******************************** "); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(true); +// rs.addItem(c, 19); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// ma.getPlAttr().setPlProtected(true); +// ma.getPlAttr().setPlPackage(true); +// rs.addItem(ma, 20); +// c = new CommentRule(); +// c.setCommentText("//************************************** PRIVATE METHODS *************************************"); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(true); +// rs.addItem(c, 21); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// ma.getPlAttr().setPlPrivate(true); +// rs.addItem(ma, 22); +// c = new CommentRule(); +// c.setCommentText("//************************************** INNER CLASSES ************************************* "); +// c.setEmitCondition(2); +// c.setnPrecedingRulesToMatch(1); +// c.setnSubsequentRulesToMatch(1); +// c.setAllPrecedingRules(true); +// c.setAllSubsequentRules(true); +// rs.addItem(c, 23); +// InnerClassAttributes ic = new InnerClassAttributes(); +// ic.getSortAttr().setByName(true); +// rs.addItem(ic, 24); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(false); +// if (doGlobalPattern) { +// rs.setGlobalCommentPattern("//\\*{20,45}[A-Z /]*\\*{20,45}\n"); +// } +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile(compareFilename); +// } +// +// public final void testReturnTypeMatch() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest12.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.getReturnTypeAttr().setMatch(true); +// ma.getReturnTypeAttr().setExpression("void"); +// rs.addItem(ma, 0); +// FieldAttributes fa = new FieldAttributes(); +// fa.getTypeAttr().setMatch(true); +// fa.getTypeAttr().setExpression("int"); +// rs.addItem(fa, 1); +// ma = new MethodAttributes(); +// ma.getReturnTypeAttr().setMatch(true); +// ma.getReturnTypeAttr().setExpression(".*je.*"); +// rs.addItem(ma, 2); +// ma = new MethodAttributes(); +// ma.getReturnTypeAttr().setMatch(true); +// ma.getReturnTypeAttr().setExpression("Integer\\[\\]"); +// rs.addItem(ma, 3); +// ma = new MethodAttributes(); +// ma.getReturnTypeAttr().setMatch(true); +// ma.getReturnTypeAttr().setExpression("int"); +// rs.addItem(ma, 4); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult12.java"); +// } +// +// public final void testRelatedMethodsDepthOriginal() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DO.java"); +// } +// +// public final void testRelatedMethodsDepthAlphabetical() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.ALPHABETICAL_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DA.java"); +// } +// +// public final void testRelatedMethodsDepthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DI.java"); +// } +// +// public final void testRelatedMethodsBreadthOriginal() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BO.java"); +// } +// +// public final void testRelatedMethodsBreadthAlphabetical() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.ALPHABETICAL_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BA.java"); +// } +// +// public final void testRelatedMethodsBreadthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BI.java"); +// } +// +// public final void testEmitTLCommentsRelatedMethodsBreadthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BITLC.java"); +// } +// +// public final void testEmitEMCommentsRelatedMethodsBreadthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BIEMC.java"); +// } +// +// public final void testEmitELCommentsRelatedMethodsBreadthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BIELC.java"); +// } +// +// public final void testEmitNFCommentsRelatedMethodsBreadthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13BINFC.java"); +// } +// +// public final void testEmitTLCommentsRelatedMethodsDepthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DITLC.java"); +// } +// +// public final void testEmitEMCommentsRelatedMethodsDepthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DIEMC.java"); +// } +// +// public final void testEmitELCommentsRelatedMethodsDepthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DIELC.java"); +// } +// +// public final void testEmitNFCommentsRelatedMethodsDepthInvocation() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY); +// CommentRule c = new CommentRule(); +// c.setCommentText("// Preceding comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setPrecedingComment(c); +// c = new CommentRule(); +// c.setCommentText("// Trailing comment: TL=%TL%\n" + +// "// MN=%MN%\n" + +// "// AM=%AM%\n" + +// "// Level %LV%"); +// rs.getExtractedMethodsSettings().setTrailingComment(c); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13DINFC.java"); +// } +// +// public final void testRelatedMethodsException() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER); +// MethodAttributes ma = new MethodAttributes(); +// ma.setNoExtractedMethods(true); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("GF"); +// rs.addItem(ma, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult13Ex.java"); +// } +// +// public final void testKeepOverloadedMethodsTogether() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest14.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(false); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.INVOCATION_ORDER); +// rs.setKeepOverloadedMethodsTogether(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult14.java"); +// } +// +// public final void testOverrides() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest15.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// } +// +// public final void testImplements() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest16.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// } +// +// public final void testXML() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest17.xml"); +// // we should not do anything to XML files. +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementTest17.xml"); +// } +// +// public final void testKeepGSTogether() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest18.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.ALPHABETICAL_ORDER); +// FieldAttributes fa = new FieldAttributes(); +// rs.addItem(fa, 0); +// MethodAttributes ma = new MethodAttributes(); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, 1); +// ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// ma.getSortAttr().setByName(true); +// rs.addItem(ma, 2); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult18.java"); +// } +// +// public final void testKeepGSWithProperty() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest18.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(true); +// rs.setKeepGettersSettersWithProperty(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.ALPHABETICAL_ORDER); +// FieldAttributes fa = new FieldAttributes(); +// rs.addItem(fa, 0); +// MethodAttributes ma = new MethodAttributes(); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, 1); +// ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// ma.getSortAttr().setByName(true); +// rs.addItem(ma, 2); +//// rs.setAskBeforeRearranging(true); // testing only +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult18A.java"); +// } +// +// public final void testKeepGSWithPropertyElseTogether() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest18B.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(true); +// rs.setKeepGettersSettersWithProperty(true); +// rs.getExtractedMethodsSettings().setOrdering(RelatedMethodsSettings.ALPHABETICAL_ORDER); +// FieldAttributes fa = new FieldAttributes(); +// rs.addItem(fa, 0); +// CommentRule cr = new CommentRule(); +// cr.setCommentText("// Getters/Setters"); +// cr.setEmitCondition(CommentRule.EMIT_ALWAYS); +// rs.addItem(cr, 1); +// MethodAttributes ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// ma.getSortAttr().setByName(true); +// ma.getGetterSetterDefinition().setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX); +// ma.getGetterSetterDefinition().setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_IMMATERIAL); +// ma.getGetterSetterDefinition().setSetterNameCriterion(GetterSetterDefinition.SETTER_NAME_CORRECT_PREFIX); +// ma.getGetterSetterDefinition().setSetterBodyCriterion(GetterSetterDefinition.SETTER_BODY_IMMATERIAL); +// rs.addItem(ma, 2); +// cr = new CommentRule(); +// cr.setCommentText("// Other Methods"); +// cr.setEmitCondition(CommentRule.EMIT_ALWAYS); +// rs.addItem(cr, 3); +// ma = new MethodAttributes(); +// ma.getSortAttr().setByName(true); +// rs.addItem(ma, 4); +// +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult18B.java"); +// } +// +// public final void testKeepOverloadsTogetherOriginalOrder() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest19.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(false); +// rs.setKeepOverloadedMethodsTogether(true); +// rs.setOverloadedOrder(RearrangerSettings.OVERLOADED_ORDER_RETAIN_ORIGINAL); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult19A.java"); +// } +// +// public final void testKeepOverloadsTogetherAscendingOrder() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest19.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(false); +// rs.setKeepOverloadedMethodsTogether(true); +// rs.setOverloadedOrder(RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult19B.java"); +// } +// +// public final void testKeepOverloadsTogetherDescendingOrder() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest19.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(false); +// rs.setKeepOverloadedMethodsTogether(true); +// rs.setOverloadedOrder(RearrangerSettings.OVERLOADED_ORDER_DESCENDING_PARAMETERS); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult19C.java"); +// } +// +// public final void testInnerClassReferenceToChild() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest20.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult20.java"); +// } +// +// public final void testMultipleFieldDecl() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest21.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// FieldAttributes fa = new FieldAttributes(); +// fa.getSortAttr().setByName(true); +// rs.addItem(fa, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult21.java"); +// } +// +// public final void testRemoveBlankLines() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest1.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getAfterClassLBrace().setForce(true); +// rs.getAfterClassLBrace().setnBlankLines(0); +// rs.getAfterMethodLBrace().setForce(true); +// rs.getAfterMethodLBrace().setnBlankLines(0); +// rs.getBeforeMethodRBrace().setForce(true); +// rs.getBeforeMethodRBrace().setnBlankLines(0); +// rs.getAfterMethodRBrace().setForce(true); +// rs.getAfterMethodRBrace().setnBlankLines(0); +// rs.getBeforeClassRBrace().setForce(true); +// rs.getBeforeClassRBrace().setnBlankLines(0); +// rs.getAfterClassRBrace().setForce(true); +// rs.getAfterClassRBrace().setnBlankLines(0); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(1); +// rs.setRemoveBlanksInsideCodeBlocks(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult1.java"); +// } +// +// public final void testAddBlankLines() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest2.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getAfterClassLBrace().setForce(true); +// rs.getAfterClassLBrace().setnBlankLines(2); +// rs.getAfterMethodLBrace().setForce(true); +// rs.getAfterMethodLBrace().setnBlankLines(3); +// rs.getBeforeMethodRBrace().setForce(true); +// rs.getBeforeMethodRBrace().setnBlankLines(2); +// rs.getAfterMethodRBrace().setForce(true); +// rs.getAfterMethodRBrace().setnBlankLines(1); +// rs.getBeforeClassRBrace().setForce(true); +// rs.getBeforeClassRBrace().setnBlankLines(3); +// rs.getAfterClassRBrace().setForce(true); +// rs.getAfterClassRBrace().setnBlankLines(4); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(1); +// rs.setRemoveBlanksInsideCodeBlocks(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult2.java"); +// } +// +// public final void testInnerClassBlankLines() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest4.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getAfterClassLBrace().setForce(true); +// rs.getAfterClassLBrace().setnBlankLines(0); +// rs.getAfterMethodLBrace().setForce(true); +// rs.getAfterMethodLBrace().setnBlankLines(0); +// rs.getBeforeMethodRBrace().setForce(true); +// rs.getBeforeMethodRBrace().setnBlankLines(0); +// rs.getAfterMethodRBrace().setForce(true); +// rs.getAfterMethodRBrace().setnBlankLines(1); +// rs.getBeforeClassRBrace().setForce(true); +// rs.getBeforeClassRBrace().setnBlankLines(1); +// rs.getAfterClassRBrace().setForce(true); +// rs.getAfterClassRBrace().setnBlankLines(1); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(1); +// rs.setRemoveBlanksInsideCodeBlocks(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult4.java"); +// } +// +// public void testInnerClassSpacing() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest5.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final File physFile = new File(InteractiveTest.DEFAULT_CONFIGURATION); +// rs = RearrangerSettings.getSettingsFromFile(physFile); +// rs.setAskBeforeRearranging(false); +// rs.getAfterClassRBrace().setnBlankLines(2); +// rs.getAfterClassRBrace().setForce(true); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(3); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult5.java"); +// } +// +// public void testNoRearrangementInnerClass() throws Exception { +// configureByFile("/com/wrq/rearranger/NoRearrangeInnerClassTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final File settingsFile = new File(InteractiveTest.DEFAULT_CONFIGURATION_ROOT + +// "/test/testData/com/wrq/rearranger/NoRearrangementInnerClassCfg.xml"); +// rs = RearrangerSettings.getSettingsFromFile(settingsFile); +// rs.setAskBeforeRearranging(false); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/NoRearrangeInnerClassResult.java"); +// } +// +// public void testSpacingWithTrailingWhitespace() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest6.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); +// rs.setAskBeforeRearranging(false); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(1); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult6.java"); +// } +// +// public void testSpacingJoinLineBug() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest7.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// File settingsFile = new File(InteractiveTest.DEFAULT_CONFIGURATION_ROOT + +// "/test/testData/com/wrq/rearranger/SpaceTest7cfg.xml"); +// rs = RearrangerSettings.getSettingsFromFile(settingsFile); +// rs.setAskBeforeRearranging(false); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult7.java"); +// } +// +// /** +// * Submitted by Brian Buckley. +// * +// * @throws Exception test exception +// */ +// public void testSpacingConflictingSettingBug() throws Exception { +// configureByFile("/com/wrq/rearranger/SpaceTest8.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); +// rs.setAskBeforeRearranging(false); +// rs.getAfterClassLBrace().setForce(true); +// rs.getAfterClassLBrace().setnBlankLines(0); +// rs.getBeforeMethodLBrace().setForce(true); +// rs.getBeforeMethodLBrace().setnBlankLines(1); +// rs.getNewlinesAtEOF().setForce(true); +// rs.getNewlinesAtEOF().setnBlankLines(1); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/SpaceResult8.java"); +// } +// +// public void testGetPrefixImmaterial() throws Exception { +// configureByFile("/com/wrq/rearranger/GetterDefinitionTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_IMMATERIAL); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/GetPrefixImmaterialResult.java"); +// } +// +// public void testGetPrefixReturns() throws Exception { +// configureByFile("/com/wrq/rearranger/GetterDefinitionTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_RETURNS); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/GetPrefixReturnsResult.java"); +// } +// +// public void testGetPrefixReturnsField() throws Exception { +// configureByFile("/com/wrq/rearranger/GetterDefinitionTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/GetPrefixReturnsFieldResult.java"); +// } +// +// public void testGetFieldReturns() throws Exception { +// configureByFile("/com/wrq/rearranger/GetterDefinitionTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_RETURNS); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/GetFieldReturnsResult.java"); +// } +// +// public void testGetFieldReturnsField() throws Exception { +// configureByFile("/com/wrq/rearranger/GetterDefinitionTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/GetFieldReturnsFieldResult.java"); +// } +// +// public void testSpecialGS() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest22.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma = new MethodAttributes(); +// GetterSetterDefinition gsd = ma.getGetterSetterDefinition(); +// rs.addItem(ma, 0); +// ma.setGetterSetterMethodType(true); +// gsd.setGetterNameCriterion(GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX); +// gsd.setGetterBodyCriterion(GetterSetterDefinition.GETTER_BODY_RETURNS); +// gsd.setSetterBodyCriterion(GetterSetterDefinition.SETTER_BODY_IMMATERIAL); +// gsd.setSetterNameCriterion(GetterSetterDefinition.SETTER_NAME_CORRECT_PREFIX); +// rs.setKeepGettersSettersTogether(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult22.java"); +// } +// +// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodAlphabetical() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(false); +// InterfaceAttributes ia = new InterfaceAttributes(); +// CommentRule cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Header ****/"); +// ia.setPrecedingComment(cr); +// cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Trailer ***/"); +// ia.setTrailingComment(cr); +// ia.setNoExtractedMethods(true); +// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ALPHABETICAL); +// ia.setAlphabetizeInterfaces(false); +// rs.addItem(ia, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXMA.java"); +// } +// +// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(false); +// InterfaceAttributes ia = new InterfaceAttributes(); +// CommentRule cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Header ****/"); +// ia.setPrecedingComment(cr); +// cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Trailer ***/"); +// ia.setTrailingComment(cr); +// ia.setNoExtractedMethods(true); +// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); +// ia.setAlphabetizeInterfaces(false); +// rs.addItem(ia, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXME.java"); +// } +// +// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodInterfaceOrder() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(false); +// InterfaceAttributes ia = new InterfaceAttributes(); +// CommentRule cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Header ****/"); +// ia.setPrecedingComment(cr); +// cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Trailer ***/"); +// ia.setTrailingComment(cr); +// ia.setNoExtractedMethods(true); +// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_INTERFACE_ORDER); +// ia.setAlphabetizeInterfaces(false); +// rs.addItem(ia, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXMI.java"); +// } +// +// public void testInterfaceByNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(false); +// InterfaceAttributes ia = new InterfaceAttributes(); +// ia.getNameAttr().setMatch(true); +// ia.getNameAttr().setExpression("IFace1"); +// ia.setNoExtractedMethods(true); +// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); +// ia.setAlphabetizeInterfaces(false); +// rs.addItem(ia, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23BNNANXME.java"); +// } +// +// public void testInterfaceIsAlphabeticalNoExcludeMethodEncountered() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(false); +// InterfaceAttributes ia = new InterfaceAttributes(); +// CommentRule cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Header ****/"); +// ia.setPrecedingComment(cr); +// cr = new CommentRule(); +// cr.setCommentText("/**** Interface %IF% Trailer ***/"); +// ia.setTrailingComment(cr); +// ia.setNoExtractedMethods(true); +// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); +// ia.setAlphabetizeInterfaces(true); +// rs.addItem(ia, 0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNIANXME.java"); +// } +// +// public void testNPE24() throws Exception { +// // submitted by Nathan Brown. Caused NPE in Rearranger plugin version 1.7. +// int itemIndex = 0; +// configureByFile("/com/wrq/rearranger/RearrangementTest24.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(true); +// rs.setKeepOverloadedMethodsTogether(true); +//// rs.setAskBeforeRearranging(false); +// rs.setOverloadedOrder(1); +// rs.setGlobalCommentPattern(""); +// rs.setRemoveBlanksInsideCodeBlocks(false); +// FieldAttributes fa; +// fa = new FieldAttributes(); +// fa.getSortAttr().setByName(false); +// fa.getPlAttr().setPlPublic(true); +// fa.getPlAttr().setPlPrivate(true); +// fa.getPlAttr().setPlProtected(true); +// fa.getPlAttr().setPlPackage(true); +// fa.getPlAttr().setInvertProtectionLevel(false); +// fa.getStAttr().setValue(true); +// fa.getStAttr().setInvert(false); +// rs.addItem(fa, itemIndex++); +// fa = new FieldAttributes(); +// fa.getStAttr().setValue(true); +// fa.getStAttr().setInvert(true); +// fa.getInitToAnonClassAttr().setValue(true); +// fa.getInitToAnonClassAttr().setInvert(true); +// rs.addItem(fa, itemIndex++); +// fa = new FieldAttributes(); +// fa.getInitToAnonClassAttr().setValue(true); +// rs.addItem(fa, itemIndex++); +// MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.getStaticInitAttr().setValue(true); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.setConstructorMethodType(true); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("clone"); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("dispose"); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("_dispose"); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("build"); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getAbstractAttr().setValue(true); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.getStAttr().setValue(true); +// ma.getStAttr().setInvert(true); +// ma.getAbstractAttr().setValue(true); +// ma.getAbstractAttr().setInvert(true); +// ma.setOtherMethodType(true); +// rs.addItem(ma, itemIndex++); +// ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// rs.addItem(ma, itemIndex++); +// InnerClassAttributes ica = new InnerClassAttributes(); +// rs.addItem(ica, itemIndex++); +// ma = new MethodAttributes(); +// ma.getStAttr().setValue(true); +// rs.addItem(ma, itemIndex); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rs.getExtractedMethodsSettings().setBelowFirstCaller(false); +// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); +// rs.getExtractedMethodsSettings().setOrdering(0); +// rs.getExtractedMethodsSettings().setNonPrivateTreatment(2); +// rs.getExtractedMethodsSettings().setCommentType(0); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// } +// +// 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 +// * Rearrager from editor's context menu: +// */ +// configureByFile("/com/wrq/rearranger/RearrangementTest25.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.getBeforeClassRBrace().setForce(true); +// rs.getBeforeClassRBrace().setnBlankLines(0); +// rs.getBeforeMethodRBrace().setForce(true); +// rs.getBeforeMethodRBrace().setnBlankLines(0); +// rs.setRemoveBlanksInsideCodeBlocks(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult25.java"); +// } +// +// public void testPriority() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.setPriority(1); +// rs.addItem(ma, 0); +// ma = new MethodAttributes(); +// ma.setPriority(2); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression("method.*"); +// rs.addItem(ma, 1); +// ma = new MethodAttributes(); +// ma.setPriority(2); +// ma.getNameAttr().setMatch(true); +// ma.getNameAttr().setExpression(".*Method"); +// rs.addItem(ma, 2); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult1A.java"); +// } +// +// public void testGSRuleWithClassInitializer() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest26.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// MethodAttributes ma; +// ma = new MethodAttributes(); +// ma.setGetterSetterMethodType(true); +// rs.addItem(ma, 0); +// rs.setKeepGettersSettersTogether(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult26.java"); +// } +// +// public void testKeepGSTogetherAndExtractedMethods() throws Exception { +// configureByFile("/com/wrq/rearranger/RearrangementTest27.java"); +// final PsiFile file = getFile(); +// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); +// final RearrangerActionHandler rah = new RearrangerActionHandler(); +// rs.setKeepGettersSettersTogether(true); +// rs.setKeepOverloadedMethodsTogether(true); +// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); +// rah.rearrangeDocument(getProject(), file, rs, doc); +// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult27.java"); +// } +// +// 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
"); + } + 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
new file mode 100644
index 000000000000..a6c07a06482d
--- /dev/null
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum1Test.java
@@ -0,0 +1,696 @@
+/**
+ * $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
new file mode 100644
index 000000000000..2b078c110cbf
--- /dev/null
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2AResult.java
@@ -0,0 +1,26 @@
+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
new file mode 100644
index 000000000000..a7326ea7056b
--- /dev/null
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Result.java
@@ -0,0 +1,31 @@
+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
new file mode 100644
index 000000000000..3eae2a547765
--- /dev/null
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/Enum2Test.java
@@ -0,0 +1,24 @@
+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
new file mode 100644
index 000000000000..16b18c44c73d
--- /dev/null
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/GenericsResult1.java
@@ -0,0 +1,8 @@
+public class TestGenerics
"); // a divider line
+ tt.append("Iterations: ").append(getIterations()).append("