--- a/java.source/apichanges.xml Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/apichanges.xml Thu Feb 16 13:28:43 2012 +0100 @@ -108,6 +108,21 @@ + + + Added several methods to CodeStyle supporting customization of the generated class members order and other minor formatting enhancements. + + + + + + Added CodeStyle.getClassMemberGroups, CodeStyle.getClassMemberInsertionPoint, + to support customization of the generated class members order, and CodeStyle.wrapAfterDotInChainedMethodCalls, + CodeStyle.getBlankLinesAfterAnonymousClassHeader, CodeStyle.spaceAroundAnnotationValueAssignOps + to support minor formatting enhancements. + + + Added SourceUtils.waitUserActionTask. --- a/java.source/src/org/netbeans/api/java/source/CodeStyle.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/api/java/source/CodeStyle.java Thu Feb 16 13:28:43 2012 +0100 @@ -46,15 +46,27 @@ import java.util.Arrays; import java.util.Comparator; +import java.util.EnumSet; +import java.util.Set; import java.util.prefs.Preferences; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.Modifier; import javax.swing.text.Document; + +import com.sun.source.tree.BlockTree; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.VariableTree; + import org.netbeans.api.project.Project; import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.modules.java.ui.FmtOptions; - +import static org.netbeans.modules.java.ui.FmtOptions.*; import org.openide.filesystems.FileObject; -import static org.netbeans.modules.java.ui.FmtOptions.*; /** * XXX make sure the getters get the defaults from somewhere @@ -239,7 +251,26 @@ } public boolean makeParametersFinal() { - return preferences.getBoolean(makeParametersFinal, getDefaultAsBoolean(useFQNs)); + return preferences.getBoolean(makeParametersFinal, getDefaultAsBoolean(makeParametersFinal)); + } + + /** + * Returns an information about the desired grouping of class members. + * @since 0.96 + */ + public MemberGroups getClassMemberGroups() { + return new MemberGroups(preferences.get(classMembersOrder, getDefaultAsString(classMembersOrder)), + preferences.getBoolean(sortMembersByVisibility, getDefaultAsBoolean(sortMembersByVisibility)) + ? preferences.get(visibilityOrder, getDefaultAsString(visibilityOrder)) : null); + } + + /** + * Returns an information about the desired insertion point of a new class member. + * @since 0.96 + */ + public InsertionPoint getClassMemberInsertionPoint() { + String point = preferences.get(classMemberInsertionPoint, getDefaultAsString(classMemberInsertionPoint)); + return InsertionPoint.valueOf(point); } // Alignment and braces ---------------------------------------------------- @@ -400,6 +431,10 @@ return WrapStyle.valueOf(wrap); } + public boolean wrapAfterDotInChainedMethodCalls() { + return preferences.getBoolean(wrapAfterDotInChainedMethodCalls, getDefaultAsBoolean(wrapAfterDotInChainedMethodCalls)); + } + public WrapStyle wrapArrayInit() { String wrap = preferences.get(wrapArrayInit, getDefaultAsString(wrapArrayInit)); return WrapStyle.valueOf(wrap); @@ -511,6 +546,10 @@ return preferences.getInt(blankLinesAfterClassHeader, getDefaultAsInt(blankLinesAfterClassHeader)); } + public int getBlankLinesAfterAnonymousClassHeader() { + return preferences.getInt(blankLinesAfterAnonymousClassHeader, getDefaultAsInt(blankLinesAfterAnonymousClassHeader)); + } + public int getBlankLinesBeforeFields() { return preferences.getInt(blankLinesBeforeFields, getDefaultAsInt(blankLinesBeforeFields)); } @@ -604,6 +643,10 @@ return preferences.getBoolean(spaceAroundAssignOps, getDefaultAsBoolean(spaceAroundAssignOps)); } + public boolean spaceAroundAnnotationValueAssignOps() { + return preferences.getBoolean(spaceAroundAnnotationValueAssignOps, getDefaultAsBoolean(spaceAroundAnnotationValueAssignOps)); + } + public boolean spaceBeforeClassDeclLeftBrace() { return preferences.getBoolean(spaceBeforeClassDeclLeftBrace, getDefaultAsBoolean(spaceBeforeClassDeclLeftBrace)); } @@ -896,6 +939,12 @@ WRAP_NEVER } + public enum InsertionPoint { + LAST_IN_CATEGORY, + FIRST_IN_CATEGORY, + CARET_LOCATION + } + /** * Provides an information about the desired grouping of import statements, * including group order. @@ -971,6 +1020,134 @@ } } + /** + * Provides an information about the desired grouping of class members, + * including group order. + * @since 0.96 + */ + public static final class MemberGroups { + + private Info[] infos; + + private MemberGroups(String groups, String visibility) { + if (groups == null || groups.length() == 0) { + this.infos = new Info[0]; + } else { + String[] order = groups.trim().split("\\s*[,;]\\s*"); //NOI18N + String[] visibilityOrder = visibility != null ? visibility.trim().split("\\s*[,;]\\s*") : new String[1]; //NOI18N + this.infos = new Info[order.length * visibilityOrder.length]; + for (int i = 0; i < order.length; i++) { + String o = order[i]; + boolean isStatic = false; + if (o.startsWith("STATIC ")) { //NOI18N + isStatic = true; + o = o.substring(7); + } + ElementKind kind = ElementKind.valueOf(o); + for (int j = 0; j < visibilityOrder.length; j++) { + int idx = i * visibilityOrder.length + j; + String vo = visibilityOrder[j]; + Info info = new Info(idx); + info.ignoreVisibility = vo == null || !"DEFAULT".equals(vo); //NOI18N + info.mods = vo != null && !"DEFAULT".equals(vo) ? EnumSet.of(Modifier.valueOf(vo)) : EnumSet.noneOf(Modifier.class); //NOI18N + if (isStatic) + info.mods.add(Modifier.STATIC); + info.kind = kind; + this.infos[idx] = info; + } + } + } + } + + /** + * Returns the group number of the class member. Elements with the same + * number form a group. Groups with lower numbers should be positioned + * higher in the class member list. + * @param tree the member tree + * @return the group number + * @since 0.96 + */ + public int getGroupId(Tree tree) { + for (Info info : infos) { + ElementKind kind = ElementKind.OTHER; + Set modifiers = null; + switch (tree.getKind()) { + case ANNOTATION_TYPE: + case CLASS: + case ENUM: + case INTERFACE: + kind = ElementKind.CLASS; + modifiers = ((ClassTree)tree).getModifiers().getFlags(); + break; + case METHOD: + MethodTree mt = (MethodTree)tree; + if (mt.getName().contentEquals("")) { //NOI18N + kind = ElementKind.CONSTRUCTOR; + } else { + kind = ElementKind.METHOD; + } + modifiers = mt.getModifiers().getFlags(); + break; + case VARIABLE: + kind = ElementKind.FIELD; + modifiers = ((VariableTree)tree).getModifiers().getFlags(); + break; + case BLOCK: + kind = ((BlockTree)tree).isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; + break; + } + if (info.check(kind, modifiers)) + return info.groupId; + } + return infos.length; + } + + /** + * Returns the group number of the class member. Elements with the same + * number form a group. Groups with lower numbers should be positioned + * higher in the class member list. + * @param element the member element + * @return the group number + * @since 0.96 + */ + public int getGroupId(Element element) { + for (Info info : infos) { + ElementKind kind = element.getKind(); + if (kind == ElementKind.ANNOTATION_TYPE || kind == ElementKind.ENUM || kind == ElementKind.INSTANCE_INIT) + kind = ElementKind.CLASS; + if (info.check(kind, element.getModifiers())); + return info.groupId; + } + return infos.length; + } + + private static final class Info { + + private int groupId; + private boolean ignoreVisibility; + private Set mods; + private ElementKind kind; + + private Info(int id) { + this.groupId = id; + } + + private boolean check(ElementKind kind, Set modifiers) { + if (this.kind != kind) + return false; + if (modifiers == null) + return true; + if (!modifiers.containsAll(this.mods)) + return false; + if (ignoreVisibility) + return true; + EnumSet copy = EnumSet.copyOf(modifiers); + copy.retainAll(EnumSet.of(Modifier.PUBLIC, Modifier.PRIVATE, Modifier.PROTECTED)); + return copy.isEmpty(); + } + } + } + // Communication with non public packages ---------------------------------- private static class Producer implements FmtOptions.CodeStyleProducer { --- a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java Thu Feb 16 13:28:43 2012 +0100 @@ -111,9 +111,10 @@ import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.java.lexer.JavaTokenId; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.GuardedDocument; @@ -162,32 +163,38 @@ public ClassTree insertClassMember(ClassTree clazz, Tree member) { assert clazz != null && member != null; int idx = 0; - GuardedDocument gdoc = null; - SourcePositions sp = null; + Document doc = null; + int caretPos = -1; try { - Document doc = copy.getDocument(); + doc = copy.getDocument(); if (doc == null) { DataObject data = DataObject.find(copy.getFileObject()); EditorCookie cookie = data.getCookie(EditorCookie.class); doc = cookie.openDocument(); } - - if (doc != null && doc instanceof GuardedDocument) { - gdoc = (GuardedDocument)doc; - sp = copy.getTrees().getSourcePositions(); - } } catch (IOException ioe) {} + CodeStyle codeStyle = DiffContext.getCodeStyle(copy); + if (codeStyle.getClassMemberInsertionPoint() == CodeStyle.InsertionPoint.CARET_LOCATION) { + JTextComponent jtc = EditorRegistry.lastFocusedComponent(); + if (jtc.getDocument() == doc) + caretPos = jtc.getCaretPosition(); + } + ClassMemberComparator comparator = caretPos < 0 ? new ClassMemberComparator(codeStyle) : null; + SourcePositions sp = copy.getTrees().getSourcePositions(); TreeUtilities utils = copy.getTreeUtilities(); CompilationUnitTree compilationUnit = copy.getCompilationUnit(); Tree lastMember = null; for (Tree tree : clazz.getMembers()) { TreePath path = TreePath.getPath(compilationUnit, tree); - if ((path == null || !utils.isSynthetic(path)) && CLASS_MEMBER_COMPARATOR.compare(member, tree) < 0) { - if (gdoc == null) + if ((path == null || !utils.isSynthetic(path)) && (caretPos < 0 + && (codeStyle.getClassMemberInsertionPoint() == CodeStyle.InsertionPoint.FIRST_IN_CATEGORY && comparator.compare(member, tree) <= 0 + || comparator.compare(member, tree) < 0) || caretPos >= 0 && caretPos < sp.getStartPosition(compilationUnit, tree))) { + if (doc == null || !(doc instanceof GuardedDocument)) break; int pos = (int)(lastMember != null ? sp.getEndPosition(compilationUnit, lastMember) : sp.getStartPosition( compilationUnit,clazz)); - pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); - if (pos <= sp.getStartPosition(compilationUnit, tree)) + pos = ((GuardedDocument)doc).getGuardedBlockChain().adjustToBlockEnd(pos); + long treePos = sp.getStartPosition(compilationUnit, tree); + if (treePos < 0 || pos <= treePos) break; } idx++; @@ -1015,47 +1022,20 @@ private static class ClassMemberComparator implements Comparator { + private CodeStyle.MemberGroups groups; + + public ClassMemberComparator(CodeStyle cs) { + this.groups = cs.getClassMemberGroups(); + } + @Override public int compare(Tree tree1, Tree tree2) { if (tree1 == tree2) return 0; - return getSortPriority(tree1) - getSortPriority(tree2); - } - - private static int getSortPriority(Tree tree) { - int ret = 0; - ModifiersTree modifiers = null; - switch (tree.getKind()) { - case ANNOTATION_TYPE: - case CLASS: - case ENUM: - case INTERFACE: - ret = 4000; - modifiers = ((ClassTree)tree).getModifiers(); - break; - case METHOD: - MethodTree mt = (MethodTree)tree; - if (mt.getName().contentEquals("")) - ret = 200; - else - ret = 300; - modifiers = mt.getModifiers(); - break; - case VARIABLE: - ret = 100; - modifiers = ((VariableTree)tree).getModifiers(); - break; - } - if (modifiers != null) { - if (!modifiers.getFlags().contains(Modifier.STATIC)) - ret += 1000; - } - return ret; + return groups.getGroupId(tree1) - groups.getGroupId(tree2); } } - private static ClassMemberComparator CLASS_MEMBER_COMPARATOR = new ClassMemberComparator(); - private static class ImportsComparator implements Comparator { private CodeStyle.ImportGroups groups; --- a/java.source/src/org/netbeans/modules/java/source/pretty/VeryPretty.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/source/pretty/VeryPretty.java Thu Feb 16 13:28:43 2012 +0100 @@ -124,6 +124,7 @@ private int fromOffset = -1; private int toOffset = -1; private boolean containsError = false; + private boolean insideAnnotation = false; private final Map tree2Tag; private final Map tag2Span; @@ -672,7 +673,7 @@ } } if (!emptyClass) { - blankLines(cs.getBlankLinesAfterClassHeader()); + blankLines(enclClassName.isEmpty() ? cs.getBlankLinesAfterAnonymousClassHeader() : cs.getBlankLinesAfterClassHeader()); if ((tree.mods.flags & ENUM) != 0) { printEnumConstants(tree.defs, false); } @@ -1356,14 +1357,15 @@ public void visitAssign(JCAssign tree) { int col = out.col; printExpr(tree.lhs, TreeInfo.assignPrec + 1); - if (cs.spaceAroundAssignOps()) + boolean spaceAroundAssignOps = cs.spaceAroundAssignOps(); + if (spaceAroundAssignOps) print(' '); print('='); int rm = cs.getRightMargin(); switch(cs.wrapAssignOps()) { case WRAP_IF_LONG: if (widthEstimator.estimateWidth(tree.rhs, rm - out.col) + out.col <= cs.getRightMargin()) { - if(cs.spaceAroundAssignOps()) + if(spaceAroundAssignOps) print(' '); break; } @@ -1372,7 +1374,7 @@ toColExactly(cs.alignMultilineAssignment() ? col : out.leftMargin + cs.getContinuationIndentSize()); break; case WRAP_NEVER: - if(cs.spaceAroundAssignOps()) + if(spaceAroundAssignOps) print(' '); break; } @@ -1622,6 +1624,8 @@ @Override public void visitAnnotation(JCAnnotation tree) { + boolean oldInsideAnnotation = insideAnnotation; + insideAnnotation = true; if (!printAnnotationsFormatted(List.of(tree))) { print("@"); printExpr(tree.annotationType); @@ -1633,6 +1637,7 @@ print(cs.spaceWithinAnnotationParens() ? " )" : ")"); } } + insideAnnotation = oldInsideAnnotation; } @Override @@ -2142,7 +2147,7 @@ printEmptyBlockComments(tree, members); } else { if (members) - blankLines(cs.getBlankLinesAfterClassHeader()); + blankLines(enclClassName.isEmpty() ? cs.getBlankLinesAfterAnonymousClassHeader() : cs.getBlankLinesAfterClassHeader()); else newline(); printStats(stats, members); --- a/java.source/src/org/netbeans/modules/java/source/resources/layer.xml Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/source/resources/layer.xml Thu Feb 16 13:28:43 2012 +0100 @@ -215,13 +215,11 @@ - --- a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Thu Feb 16 13:28:43 2012 +0100 @@ -1503,7 +1503,7 @@ return bounds[1]; } - protected int diffAssign(JCAssign oldT, JCAssign newT, int[] bounds) { + protected int diffAssign(JCAssign oldT, JCAssign newT, JCTree parent, int[] bounds) { int localPointer = bounds[0]; // lhs int[] lhsBounds = getBounds(oldT.lhs); @@ -1518,7 +1518,8 @@ tokenSequence.move(rhsBounds[0]); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); if (tokenSequence.token().id() != JavaTokenId.EQ) { - if (diffContext.style.spaceAroundAssignOps()) + boolean spaceAroundAssignOps = parent.getKind() == Kind.ANNOTATION ? diffContext.style.spaceAroundAnnotationValueAssignOps() : diffContext.style.spaceAroundAssignOps(); + if (spaceAroundAssignOps) printer.print(" = "); else printer.print("="); @@ -3307,7 +3308,7 @@ retVal = diffParens((JCParens)oldT, (JCParens)newT, elementBounds); break; case JCTree.ASSIGN: - retVal = diffAssign((JCAssign)oldT, (JCAssign)newT, elementBounds); + retVal = diffAssign((JCAssign)oldT, (JCAssign)newT, parent, elementBounds); break; case JCTree.TYPECAST: retVal = diffTypeCast((JCTypeCast)oldT, (JCTypeCast)newT, elementBounds); --- a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java Thu Feb 16 13:28:43 2012 +0100 @@ -54,6 +54,7 @@ import org.netbeans.api.java.platform.JavaPlatformManager; import static org.netbeans.api.java.lexer.JavaTokenId.*; import org.netbeans.api.java.source.*; +import org.netbeans.api.java.source.CodeStyle.WrapStyle; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; @@ -136,7 +137,9 @@ return; } } - CodeStyle cs = CodeStyle.getDefault(doc); + CodeStyle cs = (CodeStyle) doc.getProperty(CodeStyle.class); + if (cs == null) + cs = CodeStyle.getDefault(doc); List indentRegions = context.indentRegions(); Collections.reverse(indentRegions); for (Context.Region region : indentRegions) @@ -426,6 +429,7 @@ private int tpLevel; private boolean eof = false; private boolean bof = false; + private boolean insideAnnotation = false; private Pretty(CompilationInfo info, TreePath path, CodeStyle cs, int startOffset, int endOffset, boolean templateEdit) { this(info.getText(), info.getTokenHierarchy().tokenSequence(JavaTokenId.language()), @@ -727,7 +731,7 @@ } else { if (!cs.indentTopLevelClassMembers()) indent = old; - blankLines(cs.getBlankLinesAfterClassHeader()); + blankLines(node.getSimpleName().length() == 0 ? cs.getBlankLinesAfterAnonymousClassHeader() : cs.getBlankLinesAfterClassHeader()); JavaTokenId id = null; boolean first = true; boolean semiRead = false; @@ -1120,7 +1124,10 @@ accept(LPAREN); if (args != null && !args.isEmpty()) { spaces(cs.spaceWithinAnnotationParens() ? 1 : 0); + boolean oldInsideAnnotation = insideAnnotation; + insideAnnotation = true; wrapList(cs.wrapAnnotationArgs(), cs.alignMultilineAnnotationArgs(), false, COMMA, args); + insideAnnotation = oldInsideAnnotation; spaces(cs.spaceWithinAnnotationParens() ? 1 : 0); } accept(RPAREN); @@ -1453,61 +1460,53 @@ if (ms.getKind() == Tree.Kind.MEMBER_SELECT) { ExpressionTree exp = ((MemberSelectTree)ms).getExpression(); scan(exp, p); - accept(DOT); - List targs = node.getTypeArguments(); - if (targs != null && !targs.isEmpty()) { - if (LT == accept(LT)) - tpLevel++; - for (Iterator it = targs.iterator(); it.hasNext();) { - Tree targ = it.next(); - scan(targ, p); - if (it.hasNext()) { - spaces(cs.spaceBeforeComma() ? 1 : 0); - accept(COMMA); - spaces(cs.spaceAfterComma() ? 1 : 0); + WrapStyle wrapStyle = cs.wrapChainedMethodCalls(); + if (wrapStyle == WrapStyle.WRAP_ALWAYS && exp.getKind() != Tree.Kind.METHOD_INVOCATION) + wrapStyle = WrapStyle.WRAP_IF_LONG; + switch (wrapStyle) { + case WRAP_ALWAYS: + if (cs.wrapAfterDotInChainedMethodCalls()) { + accept(DOT); + newline(); + } else { + newline(); + accept(DOT); } - } - JavaTokenId accepted; - if (tpLevel > 0 && (accepted = accept(GT, GTGT, GTGTGT)) != null) { - switch (accepted) { - case GTGTGT: - tpLevel -= 3; - break; - case GTGT: - tpLevel -= 2; - break; - case GT: - tpLevel--; - break; + scanMethodCall(node); + break; + case WRAP_IF_LONG: + int index = tokens.index(); + int c = col; + Diff d = diffs.isEmpty() ? null : diffs.getFirst(); + boolean oldCheckWrap = checkWrap; + checkWrap = true; + try { + accept(DOT); + scanMethodCall(node); + } catch (WrapAbort wa) { + } finally { + checkWrap = oldCheckWrap; } - } - } - CodeStyle.WrapStyle wrapStyle = cs.wrapChainedMethodCalls(); - if(exp.getKind() == Tree.Kind.METHOD_INVOCATION) { - wrapToken(wrapStyle, -1, 0, IDENTIFIER, THIS, SUPER); - } else { - int index = tokens.index(); - int c = col; - Diff d = diffs.isEmpty() ? null : diffs.getFirst(); - accept(IDENTIFIER, THIS, SUPER); - if (wrapStyle != CodeStyle.WrapStyle.WRAP_NEVER && col > rightMargin && c > indent) { - rollback(index, c, d); - newline(); - accept(IDENTIFIER, THIS, SUPER); - } + if (col > rightMargin) { + rollback(index, c, d); + if (cs.wrapAfterDotInChainedMethodCalls()) { + accept(DOT); + newline(); + } else { + newline(); + accept(DOT); + } + scanMethodCall(node); + } + break; + case WRAP_NEVER: + accept(DOT); + scanMethodCall(node); + break; } } else { - scan(node.getMethodSelect(), p); + scanMethodCall(node); } - spaces(cs.spaceBeforeMethodCallParen() ? 1 : 0); - accept(LPAREN); - List args = node.getArguments(); - if (args != null && !args.isEmpty()) { - spaces(cs.spaceWithinMethodCallParens() ? 1 : 0, true); - wrapList(cs.wrapMethodCallArgs(), cs.alignMultilineCallArgs(), false, COMMA, args); - spaces(cs.spaceWithinMethodCallParens() ? 1 : 0); - } - accept(RPAREN); return true; } @@ -1996,18 +1995,19 @@ int alignIndent = cs.alignMultilineAssignment() ? col : -1; boolean b = scan(node.getVariable(), p); if (b || getCurrentPath().getParentPath().getLeaf().getKind() != Tree.Kind.ANNOTATION) { - spaces(cs.spaceAroundAssignOps() ? 1 : 0); + boolean spaceAroundAssignOps = insideAnnotation ? cs.spaceAroundAnnotationValueAssignOps() : cs.spaceAroundAssignOps(); + spaces(spaceAroundAssignOps ? 1 : 0); accept(EQ); ExpressionTree expr = node.getExpression(); if (expr.getKind() == Tree.Kind.NEW_ARRAY && ((NewArrayTree)expr).getType() == null) { if (cs.getOtherBracePlacement() == CodeStyle.BracePlacement.SAME_LINE) - spaces(cs.spaceAroundAssignOps() ? 1 : 0); + spaces(spaceAroundAssignOps ? 1 : 0); scan(expr, p); } else { if (wrapAnnotation && expr.getKind() == Tree.Kind.ANNOTATION) { - wrapTree(CodeStyle.WrapStyle.WRAP_ALWAYS, alignIndent, cs.spaceAroundAssignOps() ? 1 : 0, expr); + wrapTree(CodeStyle.WrapStyle.WRAP_ALWAYS, alignIndent, spaceAroundAssignOps ? 1 : 0, expr); } else { - wrapTree(cs.wrapAssignOps(), alignIndent, cs.spaceAroundAssignOps() ? 1 : 0, expr); + wrapTree(cs.wrapAssignOps(), alignIndent, spaceAroundAssignOps ? 1 : 0, expr); } } } else { @@ -3005,6 +3005,7 @@ int c = col; Diff d = diffs.isEmpty() ? null : diffs.getFirst(); old = indent; + boolean oldCheckWrap = checkWrap; checkWrap = true; try { if (alignIndent >= 0) @@ -3015,7 +3016,7 @@ accept(first, rest); } catch (WrapAbort wa) { } finally { - checkWrap = false; + checkWrap = oldCheckWrap; } if (this.col > rightMargin) { rollback(index, c, d); @@ -3056,6 +3057,7 @@ int c = col; Diff d = diffs.isEmpty() ? null : diffs.getFirst(); old = indent; + boolean oldCheckWrap = checkWrap; checkWrap = true; try { if (alignIndent >= 0) @@ -3066,7 +3068,7 @@ scan(tree, null); } catch (WrapAbort wa) { } finally { - checkWrap = false; + checkWrap = oldCheckWrap; } if (col > rightMargin) { rollback(index, c, d); @@ -3114,6 +3116,7 @@ int c = col; Diff d = diffs.isEmpty() ? null : diffs.getFirst(); old = indent; + boolean oldCheckWrap = checkWrap; checkWrap = true; try { if (alignIndent >= 0) @@ -3131,7 +3134,7 @@ scan(tree, null); } catch (WrapAbort wa) { } finally { - checkWrap = false; + checkWrap = oldCheckWrap; } if (col > rightMargin) { rollback(index, c, d); @@ -3293,6 +3296,47 @@ } } + private void scanMethodCall(MethodInvocationTree node) { + List targs = node.getTypeArguments(); + if (targs != null && !targs.isEmpty()) { + if (LT == accept(LT)) + tpLevel++; + for (Iterator it = targs.iterator(); it.hasNext();) { + Tree targ = it.next(); + scan(targ, null); + if (it.hasNext()) { + spaces(cs.spaceBeforeComma() ? 1 : 0); + accept(COMMA); + spaces(cs.spaceAfterComma() ? 1 : 0); + } + } + JavaTokenId accepted; + if (tpLevel > 0 && (accepted = accept(GT, GTGT, GTGTGT)) != null) { + switch (accepted) { + case GTGTGT: + tpLevel -= 3; + break; + case GTGT: + tpLevel -= 2; + break; + case GT: + tpLevel--; + break; + } + } + } + accept(IDENTIFIER, THIS, SUPER); + spaces(cs.spaceBeforeMethodCallParen() ? 1 : 0); + accept(LPAREN); + List args = node.getArguments(); + if (args != null && !args.isEmpty()) { + spaces(cs.spaceWithinMethodCallParens() ? 1 : 0, true); + wrapList(cs.wrapMethodCallArgs(), cs.alignMultilineCallArgs(), false, COMMA, args); + spaces(cs.spaceWithinMethodCallParens() ? 1 : 0); + } + accept(RPAREN); + } + private void reformatComment() { if (tokens.token().id() != BLOCK_COMMENT && tokens.token().id() != JAVADOC_COMMENT) return; --- a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties Thu Feb 16 13:28:43 2012 +0100 @@ -64,6 +64,10 @@ LBL_wrp_WRAP_IF_LONG=If Long LBL_wrp_WRAP_NEVER=Never +LBL_ip_CARET_LOCATION=Caret Location +LBL_ip_FIRST_IN_CATEGORY=First In Category +LBL_ip_LAST_IN_CATEGORY=Last In Category + LBL_ExpandTabToSpaces=&Expand Tab to Spaces LBL_TabSize=&Tab Size: LBL_IndentSize=&Indentation Size: @@ -74,31 +78,47 @@ LBL_AddLeadingStarInComment=A&dd Leading Star In Comment LBL_RightMargin=&Right Margin: -LBL_Naming=Naming\: -LBL_PreferLongerNames=Prefer Longer Names -LBL_Prefix=Prefix -LBL_Suffix=Suffix -LBL_Field=Field\: -LBL_StaticField=Static Field\: -LBL_Parameter=Parameter\: -LBL_LocalVariable=Local Variable\: -LBL_Misc=Misc\: -LBL_QualifyFieldAccess=Qualify Field Access -LBL_UseIsForBooleanGetters=Use Is For Boolean Getters -LBL_AddOverrideAnnotation=Add Override Annotation -LBL_FinalMofier=Final Modifier\: -LBL_ParametersFinal=Make Generated Parameters Final -LBL_LocalVariablesFinal=Make Generated Local variables Final -LBL_ImportOredering=Import Ordering\: -LBL_ImportUp=Move Up -LBL_ImportDown=Move Down +LBL_gen_Naming=Naming Conventions\: +LBL_gen_PreferLongerNames=Prefer Longer Names +LBL_gen_UseIsForBooleanGetters=Use Is For Boolean Getters +LBL_gen_Prefix=Prefix +LBL_gen_Suffix=Suffix +LBL_gen_Field=Field\: +LBL_gen_StaticField=Static Field\: +LBL_gen_Parameter=Parameter\: +LBL_gen_LocalVariable=Local Variable\: +LBL_gen_Other=Other\: +LBL_gen_QualifyFieldAccess=Qualify Field Access +LBL_gen_AddOverrideAnnotation=Add Override Annotation +LBL_gen_ParametersFinal=Make Generated Parameters Final +LBL_gen_LocalVariablesFinal=Make Generated Local variables Final +LBL_gen_MembersOreder=Members Sort Order\: +LBL_gen_MembersOrederUp=Move Up +LBL_gen_MembersOrederDown=Move Down +LBL_gen_SortByVisibility=Sort Members By Visibility +LBL_gen_InsertionPoint=Insertion Point\: + +VAL_gen_STATIC=Static +VAL_gen_CLASS=Classes +VAL_gen_CONSTRUCTOR=Constructors +VAL_gen_FIELD=Fields +VAL_gen_INSTANCE_INIT=Instance Initializers +VAL_gen_METHOD=Methods +VAL_gen_STATIC_INIT=Static Initializers + +VAL_gen_PUBLIC=Public +VAL_gen_PRIVATE=Private +VAL_gen_PROTECTED=Protected +VAL_gen_DEFAULT=Default + LBL_blBeforePackage=Before &Package\: -LBL_blAfterPackage=After P&ackage\: +LBL_blAfterPackage=After Packa&ge\: LBL_blBeforeImports=Before &Imports\: LBL_blAfterImports=After Imports\: LBL_blBeforeClass=Before &Class\: LBL_blAfterClass=After C&lass\: LBL_blAfterClassHeader=After Class &Header\: +LBL_blAfterAnonymousClassHeader=After &Anonymous Class Header: LBL_blBeforeFields=Before &Field\: LBL_blAfterFields=After Fi&eld\: LBL_blBeforeMethods=Before &Method\: @@ -127,6 +147,7 @@ LBL_spaceAroundBinaryOps=Binary Operators LBL_spaceAroundTernaryOps=Ternary Operators LBL_spaceAroundAssignOps=Assignment Operators +LBL_spaceAroundAnnotationValueAssignOps=Annotation Value Assignment Operator LBL_BeforeLeftBraces=Before Left Braces LBL_spaceBeforeClassDeclLeftBrace=Class Declaration @@ -168,6 +189,7 @@ LBL_spaceBeforeColon=Before Colon LBL_spaceAfterColon=After Colon LBL_spaceAfterTypeCast=After Type Cast + LBL_wrp_extendsImplementsKeyword=&Extends/Implements Keyword\: LBL_wrp_extendsImplementsList=E&xtends/Implements List\: LBL_wrp_methodParameters=Method &Parameters\: @@ -176,6 +198,7 @@ LBL_wrp_methodCallArgs=Method Call Arguments\: LBL_wrp_annotationArgs=Annotation Arg&uments\: LBL_wrp_chainedMethodCalls=C&hained Method Calls\: +LBL_wrp_afeterDot=Wrap After Dot In Chained Method Call LBL_wrp_arrayInit=Array Initiali&zer\: LBL_wrp_tryResources=Try Re&sources\: LBL_wrp_multiCatches=Dis&junctive Catch Types\: @@ -228,6 +251,7 @@ LBL_Comments=Comments LBL_doc_enableCommentFormat=Enable Comments Formatting +LBL_doc_enableBlockCommentFormat=Format Block Comments LBL_doc_generalLabel=General LBL_doc_addLeadingStar=Add Leading Star LBL_doc_wrapCommentText=Wrap Text At Right Margin @@ -355,7 +379,7 @@ if (number==13 && object instanceof Runnable )\ method( "Some text", 12, new Object());\ for( int i = 1; i < 100; i++ )\ -System.out.println(i);\ +System.out.print(i);\ while ( this.number < 2 && number != 3 )\ this.number++;\ do \ @@ -380,6 +404,10 @@ public ClassA() {\ }\ public void methodA() {\ +new Runnable() {\ +public void run() {\ +}\ +};\ }\ public void methodB() {\ }\ @@ -463,6 +491,11 @@ }\ } +SAMPLE_CodeGen=public class ClassA {\ +\ +private String name;\ +} + nlFinallyCheckBox1.text="finall&y" AN_Preview=Preview @@ -472,5 +505,4 @@ FmtTabsIndents.indentCasesFromSwitchCheckBox.AccessibleContext.accessibleDescription=Additional indent for case statements FmtTabsIndents.indentTopLevelClassMembersCheckBox.AccessibleContext.accessibleDescription=Indent for top-level class members FmtTabsIndents.continuationIndentSizeField.AccessibleContext.accessibleDescription=Indent size in spaces -FmtTabsIndents.labelIndentField.AccessibleContext.accessibleDescription=Label indentation size in spaces -LBL_doc_enableBlockCommentFormat=Format Block Comments +FmtTabsIndents.labelIndentField.AccessibleContext.accessibleDescription=Label indentation size in spaces --- a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.form Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.form Thu Feb 16 13:28:43 2012 +0100 @@ -10,6 +10,7 @@ + @@ -32,23 +33,26 @@ + - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -89,26 +93,32 @@ - + + + + + + + - - + + - - + + - - + + - + @@ -126,7 +136,7 @@ - + @@ -219,6 +229,18 @@ + + + + + + + + + + + + --- a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtBlankLines.java Thu Feb 16 13:28:43 2012 +0100 @@ -66,6 +66,7 @@ bClassField.putClientProperty(OPTION_ID, blankLinesBeforeClass); aClassField.putClientProperty(OPTION_ID, blankLinesAfterClass); aClassHeaderField.putClientProperty(OPTION_ID, blankLinesAfterClassHeader); + anAnonymousClassHeaderField.putClientProperty(OPTION_ID, blankLinesAfterAnonymousClassHeader); bFieldsField.putClientProperty(OPTION_ID, blankLinesBeforeFields); aFieldsField.putClientProperty(OPTION_ID, blankLinesAfterFields); bMethodsField.putClientProperty(OPTION_ID, blankLinesBeforeMethods ); @@ -78,6 +79,7 @@ bClassField.addKeyListener(new NumericKeyListener()); aClassField.addKeyListener(new NumericKeyListener()); aClassHeaderField.addKeyListener(new NumericKeyListener()); + anAnonymousClassHeaderField.addKeyListener(new NumericKeyListener()); bFieldsField.addKeyListener(new NumericKeyListener()); aFieldsField.addKeyListener(new NumericKeyListener()); bMethodsField.addKeyListener(new NumericKeyListener()); @@ -112,6 +114,8 @@ aClassField = new javax.swing.JTextField(); aClassHeaderLabel = new javax.swing.JLabel(); aClassHeaderField = new javax.swing.JTextField(); + anAnonymousClassHeaderLabel = new javax.swing.JLabel(); + anAnonymousClassHeaderField = new javax.swing.JTextField(); bFieldsLabel = new javax.swing.JLabel(); bFieldsField = new javax.swing.JTextField(); aFieldsLabel = new javax.swing.JLabel(); @@ -127,7 +131,7 @@ bPackageLabel.setLabelFor(bPackageField); org.openide.awt.Mnemonics.setLocalizedText(bPackageLabel, org.openide.util.NbBundle.getMessage(FmtBlankLines.class, "LBL_blBeforePackage")); // NOI18N - bPackageField.setColumns(5); + bPackageField.setColumns(2); aPackageLabel.setLabelFor(aPackageField); org.openide.awt.Mnemonics.setLocalizedText(aPackageLabel, org.openide.util.NbBundle.getMessage(FmtBlankLines.class, "LBL_blAfterPackage")); // NOI18N @@ -159,6 +163,9 @@ aClassHeaderField.setColumns(5); + anAnonymousClassHeaderLabel.setLabelFor(anAnonymousClassHeaderField); + org.openide.awt.Mnemonics.setLocalizedText(anAnonymousClassHeaderLabel, org.openide.util.NbBundle.getMessage(FmtBlankLines.class, "LBL_blAfterAnonymousClassHeader")); // NOI18N + bFieldsLabel.setLabelFor(bFieldsField); org.openide.awt.Mnemonics.setLocalizedText(bFieldsLabel, org.openide.util.NbBundle.getMessage(FmtBlankLines.class, "LBL_blBeforeFields")); // NOI18N @@ -194,25 +201,25 @@ .addComponent(aClassHeaderLabel) .addComponent(bFieldsLabel) .addComponent(aFieldsLabel) + .addComponent(anAnonymousClassHeaderLabel) .addComponent(bMethodsLabel) .addComponent(aMethodsLabel)) .addGap(6, 6, 6) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(aMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aClassHeaderField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aClassField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bClassField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aImportsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bImportsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aPackageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bPackageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(aImportsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(bImportsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(aPackageField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(bPackageField) + .addComponent(aFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(bFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(anAnonymousClassHeaderField) + .addComponent(aClassHeaderField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(aClassField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(bClassField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(bMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE) + .addComponent(aMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); - - layout.linkSize( javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{aClassField, aClassHeaderField, aFieldsField, aImportsField, aMethodsField, aPackageField, bClassField, bFieldsField, bImportsField, bMethodsField, bPackageField}); - layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -243,25 +250,30 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(aClassHeaderField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(aClassHeaderLabel)) - .addGap(4, 4, 4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(bFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bFieldsLabel)) - .addGap(4, 4, 4) + .addComponent(anAnonymousClassHeaderLabel) + .addComponent(anAnonymousClassHeaderField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(aFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aFieldsLabel)) - .addGap(4, 4, 4) + .addComponent(bFieldsLabel) + .addComponent(bFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(bMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bMethodsLabel)) - .addGap(4, 4, 4) + .addComponent(aFieldsLabel) + .addComponent(aFieldsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(aMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(aMethodsLabel))) + .addComponent(bMethodsLabel) + .addComponent(bMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(aMethodsLabel) + .addComponent(aMethodsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); - layout.linkSize( javax.swing.SwingConstants.VERTICAL, new java.awt.Component[]{aClassField, aClassHeaderField, aFieldsField, aImportsField, aMethodsField, aPackageField, bClassField, bFieldsField, bImportsField, bMethodsField, bPackageField}); + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {aClassField, aClassHeaderField, aFieldsField, aImportsField, aMethodsField, aPackageField, bClassField, bFieldsField, bImportsField, bMethodsField, bPackageField}); }// //GEN-END:initComponents @@ -279,6 +291,8 @@ private javax.swing.JLabel aMethodsLabel; private javax.swing.JTextField aPackageField; private javax.swing.JLabel aPackageLabel; + private javax.swing.JTextField anAnonymousClassHeaderField; + private javax.swing.JLabel anAnonymousClassHeaderLabel; private javax.swing.JTextField bClassField; private javax.swing.JLabel bClassLabel; private javax.swing.JTextField bFieldsField; --- a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.form Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.form Thu Feb 16 13:28:43 2012 +0100 @@ -1,6 +1,6 @@ -
+ @@ -10,33 +10,147 @@ + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - + @@ -48,180 +162,11 @@ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -233,16 +178,178 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + @@ -254,16 +361,11 @@ - - - - - - + @@ -275,28 +377,11 @@ - - - - - - - - - - - - - - - - - - + @@ -308,16 +393,11 @@ - - - - - - + @@ -329,85 +409,135 @@ - - - - - - + - + - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.java Thu Feb 16 13:28:43 2012 +0100 @@ -44,23 +44,70 @@ package org.netbeans.modules.java.ui; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.prefs.Preferences; + +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.Modifier; +import javax.swing.DefaultListModel; +import javax.swing.JEditorPane; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +import com.sun.source.tree.AssignmentTree; +import com.sun.source.tree.BlockTree; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.IdentifierTree; +import com.sun.source.tree.ModifiersTree; +import com.sun.source.tree.NewClassTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.TypeParameterTree; +import com.sun.source.tree.VariableTree; + +import org.netbeans.api.java.source.CodeStyle; +import org.netbeans.api.java.source.GeneratorUtilities; +import org.netbeans.api.java.source.JavaSource.Phase; +import org.netbeans.api.java.source.ModificationResult; +import org.netbeans.api.java.source.TreeMaker; +import org.netbeans.api.java.source.WorkingCopy; +import org.netbeans.editor.BaseDocument; +import org.netbeans.modules.editor.indent.api.Reformat; import static org.netbeans.modules.java.ui.FmtOptions.*; +import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID; -import org.netbeans.modules.java.ui.FmtOptions.CategorySupport; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; +import org.netbeans.modules.parsing.api.ResultIterator; +import org.netbeans.modules.parsing.api.Source; +import org.netbeans.modules.parsing.api.UserTask; +import org.openide.cookies.SaveCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.util.NbBundle; /** * - * @author phrebejk + * @author Petr Hrebejk, Dusan Balek */ -public class FmtCodeGeneration extends javax.swing.JPanel { +public class FmtCodeGeneration extends javax.swing.JPanel implements Runnable, ListSelectionListener { /** Creates new form FmtCodeGeneration */ public FmtCodeGeneration() { initComponents(); preferLongerNamesCheckBox.putClientProperty(OPTION_ID, preferLongerNames); + isForBooleanGettersCheckBox.putClientProperty(OPTION_ID, useIsForBooleanGetters); fieldPrefixField.putClientProperty(OPTION_ID, fieldNamePrefix); fieldSuffixField.putClientProperty(OPTION_ID, fieldNameSuffix); staticFieldPrefixField.putClientProperty(OPTION_ID, staticFieldNamePrefix); @@ -70,18 +117,67 @@ localVarPrefixField.putClientProperty(OPTION_ID, localVarNamePrefix); localVarSuffixField.putClientProperty(OPTION_ID, localVarNameSuffix); qualifyFieldAccessCheckBox.putClientProperty(OPTION_ID, qualifyFieldAccess); - isForBooleanGettersCheckBox.putClientProperty(OPTION_ID, useIsForBooleanGetters); addOverrideAnnortationCheckBox.putClientProperty(OPTION_ID, addOverrideAnnotation); parametersFinalCheckBox.putClientProperty(OPTION_ID, makeParametersFinal); localVarsFinalCheckBox.putClientProperty(OPTION_ID, makeLocalVarsFinal); - // importsOrderList.putClientProperty(OPTION_ID, importsOrder); XXX - + membersOrderList.putClientProperty(OPTION_ID, classMembersOrder); + sortByVisibilityCheckBox.putClientProperty(OPTION_ID, sortMembersByVisibility); + visibilityOrderList.putClientProperty(OPTION_ID, visibilityOrder); + insertionPointComboBox.putClientProperty(OPTION_ID, classMemberInsertionPoint); } public static PreferencesCustomizer.Factory getController() { - return new CategorySupport.Factory("code-generation", FmtCodeGeneration.class, null); + return new PreferencesCustomizer.Factory() { + public PreferencesCustomizer create(Preferences preferences) { + CodeGenCategorySupport support = new CodeGenCategorySupport(preferences, new FmtCodeGeneration()); + ((Runnable)support.panel).run(); + return support; + } + }; } + @Override + public void run() { + membersOrderList.setSelectedIndex(0); + membersOrderList.addListSelectionListener(this); + enableMembersOrderButtons(); + visibilityOrderList.setSelectedIndex(0); + visibilityOrderList.addListSelectionListener(this); + enableVisibilityOrder(); + namingConventionsLabel.setVisible(false); + preferLongerNamesCheckBox.setVisible(false); + isForBooleanGettersCheckBox.setVisible(false); + prefixLabel.setVisible(false); + suffixLabel.setVisible(false); + fieldLabel.setVisible(false); + fieldPrefixField.setVisible(false); + fieldSuffixField.setVisible(false); + staticFieldLabel.setVisible(false); + staticFieldPrefixField.setVisible(false); + staticFieldSuffixField.setVisible(false); + parameterLabel.setVisible(false); + parameterPrefixField.setVisible(false); + parameterSuffixField.setVisible(false); + localVarLabel.setVisible(false); + localVarPrefixField.setVisible(false); + localVarSuffixField.setVisible(false); + jSeparator1.setVisible(false); + otherLabel.setVisible(false); + qualifyFieldAccessCheckBox.setVisible(false); + addOverrideAnnortationCheckBox.setVisible(false); + parametersFinalCheckBox.setVisible(false); + localVarsFinalCheckBox.setVisible(false); + jSeparator3.setVisible(false); + } + + @Override + public void valueChanged(ListSelectionEvent e) { + if (e.getSource() == membersOrderList) + enableMembersOrderButtons(); + else + enableVisibilityOrder(); + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is @@ -91,8 +187,10 @@ private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; - preferLongerNamesLabel = new javax.swing.JLabel(); + namingConventionsLabel = new javax.swing.JLabel(); preferLongerNamesCheckBox = new javax.swing.JCheckBox(); + isForBooleanGettersCheckBox = new javax.swing.JCheckBox(); + jPanel1 = new javax.swing.JPanel(); prefixLabel = new javax.swing.JLabel(); suffixLabel = new javax.swing.JLabel(); fieldLabel = new javax.swing.JLabel(); @@ -105,295 +203,610 @@ parameterPrefixField = new javax.swing.JTextField(); parameterSuffixField = new javax.swing.JTextField(); localVarLabel = new javax.swing.JLabel(); + localVarSuffixField = new javax.swing.JTextField(); localVarPrefixField = new javax.swing.JTextField(); - localVarSuffixField = new javax.swing.JTextField(); - miscLabel = new javax.swing.JLabel(); + jSeparator1 = new javax.swing.JSeparator(); + otherLabel = new javax.swing.JLabel(); qualifyFieldAccessCheckBox = new javax.swing.JCheckBox(); - isForBooleanGettersCheckBox = new javax.swing.JCheckBox(); addOverrideAnnortationCheckBox = new javax.swing.JCheckBox(); - finalLabel = new javax.swing.JLabel(); parametersFinalCheckBox = new javax.swing.JCheckBox(); localVarsFinalCheckBox = new javax.swing.JCheckBox(); - jLabel10 = new javax.swing.JLabel(); - jPanel1 = new javax.swing.JPanel(); + memberOrderLabel = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); - importsOrderList = new javax.swing.JList(); - importUpButton = new javax.swing.JButton(); - importDownButton = new javax.swing.JButton(); + membersOrderList = new javax.swing.JList(); + upButton = new javax.swing.JButton(); + downButton = new javax.swing.JButton(); + jSeparator3 = new javax.swing.JSeparator(); + sortByVisibilityCheckBox = new javax.swing.JCheckBox(); + jScrollPane2 = new javax.swing.JScrollPane(); + visibilityOrderList = new javax.swing.JList(); + visUpButton = new javax.swing.JButton(); + visDownButton = new javax.swing.JButton(); + jSeparator2 = new javax.swing.JSeparator(); + insertionPointLabel = new javax.swing.JLabel(); + insertionPointComboBox = new javax.swing.JComboBox(); setName(org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_CodeGeneration")); // NOI18N setOpaque(false); - setLayout(new java.awt.GridBagLayout()); - org.openide.awt.Mnemonics.setLocalizedText(preferLongerNamesLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Naming")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(preferLongerNamesLabel, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(namingConventionsLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Naming")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(preferLongerNamesCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_PreferLongerNames")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(preferLongerNamesCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_PreferLongerNames")); // NOI18N preferLongerNamesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); preferLongerNamesCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); preferLongerNamesCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(preferLongerNamesCheckBox, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(prefixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Prefix")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(isForBooleanGettersCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_UseIsForBooleanGetters")); // NOI18N + isForBooleanGettersCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + isForBooleanGettersCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); + isForBooleanGettersCheckBox.setOpaque(false); + + jPanel1.setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(prefixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Prefix")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(prefixLabel, gridBagConstraints); + jPanel1.add(prefixLabel, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(suffixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Suffix")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(suffixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Suffix")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(suffixLabel, gridBagConstraints); + jPanel1.add(suffixLabel, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Field")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Field")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(fieldLabel, gridBagConstraints); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + jPanel1.add(fieldLabel, gridBagConstraints); fieldPrefixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(fieldPrefixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(fieldPrefixField, gridBagConstraints); fieldSuffixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(fieldSuffixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(fieldSuffixField, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(staticFieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_StaticField")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(staticFieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_StaticField")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(staticFieldLabel, gridBagConstraints); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + jPanel1.add(staticFieldLabel, gridBagConstraints); staticFieldPrefixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(staticFieldPrefixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(staticFieldPrefixField, gridBagConstraints); staticFieldSuffixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(staticFieldSuffixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(staticFieldSuffixField, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(parameterLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Parameter")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(parameterLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Parameter")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(parameterLabel, gridBagConstraints); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + jPanel1.add(parameterLabel, gridBagConstraints); parameterPrefixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(parameterPrefixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(parameterPrefixField, gridBagConstraints); parameterSuffixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(parameterSuffixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0); + jPanel1.add(parameterSuffixField, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(localVarLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_LocalVariable")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(localVarLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_LocalVariable")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 9, 0); - add(localVarLabel, gridBagConstraints); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0); + jPanel1.add(localVarLabel, gridBagConstraints); + + localVarSuffixField.setColumns(5); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0); + jPanel1.add(localVarSuffixField, gridBagConstraints); localVarPrefixField.setColumns(5); gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 9, 0); - add(localVarPrefixField, gridBagConstraints); + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0); + jPanel1.add(localVarPrefixField, gridBagConstraints); - localVarSuffixField.setColumns(5); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 9, 0); - add(localVarSuffixField, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(otherLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Other")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(miscLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_Misc")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(miscLabel, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(qualifyFieldAccessCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_QualifyFieldAccess")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(qualifyFieldAccessCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_QualifyFieldAccess")); // NOI18N qualifyFieldAccessCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); qualifyFieldAccessCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); qualifyFieldAccessCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(qualifyFieldAccessCheckBox, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(isForBooleanGettersCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_UseIsForBooleanGetters")); // NOI18N - isForBooleanGettersCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - isForBooleanGettersCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); - isForBooleanGettersCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(isForBooleanGettersCheckBox, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(addOverrideAnnortationCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_AddOverrideAnnotation")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(addOverrideAnnortationCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_AddOverrideAnnotation")); // NOI18N addOverrideAnnortationCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); addOverrideAnnortationCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); addOverrideAnnortationCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 0); - add(addOverrideAnnortationCheckBox, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(finalLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_FinalMofier")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(finalLabel, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(parametersFinalCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_ParametersFinal")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(parametersFinalCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_ParametersFinal")); // NOI18N parametersFinalCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); parametersFinalCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); parametersFinalCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - add(parametersFinalCheckBox, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(localVarsFinalCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_LocalVariablesFinal")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(localVarsFinalCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_LocalVariablesFinal")); // NOI18N localVarsFinalCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); localVarsFinalCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); localVarsFinalCheckBox.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 0); - add(localVarsFinalCheckBox, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_ImportOredering")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - add(jLabel10, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(memberOrderLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_MembersOreder")); // NOI18N - jPanel1.setOpaque(false); - jPanel1.setLayout(new java.awt.GridBagLayout()); - - importsOrderList.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + membersOrderList.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); - jScrollPane1.setViewportView(importsOrderList); + membersOrderList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + jScrollPane1.setViewportView(membersOrderList); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0); - jPanel1.add(jScrollPane1, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(upButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_MembersOrederUp")); // NOI18N + upButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + upButtonActionPerformed(evt); + } + }); - org.openide.awt.Mnemonics.setLocalizedText(importUpButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_ImportUp")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 1); - jPanel1.add(importUpButton, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(downButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_MembersOrederDown")); // NOI18N + downButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + downButtonActionPerformed(evt); + } + }); - org.openide.awt.Mnemonics.setLocalizedText(importDownButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_ImportDown")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 1); - jPanel1.add(importDownButton, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(sortByVisibilityCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_SortByVisibility")); // NOI18N + sortByVisibilityCheckBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + sortByVisibilityCheckBoxActionPerformed(evt); + } + }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(jPanel1, gridBagConstraints); + visibilityOrderList.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + visibilityOrderList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + jScrollPane2.setViewportView(visibilityOrderList); + + org.openide.awt.Mnemonics.setLocalizedText(visUpButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_MembersOrederUp")); // NOI18N + visUpButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + visUpButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(visDownButton, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_MembersOrederDown")); // NOI18N + visDownButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + visDownButtonActionPerformed(evt); + } + }); + + insertionPointLabel.setLabelFor(insertionPointComboBox); + org.openide.awt.Mnemonics.setLocalizedText(insertionPointLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_InsertionPoint")); // NOI18N + + insertionPointComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSeparator1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(otherLabel) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(qualifyFieldAccessCheckBox) + .addComponent(addOverrideAnnortationCheckBox) + .addComponent(parametersFinalCheckBox) + .addComponent(localVarsFinalCheckBox)))) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(jSeparator3) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(namingConventionsLabel) + .addComponent(memberOrderLabel) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(isForBooleanGettersCheckBox) + .addComponent(preferLongerNamesCheckBox) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(downButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(visDownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(visUpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))))) + .addComponent(sortByVisibilityCheckBox) + .addGroup(layout.createSequentialGroup() + .addGap(5, 5, 5) + .addComponent(insertionPointLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(insertionPointComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addContainerGap()) + .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(namingConventionsLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(preferLongerNamesCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(isForBooleanGettersCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(otherLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(qualifyFieldAccessCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(addOverrideAnnortationCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(parametersFinalCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(localVarsFinalCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(memberOrderLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addComponent(upButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(downButton))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sortByVisibilityCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addComponent(visUpButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(visDownButton))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(10, 10, 10) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(insertionPointLabel) + .addComponent(insertionPointComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); }// //GEN-END:initComponents + + private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed + int idx = membersOrderList.getSelectedIndex(); + if (idx > 0) { + Object val = membersOrderList.getModel().getElementAt(idx); + ((DefaultListModel)membersOrderList.getModel()).removeElementAt(idx); + ((DefaultListModel)membersOrderList.getModel()).insertElementAt(val, idx - 1); + membersOrderList.setSelectedIndex(idx - 1); + } + }//GEN-LAST:event_upButtonActionPerformed + + private void downButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed + int idx = membersOrderList.getSelectedIndex(); + if (idx >= 0 && idx < membersOrderList.getModel().getSize() - 1) { + Object val = membersOrderList.getModel().getElementAt(idx); + ((DefaultListModel)membersOrderList.getModel()).removeElementAt(idx); + ((DefaultListModel)membersOrderList.getModel()).insertElementAt(val, idx + 1); + membersOrderList.setSelectedIndex(idx + 1); + } + }//GEN-LAST:event_downButtonActionPerformed + + private void visUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_visUpButtonActionPerformed + int idx = visibilityOrderList.getSelectedIndex(); + if (idx > 0) { + Object val = visibilityOrderList.getModel().getElementAt(idx); + ((DefaultListModel)visibilityOrderList.getModel()).removeElementAt(idx); + ((DefaultListModel)visibilityOrderList.getModel()).insertElementAt(val, idx - 1); + visibilityOrderList.setSelectedIndex(idx - 1); + } + }//GEN-LAST:event_visUpButtonActionPerformed + + private void visDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_visDownButtonActionPerformed + int idx = visibilityOrderList.getSelectedIndex(); + if (idx >= 0 && idx < visibilityOrderList.getModel().getSize() - 1) { + Object val = visibilityOrderList.getModel().getElementAt(idx); + ((DefaultListModel)visibilityOrderList.getModel()).removeElementAt(idx); + ((DefaultListModel)visibilityOrderList.getModel()).insertElementAt(val, idx + 1); + visibilityOrderList.setSelectedIndex(idx + 1); + } + }//GEN-LAST:event_visDownButtonActionPerformed + + private void sortByVisibilityCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sortByVisibilityCheckBoxActionPerformed + enableVisibilityOrder(); + }//GEN-LAST:event_sortByVisibilityCheckBoxActionPerformed + private void enableMembersOrderButtons() { + int idx = membersOrderList.getSelectedIndex(); + upButton.setEnabled(idx > 0); + downButton.setEnabled(idx >= 0 && idx < membersOrderList.getModel().getSize() - 1); + } + + private void enableVisibilityOrder() { + int idx = visibilityOrderList.getSelectedIndex(); + boolean b = sortByVisibilityCheckBox.isSelected(); + visibilityOrderList.setEnabled(b); + visUpButton.setEnabled(b && idx > 0); + visDownButton.setEnabled(b && idx >= 0 && idx < visibilityOrderList.getModel().getSize() - 1); + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox addOverrideAnnortationCheckBox; + private javax.swing.JButton downButton; private javax.swing.JLabel fieldLabel; private javax.swing.JTextField fieldPrefixField; private javax.swing.JTextField fieldSuffixField; - private javax.swing.JLabel finalLabel; - private javax.swing.JButton importDownButton; - private javax.swing.JButton importUpButton; - private javax.swing.JList importsOrderList; + private javax.swing.JComboBox insertionPointComboBox; + private javax.swing.JLabel insertionPointLabel; private javax.swing.JCheckBox isForBooleanGettersCheckBox; - private javax.swing.JLabel jLabel10; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JSeparator jSeparator3; private javax.swing.JLabel localVarLabel; private javax.swing.JTextField localVarPrefixField; private javax.swing.JTextField localVarSuffixField; private javax.swing.JCheckBox localVarsFinalCheckBox; - private javax.swing.JLabel miscLabel; + private javax.swing.JLabel memberOrderLabel; + private javax.swing.JList membersOrderList; + private javax.swing.JLabel namingConventionsLabel; + private javax.swing.JLabel otherLabel; private javax.swing.JLabel parameterLabel; private javax.swing.JTextField parameterPrefixField; private javax.swing.JTextField parameterSuffixField; private javax.swing.JCheckBox parametersFinalCheckBox; private javax.swing.JCheckBox preferLongerNamesCheckBox; - private javax.swing.JLabel preferLongerNamesLabel; private javax.swing.JLabel prefixLabel; private javax.swing.JCheckBox qualifyFieldAccessCheckBox; + private javax.swing.JCheckBox sortByVisibilityCheckBox; private javax.swing.JLabel staticFieldLabel; private javax.swing.JTextField staticFieldPrefixField; private javax.swing.JTextField staticFieldSuffixField; private javax.swing.JLabel suffixLabel; + private javax.swing.JButton upButton; + private javax.swing.JButton visDownButton; + private javax.swing.JButton visUpButton; + private javax.swing.JList visibilityOrderList; // End of variables declaration//GEN-END:variables + + private static final class CodeGenCategorySupport extends CategorySupport { + + private Source source = null; + + private CodeGenCategorySupport(Preferences preferences, JPanel panel) { + super(preferences, "code-generation", panel, NbBundle.getMessage(FmtCodeGeneration.class, "SAMPLE_CodeGen"), //NOI18N + new String[] { FmtOptions.blankLinesBeforeFields, "1" }); //NOI18N + } + @Override + protected void loadListData(JList list, String optionID, Preferences node) { + DefaultListModel model = new DefaultListModel(); + String value = node.get(optionID, getDefaultAsString(optionID)); + for (String s : value.trim().split("\\s*[,;]\\s*")) { //NOI18N + if (classMembersOrder.equals(optionID)) { + Element e = new Element(); + if (s.startsWith("STATIC ")) { //NOI18N + e.isStatic = true; + s = s.substring(7); + } + e.kind = ElementKind.valueOf(s); + model.addElement(e); + } else { + Visibility v = new Visibility(); + v.kind = s; + model.addElement(v); + } + } + list.setModel(model); + } + + @Override + protected void storeListData(final JList list, final String optionID, final Preferences node) { + StringBuilder sb = null; + for (int i = 0; i < list.getModel().getSize(); i++) { + if (sb == null) { + sb = new StringBuilder(); + } else { + sb.append(';'); + } + if (classMembersOrder.equals(optionID)) { + Element e = (Element) list.getModel().getElementAt(i); + if (e.isStatic) + sb.append("STATIC "); //NOI18N + sb.append(e.kind.name()); + } else { + Visibility v = (Visibility) list.getModel().getElementAt(i); + sb.append(v.kind); + } + } + String value = sb != null ? sb.toString() : ""; //NOI18N + if (getDefaultAsString(optionID).equals(value)) + node.remove(optionID); + else + node.put(optionID, value); + } + + @Override + public void refreshPreview() { + final JEditorPane jep = (JEditorPane) getPreviewComponent(); + try { + Class.forName(CodeStyle.class.getName(), true, CodeStyle.class.getClassLoader()); + } catch (ClassNotFoundException cnfe) { + // ignore + } + + final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs); + jep.setIgnoreRepaint(true); + try { + if (source == null) { + FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("org.netbeans.samples.ClassA", "java"); //NOI18N + source = Source.create(fo); + } + final Document doc = source.getDocument(true); + if (doc.getLength() > 0) { + doc.remove(0, doc.getLength()); + } + doc.insertString(0, previewText, null); + doc.putProperty(CodeStyle.class, codeStyle); + jep.setDocument(doc); + ModificationResult result = ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() { + + @Override + public void run(ResultIterator resultIterator) throws Exception { + WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); + copy.toPhase(Phase.RESOLVED); + TreeMaker tm = copy.getTreeMaker(); + GeneratorUtilities gu = GeneratorUtilities.get(copy); + CompilationUnitTree cut = copy.getCompilationUnit(); + ClassTree ct = (ClassTree) cut.getTypeDecls().get(0); + VariableTree field = (VariableTree)ct.getMembers().get(1); + List members = new ArrayList(); + AssignmentTree stat = tm.Assignment(tm.Identifier("name"), tm.Literal("Name")); //NOI18N + BlockTree init = tm.Block(Collections.singletonList(tm.ExpressionStatement(stat)), false); + members.add(init); + members.add(gu.createConstructor(ct, Collections.emptyList())); + members.add(gu.createGetter(field)); + ModifiersTree mods = tm.Modifiers(EnumSet.of(Modifier.PRIVATE)); + ClassTree inner = tm.Class(mods, "Inner", Collections.emptyList(), null, Collections.emptyList(), Collections.emptyList()); //NOI18N + members.add(inner); + mods = tm.Modifiers(EnumSet.of(Modifier.PRIVATE, Modifier.STATIC)); + ClassTree nested = tm.Class(mods, "Nested", Collections.emptyList(), null, Collections.emptyList(), Collections.emptyList()); //NOI18N + members.add(nested); + IdentifierTree nestedId = tm.Identifier("Nested"); //NOI18N + VariableTree staticField = tm.Variable(mods, "instance", nestedId, null); //NOI18N + members.add(staticField); + NewClassTree nct = tm.NewClass(null, Collections.emptyList(), nestedId, Collections.emptyList(), null); + stat = tm.Assignment(tm.Identifier("instance"), nct); //NOI18N + BlockTree staticInit = tm.Block(Collections.singletonList(tm.ExpressionStatement(stat)), true); + members.add(staticInit); + members.add(gu.createGetter(staticField)); + ClassTree newCT = gu.insertClassMembers(ct, members); + copy.rewrite(ct, newCT); + } + }); + result.commit(); + final Reformat reformat = Reformat.get(doc); + reformat.lock(); + try { + if (doc instanceof BaseDocument) { + ((BaseDocument) doc).runAtomicAsUser(new Runnable() { + @Override + public void run() { + try { + reformat.reformat(0, doc.getLength()); + } catch (BadLocationException ble) {} + } + }); + } else { + reformat.reformat(0, doc.getLength()); + } + } finally { + reformat.unlock(); + } + DataObject dataObject = DataObject.find(source.getFileObject()); + SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class); + if (sc != null) + sc.save(); + } catch (Exception ex) {} + jep.setIgnoreRepaint(false); + jep.scrollRectToVisible(new Rectangle(0, 0, 10, 10)); + jep.repaint(100); + } + + private static class Element { + + private boolean isStatic; + private ElementKind kind; + + @Override + public String toString() { + return (isStatic ? NbBundle.getMessage(FmtCodeGeneration.class, "VAL_gen_STATIC") + " " : "") //NOI18N + + NbBundle.getMessage(FmtCodeGeneration.class, "VAL_gen_" + kind.name()); //NOI18N + } + } + + private static class Visibility { + + private String kind; + + @Override + public String toString() { + return NbBundle.getMessage(FmtCodeGeneration.class, "VAL_gen_" + kind); //NOI18N + } + } + } } --- a/java.source/src/org/netbeans/modules/java/ui/FmtOptions.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtOptions.java Thu Feb 16 13:28:43 2012 +0100 @@ -63,6 +63,7 @@ import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JEditorPane; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.JTable; @@ -72,6 +73,8 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import org.netbeans.api.editor.settings.SimpleValueNames; @@ -119,6 +122,9 @@ public static final String makeLocalVarsFinal = "makeLocalVarsFinal"; //NOI18N public static final String makeParametersFinal = "makeParametersFinal"; //NOI18N public static final String classMembersOrder = "classMembersOrder"; //NOI18N + public static final String sortMembersByVisibility = "sortMembersByVisibility"; //NOI18N + public static final String visibilityOrder = "visibilityOrder"; //NOI18N + public static final String classMemberInsertionPoint = "classMemberInsertionPoint"; //NOI18N public static final String classDeclBracePlacement = "classDeclBracePlacement"; //NOI18N public static final String methodDeclBracePlacement = "methodDeclBracePlacement"; //NOI18N @@ -155,6 +161,7 @@ public static final String wrapMethodCallArgs = "wrapMethodCallArgs"; //NOI18N public static final String wrapAnnotationArgs = "wrapAnnotationArgs"; //NOI18N public static final String wrapChainedMethodCalls = "wrapChainedMethodCalls"; //NOI18N + public static final String wrapAfterDotInChainedMethodCalls = "wrapAfterDotInChainedMethodCalls"; //NOI18N public static final String wrapArrayInit = "wrapArrayInit"; //NOI18N public static final String wrapTryResources = "wrapTryResources"; //NOI18N public static final String wrapDisjunctiveCatchTypes = "wrapDisjunctiveCatchTypes"; //NOI18N @@ -179,6 +186,7 @@ public static final String blankLinesBeforeClass = "blankLinesBeforeClass"; //NOI18N public static final String blankLinesAfterClass = "blankLinesAfterClass"; //NOI18N public static final String blankLinesAfterClassHeader = "blankLinesAfterClassHeader"; //NOI18N + public static final String blankLinesAfterAnonymousClassHeader = "blankLinesAfterAnonymousClassHeader"; //NOI18N public static final String blankLinesBeforeFields = "blankLinesBeforeFields"; //NOI18N public static final String blankLinesAfterFields = "blankLinesAfterFields"; //NOI18N public static final String blankLinesBeforeMethods = "blankLinesBeforeMethods"; //NOI18N @@ -202,6 +210,7 @@ public static final String spaceAroundBinaryOps = "spaceAroundBinaryOps"; //NOI18N public static final String spaceAroundTernaryOps = "spaceAroundTernaryOps"; //NOI18N public static final String spaceAroundAssignOps = "spaceAroundAssignOps"; //NOI18N + public static final String spaceAroundAnnotationValueAssignOps = "spaceAroundAnnotationValueAssignOps"; //NOI18N public static final String spaceBeforeClassDeclLeftBrace = "spaceBeforeClassDeclLeftBrace"; //NOI18N public static final String spaceBeforeMethodDeclLeftBrace = "spaceBeforeMethodDeclLeftBrace"; //NOI18N public static final String spaceBeforeIfLeftBrace = "spaceBeforeIfLeftBrace"; //NOI18N @@ -340,7 +349,11 @@ private static final String BGS_ELIMINATE = BracesGenerationStyle.ELIMINATE.name(); private static final String BGS_LEAVE_ALONE = BracesGenerationStyle.LEAVE_ALONE.name(); - private static final String BGS_GENERATE = BracesGenerationStyle.GENERATE.name(); + private static final String BGS_GENERATE = BracesGenerationStyle.GENERATE.name(); + + private static final String IP_CARET = InsertionPoint.CARET_LOCATION.name(); + private static final String IP_FIRST = InsertionPoint.FIRST_IN_CATEGORY.name(); + private static final String IP_LAST = InsertionPoint.LAST_IN_CATEGORY.name(); private static Map defaults; @@ -376,7 +389,10 @@ { addOverrideAnnotation, TRUE}, //NOI18N { makeLocalVarsFinal, FALSE}, //NOI18N { makeParametersFinal, FALSE}, //NOI18N - { classMembersOrder, ""}, //NOI18N // XXX + { classMembersOrder, "STATIC FIELD;STATIC_INIT;STATIC METHOD;FIELD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS"}, //NOI18N + { sortMembersByVisibility, FALSE}, //NOI18N + { visibilityOrder, "PUBLIC;PRIVATE;PROTECTED;DEFAULT"}, //NOI18N + { classMemberInsertionPoint, IP_LAST}, { classDeclBracePlacement, BP_SAME_LINE}, //NOI18N { methodDeclBracePlacement, BP_SAME_LINE}, //NOI18N @@ -413,6 +429,7 @@ { wrapMethodCallArgs, WRAP_NEVER}, //NOI18N { wrapAnnotationArgs, WRAP_NEVER}, //NOI18N { wrapChainedMethodCalls, WRAP_NEVER}, //NOI18N + { wrapAfterDotInChainedMethodCalls, TRUE}, //NOI18N { wrapArrayInit, WRAP_NEVER}, //NOI18N { wrapTryResources, WRAP_NEVER}, //NOI18N { wrapDisjunctiveCatchTypes, WRAP_NEVER}, //NOI18N @@ -437,6 +454,7 @@ { blankLinesBeforeClass, "1"}, //NOI18N { blankLinesAfterClass, "0"}, //NOI18N { blankLinesAfterClassHeader, "1"}, //NOI18N + { blankLinesAfterAnonymousClassHeader, "0"}, //NOI18N { blankLinesBeforeFields, "0"}, //NOI18N { blankLinesAfterFields, "0"}, //NOI18N { blankLinesBeforeMethods, "1"}, //NOI18N @@ -460,6 +478,7 @@ { spaceAroundBinaryOps, TRUE}, //NOI18N { spaceAroundTernaryOps, TRUE}, //NOI18N { spaceAroundAssignOps, TRUE}, //NOI18N + { spaceAroundAnnotationValueAssignOps, TRUE}, //NOI18N { spaceBeforeClassDeclLeftBrace, TRUE}, //NOI18N { spaceBeforeMethodDeclLeftBrace, TRUE}, //NOI18N { spaceBeforeIfLeftBrace, TRUE}, //NOI18N @@ -534,7 +553,7 @@ // Support section --------------------------------------------------------- - public static class CategorySupport implements ActionListener, ChangeListener, TableModelListener, DocumentListener, PreviewProvider, PreferencesCustomizer { + public static class CategorySupport implements ActionListener, ChangeListener, ListDataListener, TableModelListener, DocumentListener, PreviewProvider, PreferencesCustomizer { public static final String OPTION_ID = "org.netbeans.modules.java.ui.FormatingOptions.ID"; @@ -560,6 +579,12 @@ new ComboItem( WrapStyle.WRAP_NEVER.name(), "LBL_wrp_WRAP_NEVER" ) // NOI18N }; + private static final ComboItem insertionPoint[] = new ComboItem[] { + new ComboItem( InsertionPoint.LAST_IN_CATEGORY.name(), "LBL_ip_LAST_IN_CATEGORY" ), // NOI18N + new ComboItem( InsertionPoint.FIRST_IN_CATEGORY.name(), "LBL_ip_FIRST_IN_CATEGORY" ), // NOI18N + new ComboItem( InsertionPoint.CARET_LOCATION.name(), "LBL_ip_CARET_LOCATION" ) // NOI18N + }; + protected final String previewText; // private String forcedOptions[][]; @@ -619,6 +644,12 @@ refreshPreview(); } + protected void loadListData(final JList list, final String optionID, final Preferences p) { + } + + protected void storeListData(final JList list, final String optionID, final Preferences node) { + } + protected void loadTableData(final JTable table, final String optionID, final Preferences p) { } @@ -638,6 +669,21 @@ notifyChanged(); } + // ListDataListener implementation ----------------------------------- + + @Override + public void contentsChanged(ListDataEvent e) { + } + + @Override + public void intervalAdded(ListDataEvent e) { + notifyChanged(); + } + + @Override + public void intervalRemoved(ListDataEvent e) { + } + // TableModelListener implementation ----------------------------------- @Override @@ -812,6 +858,9 @@ ComboItem item = whichItem(value, model); cb.setSelectedItem(item); } + else if ( jc instanceof JList ) { + loadListData((JList)jc, optionID, node); + } else if ( jc instanceof JTable ) { loadTableData((JTable)jc, optionID, node); } @@ -871,6 +920,9 @@ else node.put(optionID,value); } + else if ( jc instanceof JList ) { + storeListData((JList)jc, optionID, node); + } else if ( jc instanceof JTable ) { storeTableData((JTable)jc, optionID, node); } @@ -894,6 +946,10 @@ JComboBox cb = (JComboBox)jc; cb.addActionListener(this); } + else if ( jc instanceof JList) { + JList jl = (JList)jc; + jl.getModel().addListDataListener(this); + } else if ( jc instanceof JTable) { JTable jt = (JTable)jc; jt.getModel().addTableModelListener(this); @@ -917,13 +973,20 @@ } } - // is it wrap + // is it wrap? for (ComboItem comboItem : wrap) { if ( value.equals( comboItem.value) ) { return new DefaultComboBoxModel( wrap ); } } + // is it insertion point? + for (ComboItem comboItem : insertionPoint) { + if ( value.equals( comboItem.value) ) { + return new DefaultComboBoxModel( insertionPoint ); + } + } + return null; } --- a/java.source/src/org/netbeans/modules/java/ui/FmtSpaces.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtSpaces.java Thu Feb 16 13:28:43 2012 +0100 @@ -244,7 +244,8 @@ new Item(spaceAroundUnaryOps), new Item(spaceAroundBinaryOps), new Item(spaceAroundTernaryOps), - new Item(spaceAroundAssignOps) ), + new Item(spaceAroundAssignOps), + new Item(spaceAroundAnnotationValueAssignOps) ), new Item("BeforeLeftBraces", // NOI18N new Item(spaceBeforeClassDeclLeftBrace), --- a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.form Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.form Thu Feb 16 13:28:43 2012 +0100 @@ -1,4 +1,4 @@ - +
@@ -241,6 +241,27 @@ + + + + + + + + + + + + + + + + + + + + + --- a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.java Mon Feb 13 16:58:34 2012 +0100 +++ a/java.source/src/org/netbeans/modules/java/ui/FmtWrapping.java Thu Feb 16 13:28:43 2012 +0100 @@ -77,6 +77,8 @@ annotationArgsCombo.addFocusListener(this); chainedMethodCallsCombo.putClientProperty(OPTION_ID, wrapChainedMethodCalls); chainedMethodCallsCombo.addFocusListener(this); + afterDotCheckBox.putClientProperty(OPTION_ID, wrapAfterDotInChainedMethodCalls); + afterDotCheckBox.addFocusListener(this); throwsKeywordCombo.putClientProperty(OPTION_ID, wrapThrowsKeyword); throwsKeywordCombo.addFocusListener(this); throwsListCombo.putClientProperty(OPTION_ID, wrapThrowsList); @@ -118,7 +120,7 @@ public static PreferencesCustomizer.Factory getController() { return new CategorySupport.Factory("wrapping", FmtWrapping.class, //NOI18N org.openide.util.NbBundle.getMessage(FmtWrapping.class, "SAMPLE_Wrapping"), //NOI18N - new String[] { FmtOptions.rightMargin, "30" }, //NOI18N + new String[] { FmtOptions.rightMargin, "35" }, //NOI18N new String[] { FmtOptions.redundantDoWhileBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, new String[] { FmtOptions.redundantForBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, new String[] { FmtOptions.redundantIfBraces, CodeStyle.BracesGenerationStyle.LEAVE_ALONE.name() }, @@ -158,6 +160,7 @@ annotationArgsCombo = new javax.swing.JComboBox(); chainedMethodCallsLabel = new javax.swing.JLabel(); chainedMethodCallsCombo = new javax.swing.JComboBox(); + afterDotCheckBox = new javax.swing.JCheckBox(); throwsKeywordLabel = new javax.swing.JLabel(); throwsKeywordCombo = new javax.swing.JComboBox(); throwsListLabel = new javax.swing.JLabel(); @@ -290,6 +293,16 @@ gridBagConstraints.insets = new java.awt.Insets(0, 6, 4, 8); panel1.add(chainedMethodCallsCombo, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(afterDotCheckBox, org.openide.util.NbBundle.getMessage(FmtWrapping.class, "LBL_wrp_afeterDot")); // NOI18N + afterDotCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + afterDotCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); + afterDotCheckBox.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(2, 8, 6, 0); + panel1.add(afterDotCheckBox, gridBagConstraints); + throwsKeywordLabel.setLabelFor(throwsKeywordCombo); org.openide.awt.Mnemonics.setLocalizedText(throwsKeywordLabel, org.openide.util.NbBundle.getMessage(FmtWrapping.class, "LBL_wrp_throwsKeyword")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); @@ -550,6 +563,7 @@ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox afterBinaryOpsCheckBox; + private javax.swing.JCheckBox afterDotCheckBox; private javax.swing.JCheckBox afterTernaryOpsCheckBox; private javax.swing.JComboBox annotationArgsCombo; private javax.swing.JLabel annotationArgsLabel;