diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java b/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/CodeStyle.java @@ -124,6 +124,11 @@ return BracePlacement.valueOf(placement); } + public BracePlacement getAnonymousClassBracePlacement() { + String placement = preferences.get(ANONYMOUS_CLASS_BRACE_PLACEMENT, getDefaultAsString(ANONYMOUS_CLASS_BRACE_PLACEMENT)); + return BracePlacement.valueOf(placement); + } + public BracePlacement getMethodDeclBracePlacement() { String placement = preferences.get(METHOD_DECL_BRACE_PLACEMENT, getDefaultAsString(METHOD_DECL_BRACE_PLACEMENT)); return BracePlacement.valueOf(placement); @@ -264,6 +269,10 @@ return preferences.getBoolean(SPACE_BEFORE_FINALLY, getDefaultAsBoolean(SPACE_BEFORE_FINALLY)); } + public boolean spaceBeforeAnonymousClassParen() { + return preferences.getBoolean(SPACE_BEFORE_ANONYMOUS_CLASS_PAREN, getDefaultAsBoolean(SPACE_BEFORE_ANONYMOUS_CLASS_PAREN)); + } + public boolean spaceBeforeMethodDeclParen() { return preferences.getBoolean(SPACE_BEFORE_METHOD_DECL_PAREN, getDefaultAsBoolean(SPACE_BEFORE_METHOD_DECL_PAREN)); } @@ -328,6 +337,10 @@ return preferences.getBoolean(SPACE_BEFORE_CLASS_DECL_LEFT_BRACE, getDefaultAsBoolean(SPACE_BEFORE_CLASS_DECL_LEFT_BRACE)); } + public boolean spaceBeforeAnonymousClassLeftBrace() { + return preferences.getBoolean(SPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE, getDefaultAsBoolean(SPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE)); + } + public boolean spaceBeforeMethodDeclLeftBrace() { return preferences.getBoolean(SPACE_BEFORE_METHOD_DECL_LEFT_BRACE, getDefaultAsBoolean(SPACE_BEFORE_METHOD_DECL_LEFT_BRACE)); } @@ -372,6 +385,10 @@ return preferences.getBoolean(SPACE_BEFORE_USE_TRAIT_BODY_LEFT_BRACE, getDefaultAsBoolean(SPACE_BEFORE_USE_TRAIT_BODY_LEFT_BRACE)); } + public boolean spaceWithinAnonymousClassParens() { + return preferences.getBoolean(SPACE_WITHIN_ANONYMOUS_CLASS_PARENS, getDefaultAsBoolean(SPACE_WITHIN_ANONYMOUS_CLASS_PARENS)); + } + public boolean spaceWithinMethodDeclParens() { return preferences.getBoolean(SPACE_WITHIN_METHOD_DECL_PARENS, getDefaultAsBoolean(SPACE_WITHIN_METHOD_DECL_PARENS)); } diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java b/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java @@ -103,6 +103,7 @@ public static final String RIGHT_MARGIN = SimpleValueNames.TEXT_LIMIT_WIDTH; public static final String INITIAL_INDENT = "init.indent"; //NOI18N public static final String CLASS_DECL_BRACE_PLACEMENT = "classDeclBracePlacement"; //NOI18N + public static final String ANONYMOUS_CLASS_BRACE_PLACEMENT = "anonymousClassBracePlacement"; //NOI18N public static final String METHOD_DECL_BRACE_PLACEMENT = "methodDeclBracePlacement"; //NOI18N public static final String IF_BRACE_PLACEMENT = "ifBracePlacement"; //NOI18N public static final String FOR_BRACE_PLACEMENT = "forBracePlacement"; //NOI18N @@ -134,6 +135,7 @@ public static final String SPACE_BEFORE_ELSE = "spaceBeforeElse"; //NOI18N public static final String SPACE_BEFORE_CATCH = "spaceBeforeCatch"; //NOI18N public static final String SPACE_BEFORE_FINALLY = "spaceBeforeFinally"; //NOI18N + public static final String SPACE_BEFORE_ANONYMOUS_CLASS_PAREN = "spaceBeforeAnonymousClassParen"; //NOI18N public static final String SPACE_BEFORE_METHOD_DECL_PAREN = "spaceBeforeMethodDeclParen"; //NOI18N public static final String SPACE_BEFORE_METHOD_CALL_PAREN = "spaceBeforeMethodCallParen"; //NOI18N public static final String SPACE_BEFORE_IF_PAREN = "spaceBeforeIfParen"; //NOI18N @@ -150,6 +152,7 @@ public static final String SPACE_AROUND_KEY_VALUE_OPS = "spaceAroundKeyValueOps"; //NOI18N public static final String SPACE_AROUND_OBJECT_OPS = "spaceAroundObjectOps"; //NOI18N public static final String SPACE_BEFORE_CLASS_DECL_LEFT_BRACE = "spaceBeforeClassDeclLeftBrace"; //NOI18N + public static final String SPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE = "spaceBeforeAnonymousClassLeftBrace"; //NOI18N public static final String SPACE_BEFORE_METHOD_DECL_LEFT_BRACE = "spaceBeforeMethodDeclLeftBrace"; //NOI18N public static final String SPACE_BEFORE_IF_LEFT_BRACE = "spaceBeforeIfLeftBrace"; //NOI18N public static final String SPACE_BEFORE_ELSE_LEFT_BRACE = "spaceBeforeElseLeftBrace"; //NOI18N @@ -162,6 +165,7 @@ public static final String SPACE_BEFORE_FINALLY_LEFT_BRACE = "spaceBeforeFinallyLeftBrace"; //NOI18N public static final String SPACE_BEFORE_USE_TRAIT_BODY_LEFT_BRACE = "spaceBeforeUseTraitBodyLeftBrace"; //NOI18N public static final String SPACE_WITHIN_ARRAY_DECL_PARENS = "spaceWithinArrayDeclParens"; //NOI18N + public static final String SPACE_WITHIN_ANONYMOUS_CLASS_PARENS = "spaceWithinAnonymousClassParens"; //NOI18N public static final String SPACE_WITHIN_METHOD_DECL_PARENS = "spaceWithinMethodDeclParens"; //NOI18N public static final String SPACE_WITHIN_METHOD_CALL_PARENS = "spaceWithinMethodCallParens"; //NOI18N public static final String SPACE_WITHIN_IF_PARENS = "spaceWithinIfParens"; //NOI18N @@ -264,6 +268,7 @@ {INITIAL_INDENT, "0"}, //NOI18N {CLASS_DECL_BRACE_PLACEMENT, OBRACE_SAMELINE}, + {ANONYMOUS_CLASS_BRACE_PLACEMENT, OBRACE_SAMELINE}, {METHOD_DECL_BRACE_PLACEMENT, OBRACE_SAMELINE}, {IF_BRACE_PLACEMENT, OBRACE_SAMELINE}, {FOR_BRACE_PLACEMENT, OBRACE_SAMELINE}, @@ -296,6 +301,7 @@ {SPACE_BEFORE_ELSE, TRUE}, {SPACE_BEFORE_CATCH, TRUE}, {SPACE_BEFORE_FINALLY, TRUE}, + {SPACE_BEFORE_ANONYMOUS_CLASS_PAREN, FALSE}, {SPACE_BEFORE_METHOD_DECL_PAREN, FALSE}, {SPACE_BEFORE_METHOD_CALL_PAREN, FALSE}, {SPACE_BEFORE_IF_PAREN, TRUE}, @@ -324,6 +330,7 @@ {SPACE_BEFORE_FINALLY_LEFT_BRACE, TRUE}, {SPACE_BEFORE_USE_TRAIT_BODY_LEFT_BRACE, TRUE}, {SPACE_WITHIN_ARRAY_DECL_PARENS, FALSE}, + {SPACE_WITHIN_ANONYMOUS_CLASS_PARENS, FALSE}, {SPACE_WITHIN_METHOD_DECL_PARENS, FALSE}, {SPACE_WITHIN_METHOD_CALL_PARENS, FALSE}, {SPACE_WITHIN_IF_PARENS, FALSE}, diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java b/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/FormatToken.java @@ -68,6 +68,7 @@ WHITESPACE_BETWEEN_USE, WHITESPACE_AFTER_USE, WHITESPACE_BEFORE_CLASS_LEFT_BRACE, + WHITESPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE, WHITESPACE_AROUND_OBJECT_OP, WHITESPACE_AROUND_CONCAT_OP, WHITESPACE_AROUND_UNARY_OP, @@ -78,6 +79,7 @@ WHITESPACE_BEFORE_ASSIGN_OP, WHITESPACE_AFTER_ASSIGN_OP, WHITESPACE_AROUND_KEY_VALUE_OP, + WHITESPACE_BEFORE_ANONYMOUS_CLASS_PAREN, WHITESPACE_BEFORE_METHOD_DEC_PAREN, WHITESPACE_BEFORE_METHOD_CALL_PAREN, WHITESPACE_BEFORE_IF_PAREN, @@ -87,6 +89,7 @@ WHITESPACE_BEFORE_SWITCH_PAREN, WHITESPACE_BEFORE_ARRAY_DECL_PAREN, WHITESPACE_AFTER_CLASS_LEFT_BRACE, + WHITESPACE_AFTER_ANONYMOUS_CLASS_LEFT_BRACE, WHITESPACE_AFTER_KEYWORD, WHITESPACE_BEFORE_FUNCTION_LEFT_BRACE, WHITESPACE_BEFORE_IF_LEFT_BRACE, @@ -101,6 +104,7 @@ WHITESPACE_BEFORE_OTHER_LEFT_BRACE, WHITESPACE_AFTER_OTHER_LEFT_BRACE, WHITESPACE_BEFORE_CLASS_RIGHT_BRACE, + WHITESPACE_BEFORE_ANONYMOUS_CLASS_RIGHT_BRACE, WHITESPACE_BEFORE_FUNCTION_RIGHT_BRACE, WHITESPACE_BEFORE_IF_RIGHT_BRACE, WHITESPACE_BEFORE_FOR_RIGHT_BRACE, @@ -115,6 +119,7 @@ WHITESPACE_BEFORE_USE_TRAIT_BODY_RIGHT_BRACE, WHITESPACE_AFTER_ARRAY_DECL_LEFT_PAREN, WHITESPACE_BEFORE_ARRAY_DECL_RIGHT_PAREN, + WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS, WHITESPACE_WITHIN_METHOD_DECL_PARENS, WHITESPACE_WITHIN_METHOD_CALL_PARENS, WHITESPACE_WITHIN_IF_PARENS, @@ -131,6 +136,7 @@ WHITESPACE_AFTER_TYPE_CAST, WHITESPACE_BEFORE_CLASS, WHITESPACE_AFTER_CLASS, + WHITESPACE_AFTER_ANONYMOUS_CLASS, WHITESPACE_BEFORE_FUNCTION, WHITESPACE_AFTER_FUNCTION, WHITESPACE_BEFORE_FIELDS, diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java b/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java @@ -419,6 +419,8 @@ if (ts.token().id() == PHPTokenId.PHP_CURLY_OPEN) { if (parent instanceof ClassDeclaration || parent instanceof InterfaceDeclaration || parent instanceof TraitDeclaration) { formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_CLASS_LEFT_BRACE, ts.offset())); + } else if (isAnonymousClass(parent)) { + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE, ts.offset())); } else if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_FUNCTION_LEFT_BRACE, ts.offset())); } else if (parent instanceof IfStatement) { @@ -466,6 +468,8 @@ if (parent instanceof ClassDeclaration || parent instanceof InterfaceDeclaration || parent instanceof TraitDeclaration) { formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_CLASS_LEFT_BRACE, ts.offset())); + } else if (isAnonymousClass(parent)) { + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_ANONYMOUS_CLASS_LEFT_BRACE, ts.offset())); } else { formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_OTHER_LEFT_BRACE, ts.offset())); } @@ -516,6 +520,12 @@ } addFormatToken(formatTokens); formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_CLASS, ts.offset() + ts.token().length())); + } else if (isAnonymousClass(parent)) { + if (includeWSBeforePHPDoc) { + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_ANONYMOUS_CLASS_RIGHT_BRACE, ts.offset())); + } + addFormatToken(formatTokens); + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AFTER_ANONYMOUS_CLASS, ts.offset() + ts.token().length())); } else if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_FUNCTION_RIGHT_BRACE, ts.offset())); addFormatToken(formatTokens); @@ -640,18 +650,44 @@ @Override public void visit(ClassInstanceCreation node) { scan(node.getClassName()); - if (node.ctorParams() != null && node.ctorParams().size() > 0) { - boolean addIndentation = (path.size() > 2 && (path.get(1) instanceof ArrayElement) && (path.get(2) instanceof ArrayCreation)); - if (addIndentation) { - formatTokens.add(new FormatToken.IndentToken(node.getClassName().getEndOffset(), options.continualIndentSize)); + if (node.isAnonymous()) { + while (ts.moveNext() && ts.token().id() != PHPTokenId.PHP_CURLY_OPEN) { + switch (ts.token().id()) { + case PHP_CLASS: + addFormatToken(formatTokens); + break; + case PHP_IMPLEMENTS: + if (node.getInterfaces().size() > 0) { + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_EXTENDS_IMPLEMENTS, ts.offset(), ts.token().text().toString())); + ts.movePrevious(); + addListOfNodes(node.getInterfaces(), FormatToken.Kind.WHITESPACE_IN_INTERFACE_LIST); + } + break; + case PHP_EXTENDS: + formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_EXTENDS_IMPLEMENTS, ts.offset(), ts.token().text().toString())); + addFormatToken(formatTokens); + break; + default: + addFormatToken(formatTokens); + } } - processArguments(node.ctorParams()); - if (addIndentation) { - formatTokens.add(new FormatToken.IndentToken(node.ctorParams().get(node.ctorParams().size() - 1).getEndOffset(), -1 * options.continualIndentSize)); + + ts.movePrevious(); + super.visit(node); + } else { + if (node.ctorParams() != null && node.ctorParams().size() > 0) { + boolean addIndentation = (path.size() > 2 && (path.get(1) instanceof ArrayElement) && (path.get(2) instanceof ArrayCreation)); + if (addIndentation) { + formatTokens.add(new FormatToken.IndentToken(node.getClassName().getEndOffset(), options.continualIndentSize)); + } + processArguments(node.ctorParams()); + if (addIndentation) { + formatTokens.add(new FormatToken.IndentToken(node.ctorParams().get(node.ctorParams().size() - 1).getEndOffset(), -1 * options.continualIndentSize)); + } + addAllUntilOffset(node.getEndOffset()); + } else { + super.visit(node); } - addAllUntilOffset(node.getEndOffset()); - } else { - super.visit(node); } } @@ -899,6 +935,14 @@ addFormatToken(formatTokens); // add the first token of the expression and then add the indentation Expression expression = node.getExpression(); boolean addIndent = !(expression instanceof MethodInvocation || expression instanceof StaticMethodInvocation); + if (expression instanceof Assignment) { + // anonymous classes + Assignment assignment = (Assignment) expression; + Expression right = assignment.getRightHandSide(); + if (isAnonymousClass(right)) { + addIndent = false; + } + } if (addIndent) { formatTokens.add(new FormatToken.IndentToken(ts.offset() + ts.token().length(), options.continualIndentSize)); super.visit(node); @@ -1121,6 +1165,16 @@ boolean addIndentation = !(path.get(1) instanceof ReturnStatement || path.get(1) instanceof Assignment || (path.size() > 2 && path.get(1) instanceof MethodInvocation && path.get(2) instanceof Assignment)); + // anonymous classes + if (options.wrapMethodCallArgs != CodeStyle.WrapStyle.WRAP_ALWAYS) { + for (Expression parameter : parameters) { + if (isAnonymousClass(parameter)) { + addIndentation = false; + break; + } + } + } + if (addIndentation) { formatTokens.add(new FormatToken.IndentToken(node.getFunctionName().getEndOffset(), options.continualIndentSize)); } @@ -1288,6 +1342,19 @@ shift = true; addAllUntilOffset(node.getStartOffset()); boolean addIndent = !(path.size() > 1 && (path.get(1) instanceof Assignment)); + + // anonymous classes + if (options.wrapMethodCallArgs != CodeStyle.WrapStyle.WRAP_ALWAYS) { + FunctionInvocation method = node.getMethod(); + List parameters = method.getParameters(); + for (Expression parameter : parameters) { + if (isAnonymousClass(parameter)) { + addIndent = false; + break; + } + } + } + if (addIndent) { formatTokens.add(new FormatToken.IndentToken(ts.offset() + ts.token().length(), options.continualIndentSize)); } @@ -1350,11 +1417,18 @@ && ((ts.offset() + ts.token().length()) <= node.getEndOffset())) { addFormatToken(formatTokens); } + + boolean addIndent = !isAnonymousClass(node.getExpression()); + if (ts.token().id() == PHPTokenId.PHP_RETURN) { addFormatToken(formatTokens); - formatTokens.add(new FormatToken.IndentToken(ts.offset(), options.continualIndentSize)); + if (addIndent) { + formatTokens.add(new FormatToken.IndentToken(ts.offset(), options.continualIndentSize)); + } super.visit(node); - formatTokens.add(new FormatToken.IndentToken(ts.offset(), -1 * options.continualIndentSize)); + if (addIndent) { + formatTokens.add(new FormatToken.IndentToken(ts.offset(), -1 * options.continualIndentSize)); + } } } @@ -1662,8 +1736,12 @@ case PHP_TOKEN: text = ts.token().text().toString(); ASTNode parent = path.get(0); - if ("(".equals(text)) { - if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { + if ("(".equals(text)) { // NOI18N + if (isAnonymousClass(parent)) { + tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_ANONYMOUS_CLASS_PAREN, ts.offset())); + tokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString())); + tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS, ts.offset() + ts.token().length())); + } else if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_METHOD_DEC_PAREN, ts.offset())); tokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString())); tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_WITHIN_METHOD_DECL_PARENS, ts.offset() + ts.token().length())); @@ -1698,8 +1776,11 @@ } else { tokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString())); } - } else if (")".equals(text)) { - if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { + } else if (")".equals(text)) { // NOI18N + if (isAnonymousClass(parent)) { + tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS, ts.offset())); + tokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString())); + } else if (parent instanceof FunctionDeclaration || parent instanceof MethodDeclaration) { tokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_WITHIN_METHOD_DECL_PARENS, ts.offset())); tokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString())); } else if (parent instanceof FunctionInvocation || parent instanceof MethodInvocation || parent instanceof ClassInstanceCreation) { @@ -2239,4 +2320,8 @@ } return index == text.length(); } + + private static boolean isAnonymousClass(ASTNode astNode) { + return astNode instanceof ClassInstanceCreation && ((ClassInstanceCreation) astNode).isAnonymous(); + } } diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java b/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java @@ -92,6 +92,7 @@ public int tabSize; public boolean expandTabsToSpaces; public CodeStyle.BracePlacement classDeclBracePlacement; + public CodeStyle.BracePlacement anonymousClassBracePlacement; public CodeStyle.BracePlacement methodDeclBracePlacement; public CodeStyle.BracePlacement ifBracePlacement; public CodeStyle.BracePlacement forBracePlacement; @@ -112,6 +113,7 @@ public boolean spaceBeforeCatchLeftBrace; public boolean spaceBeforeFinallyLeftBrace; public boolean spaceBeforeUseTraitBodyLeftBrace; + public boolean spaceBeforeAnonymousClassParen; public boolean spaceBeforeMethodDeclParen; public boolean spaceBeforeMethodCallParen; public boolean spaceBeforeIfParen; @@ -132,6 +134,7 @@ public boolean spaceAroundAssignOps; public boolean spaceAroundKeyValueOps; public boolean spaceWithinArrayDeclParens; + public boolean spaceWithinAnonymousClassParens; public boolean spaceWithinMethodDeclParens; public boolean spaceWithinMethodCallParens; public boolean spaceWithinIfParens; @@ -220,6 +223,7 @@ expandTabsToSpaces = codeStyle.expandTabToSpaces(); classDeclBracePlacement = codeStyle.getClassDeclBracePlacement(); + anonymousClassBracePlacement = codeStyle.getAnonymousClassBracePlacement(); methodDeclBracePlacement = codeStyle.getMethodDeclBracePlacement(); ifBracePlacement = codeStyle.getIfBracePlacement(); forBracePlacement = codeStyle.getForBracePlacement(); @@ -242,6 +246,7 @@ spaceBeforeFinallyLeftBrace = codeStyle.spaceBeforeFinallyLeftBrace(); spaceBeforeUseTraitBodyLeftBrace = codeStyle.spaceBeforeUseTraitBodyLeftBrace(); + spaceBeforeAnonymousClassParen = codeStyle.spaceBeforeAnonymousClassParen(); spaceBeforeMethodDeclParen = codeStyle.spaceBeforeMethodDeclParen(); spaceBeforeMethodCallParen = codeStyle.spaceBeforeMethodCallParen(); spaceBeforeIfParen = codeStyle.spaceBeforeIfParen(); @@ -265,6 +270,7 @@ spaceAroundKeyValueOps = codeStyle.spaceAroundKeyValueOps(); spaceWithinArrayDeclParens = codeStyle.spaceWithinArrayDeclParens(); + spaceWithinAnonymousClassParens = codeStyle.spaceWithinAnonymousClassParens(); spaceWithinMethodDeclParens = codeStyle.spaceWithinMethodDeclParens(); spaceWithinMethodCallParens = codeStyle.spaceWithinMethodCallParens(); spaceWithinIfParens = codeStyle.spaceWithinIfParens(); @@ -462,6 +468,16 @@ newLines = ws.lines; countSpaces = ws.spaces; break; + case WHITESPACE_BEFORE_ANONYMOUS_CLASS_LEFT_BRACE: + indentRule = true; + ws = countWhiteSpaceBeforeLeftBrace(docOptions.anonymousClassBracePlacement, + docOptions.spaceBeforeClassDeclLeftBrace, // use the same option as class decl + oldText, + indent, + peekLastBracedIndent(lastBracedBlockIndent)); + newLines = ws.lines; + countSpaces = ws.spaces; + break; case WHITESPACE_BEFORE_FUNCTION_LEFT_BRACE: indentRule = true; ws = countWhiteSpaceBeforeLeftBrace( @@ -621,6 +637,11 @@ newLines = docOptions.blankLinesAfterClassHeader + 1 > newLines ? docOptions.blankLinesAfterClassHeader + 1 : newLines; countSpaces = indent; break; + case WHITESPACE_AFTER_ANONYMOUS_CLASS_LEFT_BRACE: + indentRule = true; + newLines = docOptions.blankLinesAfterClassHeader + 1; + countSpaces = indent; + break; case WHITESPACE_AFTER_CLASS: indentRule = true; // If there is some another visible token after this one, add an extra line, @@ -631,6 +652,11 @@ newLines = docOptions.blankLinesAfterClass + extraLines > newLines ? docOptions.blankLinesAfterClass + extraLines : newLines; countSpaces = indent; break; + case WHITESPACE_AFTER_ANONYMOUS_CLASS: + indentRule = true; + newLines = 0; + countSpaces = 0; + break; case WHITESPACE_BEFORE_CLASS_RIGHT_BRACE: indentRule = true; ws = countWhiteSpaceBeforeRightBrace( @@ -646,6 +672,19 @@ countSpaces = ws.spaces; lastBracePlacement = docOptions.classDeclBracePlacement; break; + case WHITESPACE_BEFORE_ANONYMOUS_CLASS_RIGHT_BRACE: + indentRule = true; + if (docOptions.anonymousClassBracePlacement == CodeStyle.BracePlacement.PRESERVE_EXISTING) { + ws = countWhiteSpaceForPreserveExistingBracePlacement(oldText, popLastBracedIndent(lastBracedBlockIndent)); + } else { + int lines = docOptions.blankLinesBeforeClassEnd + 1; + int spaces = docOptions.anonymousClassBracePlacement == CodeStyle.BracePlacement.NEW_LINE_INDENTED ? indent + docOptions.indentSize : indent; + ws = new Whitespace(lines, spaces); + } + newLines = ws.lines; + countSpaces = ws.spaces; + lastBracePlacement = docOptions.anonymousClassBracePlacement; + break; case WHITESPACE_BEFORE_FUNCTION: indentRule = true; newLines = docOptions.blankLinesBeforeFunction + 1 > newLines ? docOptions.blankLinesBeforeFunction + 1 : newLines; @@ -1056,6 +1095,9 @@ } countSpaces = countSpaces + (docOptions.spaceAroundKeyValueOps ? 1 : 0); break; + case WHITESPACE_BEFORE_ANONYMOUS_CLASS_PAREN: + countSpaces = docOptions.spaceBeforeAnonymousClassParen ? 1 : 0; + break; case WHITESPACE_BEFORE_METHOD_DEC_PAREN: countSpaces = docOptions.spaceBeforeMethodDeclParen ? 1 : 0; break; @@ -1136,8 +1178,21 @@ case WHITESPACE_BEFORE_ARRAY_DECL_RIGHT_PAREN: countSpaces = countSpacesForArrayDeclParens(index, indent, formatTokens); break; + case WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS: + int helpIndex = index - 1; + while (helpIndex > 0 + && formatTokens.get(helpIndex).getId() != FormatToken.Kind.WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS + && (formatTokens.get(helpIndex).getId() == FormatToken.Kind.WHITESPACE)) { + helpIndex--; + } + if (helpIndex > 0 && formatTokens.get(helpIndex).getId() == FormatToken.Kind.WHITESPACE_WITHIN_ANONYMOUS_CLASS_PARENS) { + countSpaces = 0; + } else { + countSpaces = docOptions.spaceWithinAnonymousClassParens ? 1 : 0; + } + break; case WHITESPACE_WITHIN_METHOD_DECL_PARENS: - int helpIndex = index - 1; + helpIndex = index - 1; while (helpIndex > 0 && formatTokens.get(helpIndex).getId() != FormatToken.Kind.WHITESPACE_WITHIN_METHOD_DECL_PARENS && (formatTokens.get(helpIndex).getId() == FormatToken.Kind.WHITESPACE /* diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Braces.php b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Braces.php --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Braces.php +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Braces.php @@ -18,6 +18,12 @@ } } +$anonymous = new class extends AnonymousExample { + public function main() { + return "anonymous"; + } +}; + function getFruit() { return "Apple"; } diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Bundle.properties @@ -86,6 +86,7 @@ LBL_spaceBeforeFinally="finally" LBL_BeforeParentheses=Before Parentheses +LBL_spaceBeforeAnonymousClassParen=Anonymous Class LBL_spaceBeforeMethodDeclParen=Method / Function Declaration LBL_spaceBeforeMethodCallParen=Method / Function Call LBL_spaceBeforeIfParen="if", "elseif" @@ -125,6 +126,7 @@ LBL_WithinParentheses=Within Parentheses LBL_spaceWithinParens=Parentheses +LBL_spaceWithinAnonymousClassParens=Anonymous Class LBL_spaceWithinMethodDeclParens=Method / Function Declaration LBL_spaceWithinMethodCallParens=Method / Function Call LBL_spaceWithinIfParens="if" @@ -436,3 +438,4 @@ FmtWrapping.panel1.AccessibleContext.accessibleDescription=wrapping options panel FmtWrapping.wrapAfterAssignOpsCheckBox.text_1=Wrap After Assignment Operators FmtAlignment.nlFinallyCheckBox.text="fina&lly" +FmtBraces.anonymousClassLabel.text=&Anonymous Class: diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.form b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.form --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.form +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.form @@ -77,6 +77,11 @@ + + + + + @@ -97,7 +102,12 @@ - + + + + + + @@ -137,7 +147,7 @@ - + @@ -202,6 +212,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.java b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtBraces.java @@ -64,6 +64,7 @@ public FmtBraces() { initComponents(); classDeclCombo.putClientProperty(OPTION_ID, CLASS_DECL_BRACE_PLACEMENT); + anonymousClassCombo.putClientProperty(OPTION_ID, ANONYMOUS_CLASS_BRACE_PLACEMENT); methodDeclCombo.putClientProperty(OPTION_ID, METHOD_DECL_BRACE_PLACEMENT); ifCombo.putClientProperty(OPTION_ID, IF_BRACE_PLACEMENT); forCombo.putClientProperty(OPTION_ID, FOR_BRACE_PLACEMENT); @@ -96,6 +97,8 @@ bracesPlacementLabel = new javax.swing.JLabel(); classDeclLabel = new javax.swing.JLabel(); classDeclCombo = new javax.swing.JComboBox(); + anonymousClassLabel = new javax.swing.JLabel(); + anonymousClassCombo = new javax.swing.JComboBox<>(); methodDeclLabel = new javax.swing.JLabel(); methodDeclCombo = new javax.swing.JComboBox(); otherLabel = new javax.swing.JLabel(); @@ -130,6 +133,10 @@ } }); + org.openide.awt.Mnemonics.setLocalizedText(anonymousClassLabel, org.openide.util.NbBundle.getMessage(FmtBraces.class, "FmtBraces.anonymousClassLabel.text")); // NOI18N + + anonymousClassCombo.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + methodDeclLabel.setLabelFor(methodDeclCombo); org.openide.awt.Mnemonics.setLocalizedText(methodDeclLabel, org.openide.util.NbBundle.getMessage(FmtBraces.class, "LBL_bp_MethodDecl")); // NOI18N @@ -221,7 +228,11 @@ .addGroup(layout.createSequentialGroup() .addComponent(classDeclLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(classDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addComponent(classDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(anonymousClassLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(anonymousClassCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap()) ); @@ -238,7 +249,11 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(classDeclLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(classDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(6, 6, 6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(anonymousClassLabel) + .addComponent(anonymousClassCombo, 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(methodDeclLabel) .addComponent(methodDeclCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -270,7 +285,7 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(otherCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(otherLabel)) - .addContainerGap(18, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); bracesPlacementLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FmtBraces.class, "FmtBraces.bracesPlacementLabel.AccessibleContext.accessibleName")); // NOI18N @@ -328,6 +343,8 @@ // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox anonymousClassCombo; + private javax.swing.JLabel anonymousClassLabel; private javax.swing.JLabel bracesPlacementLabel; private javax.swing.JComboBox catchCombo; private javax.swing.JLabel catchLabel; diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtSpaces.java b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtSpaces.java --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtSpaces.java +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/FmtSpaces.java @@ -267,6 +267,7 @@ new Item(SPACE_BEFORE_FINALLY)), new Item("BeforeParentheses", // NOI18N + new Item(SPACE_BEFORE_ANONYMOUS_CLASS_PAREN), new Item(SPACE_BEFORE_METHOD_DECL_PAREN), new Item(SPACE_BEFORE_METHOD_CALL_PAREN), new Item(SPACE_BEFORE_IF_PAREN), @@ -302,6 +303,7 @@ ), new Item("WithinParentheses", // NOI18N + new Item(SPACE_WITHIN_ANONYMOUS_CLASS_PARENS), new Item(SPACE_WITHIN_METHOD_DECL_PARENS), new Item(SPACE_WITHIN_METHOD_CALL_PARENS), new Item(SPACE_WITHIN_IF_PARENS), diff --git a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php --- a/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php +++ b/php.editor/src/org/netbeans/modules/php/editor/indent/ui/Spaces.php @@ -57,5 +57,16 @@ } } + +public function anonymousClassExample($arg) { + $instance = new class ($arg) extends Anonymous { + public function __construct($arg) { + } + public function anon() { + echo "anonymous"; + } + }; + return $instance; +} } ?> diff --git a/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php b/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php @@ -0,0 +1,24 @@ +i = $i; + } +}); + +(new class extends BaseClass { +public function main() { +} +})->main(); + +class MyClass extends BaseClass { + private function getInstance() { +return new class() extends MyClass implements MyInterface { + public function test() { + } + }; + } +} + +$anonClass = new class { +use Foo; +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php.formatted b/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/anonymousClass.php.formatted @@ -0,0 +1,33 @@ +i = $i; + } +}); + +(new class extends BaseClass { + + public function main() { + + } +})->main(); + +class MyClass extends BaseClass { + + private function getInstance() { + return new class() extends MyClass implements MyInterface { + + public function test() { + + } + }; + } + +} + +$anonClass = new class { + + use Foo; +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/anonymousClassBP_01.php b/php.editor/test/unit/data/testfiles/formatting/anonymousClassBP_01.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/anonymousClassBP_01.php @@ -0,0 +1,5 @@ +var; + } +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass02.php.formatted b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass02.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass02.php.formatted @@ -0,0 +1,15 @@ +var; + } +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php @@ -0,0 +1,59 @@ + $b) { + echo "a is bigger than b"; + } elseif ($a == $b) { + echo $a." is equal to ".$b; + } else { + echo $this->property; + } + } + +public function forExample() { + for ($i = 1; $i <= 10; $i++) { + echo $i; +} +} + +public function foreachEample() { +$arr = array(1, 2, 3, 4); +foreach ($arr as &$value) { + $value = $value * 2; +} +} + +public function whileExample() { +$i = 1; + while ($i <= 10) { + echo $i++; + } +} + +public function doWhileExample($i) { +do { + echo $i--; +} while ($i > 0); +} + +public function switchExample() { +switch ($i) { + case 0: + echo "i equals 0"; + break; + case 1: + echo "i equals 1"; + break; +} +} +public function tryExample() { + try { + echo inverse(5) . "\n"; +} catch (Exception $e) { + echo 'Caught exception: '. $e->getMessage(). "\n"; +} + +} +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php.formatted b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/AnonymousClass03.php.formatted @@ -0,0 +1,67 @@ + $b) { + echo "a is bigger than b"; + } elseif ($a == $b) { + echo $a . " is equal to " . $b; + } else { + echo $this->property; + } + } + + public function forExample() + { + for ($i = 1; $i <= 10; $i++) { + echo $i; + } + } + + public function foreachEample() + { + $arr = array(1, 2, 3, 4); + foreach ($arr as &$value) { + $value = $value * 2; + } + } + + public function whileExample() + { + $i = 1; + while ($i <= 10) { + echo $i++; + } + } + + public function doWhileExample($i) + { + do { + echo $i--; + } while ($i > 0); + } + + public function switchExample() + { + switch ($i) { + case 0: + echo "i equals 0"; + break; + case 1: + echo "i equals 1"; + break; + } + } + + public function tryExample() + { + try { + echo inverse(5) . "\n"; + } catch (Exception $e) { + echo 'Caught exception: ' . $e->getMessage() . "\n"; + } + } +}; diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php @@ -0,0 +1,9 @@ +var; +} +}); diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php.formatted b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass01.php.formatted @@ -0,0 +1,12 @@ +var; + } +}); diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php @@ -0,0 +1,25 @@ +var; +} +}; +?> diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php.formatted b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass02.php.formatted @@ -0,0 +1,16 @@ +var; + } +}; +?> diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass03.php b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass03.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass03.php @@ -0,0 +1,8 @@ +name = $iName; +$this->price = $iPrice; +$this->qty = $iQty; +$this->calculate(); +} +protected function calculate() { +$this->price = number_format($this->price, 2); +$this->total = number_format(($this->price * $this->qty), 2); +} +public function __toString() { +return "You ordered ($this->qty) '$this->name'" . ($this->qty == 1 ? "" : "s") . +" at \$$this->price, for a total of: \$$this->total."; +} +}; +echo (new Item("Widget 22", 4.90, 2)); diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass04.php.formatted b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass04.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass04.php.formatted @@ -0,0 +1,24 @@ +name = $iName; + $this->price = $iPrice; + $this->qty = $iQty; + $this->calculate(); + } + + protected function calculate() { + $this->price = number_format($this->price, 2); + $this->total = number_format(($this->price * $this->qty), 2); + } + + public function __toString() { + return "You ordered ($this->qty) '$this->name'" . ($this->qty == 1 ? "" : "s") . + " at \$$this->price, for a total of: \$$this->total."; + } +}; +echo (new Item("Widget 22", 4.90, 2)); diff --git a/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass05.php b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass05.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/blankLines/SimpleAnonymousClass05.php @@ -0,0 +1,5 @@ +test(new class { +public function foo() { +} +} +); + +$test->test( +new class { +public function foo() { +} +} +); + +$test->test($arg1, +new class { +public function foo() { +} +} +); + +$test->test( +$arg1, +new class { +public function foo() { +} +} +); diff --git a/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass01.php.formatted b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass01.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass01.php.formatted @@ -0,0 +1,74 @@ +test(new class { + + public function foo() { + + } + } +); + +$test->test( + new class { + + public function foo() { + + } + } +); + +$test->test($arg1, + new class { + + public function foo() { + + } + } +); + +$test->test( + $arg1, + new class { + + public function foo() { + + } + } +); diff --git a/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php @@ -0,0 +1,49 @@ +test(new class { +public function foo() { +} +}); + +$test->test( +new class { +public function foo() { +} +}); + +$test->test($arg1, +new class { +public function foo() { +} +}); + +$test->test( +$arg1, +new class { +public function foo() { +} +}); diff --git a/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php.formatted b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php.formatted new file mode 100644 --- /dev/null +++ b/php.editor/test/unit/data/testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php.formatted @@ -0,0 +1,62 @@ +test(new class { + + public function foo() { + + } +}); + +$test->test( +new class { + + public function foo() { + + } +}); + +$test->test($arg1, new class { + + public function foo() { + + } +}); + +$test->test( +$arg1, new class { + + public function foo() { + + } +}); diff --git a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java --- a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java +++ b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBlankLinesTest.java @@ -186,6 +186,12 @@ reformatFileContents("testfiles/formatting/blankLines/Trait01.php", options); } + public void testBLAnonymousClass01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + reformatFileContents("testfiles/formatting/blankLines/AnonymousClass01.php", options); + } + public void testBLClass02() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); options.put(FmtOptions.INITIAL_INDENT, 0); @@ -206,6 +212,16 @@ reformatFileContents("testfiles/formatting/blankLines/Trait02.php", options); } + public void testBLAnonymousClass02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.PRESERVE_EXISTING); + options.put(FmtOptions.METHOD_DECL_BRACE_PLACEMENT, CodeStyle.BracePlacement.PRESERVE_EXISTING); + options.put(FmtOptions.OTHER_BRACE_PLACEMENT, CodeStyle.BracePlacement.PRESERVE_EXISTING); + options.put(FmtOptions.SPACE_BEFORE_CLASS_DECL_LEFT_BRACE, false); + reformatFileContents("testfiles/formatting/blankLines/AnonymousClass02.php", options); + } + public void testBLClass03() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); options.put(FmtOptions.INITIAL_INDENT, 0); @@ -226,6 +242,17 @@ reformatFileContents("testfiles/formatting/blankLines/Trait03.php", options); } + public void testBLAnonymousClass03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE); + options.put(FmtOptions.METHOD_DECL_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE); + options.put(FmtOptions.OTHER_BRACE_PLACEMENT, CodeStyle.BracePlacement.SAME_LINE); + options.put(FmtOptions.SPACE_BEFORE_CLASS_DECL_LEFT_BRACE, false); + reformatFileContents("testfiles/formatting/blankLines/AnonymousClass03.php", options); + } + + public void testBLFields01() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); options.put(FmtOptions.SPACE_BEFORE_CLASS_DECL_LEFT_BRACE, true); @@ -744,6 +771,213 @@ reformatFileContents("testfiles/formatting/blankLines/SimpleTrait17.php", options); } + public void testBLSimpleAnonymousClass01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass01.php", options); + } + + public void testBLSimpleAnonymousClass02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass02.php", options); + } + + public void testBLSimpleAnonymousClass03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass03.php", options); + } + + public void testBLSimpleAnonymousClass04() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass04.php", options); + } + + public void testBLSimpleAnonymousClass05() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 1); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass05.php", options); + } + + public void testBLSimpleAnonymousClass06() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass06.php", options); + } + + public void testBLSimpleAnonymousClass07() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 1); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass07.php", options); + } + + public void testBLSimpleAnonymousClass08() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 1); // ignore + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass08.php", options); + } + + public void testBLSimpleAnonymousClass09() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass09.php", options); + } + + public void testBLSimpleAnonymousClass10() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 1); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass10.php", options); + } + + public void testBLSimpleAnonymousClass11() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 1); // before class end is used + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass11.php", options); + } + + public void testBLSimpleAnonymousClass12() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS_HEADER, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_CLASS_END, 1); + options.put(FmtOptions.BLANK_LINES_AFTER_CLASS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FUNCTION_END, 1); + options.put(FmtOptions.BLANK_LINES_AFTER_FUNCTION, 1); + options.put(FmtOptions.BLANK_LINES_BEFORE_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_FIELDS, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_NAMESPACE, 0); + options.put(FmtOptions.BLANK_LINES_BEFORE_USE, 0); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 0); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass12.php", options); + } + + public void testBLSimpleAnonymousClass13() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass13.php", options); + } + + public void testBLSimpleAnonymousClass14() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass14.php", options); + } + + public void testBLSimpleAnonymousClass15() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass15.php", options); + } + + public void testBLSimpleAnonymousClass16() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 0); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE_INDENTED); + options.put(FmtOptions.METHOD_DECL_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE_INDENTED); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass16.php", options); + } + + public void testBLSimpleAnonymousClass17() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.INITIAL_INDENT, 4); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE_INDENTED); + options.put(FmtOptions.METHOD_DECL_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE_INDENTED); + reformatFileContents("testfiles/formatting/blankLines/SimpleAnonymousClass17.php", options); + } + public void testBLSimpleUse01() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); options.put(FmtOptions.INITIAL_INDENT, 0); diff --git a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java --- a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java +++ b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java @@ -1097,4 +1097,37 @@ reformatFileContents("testfiles/formatting/spaces/spaceAroundReturnType12.php", options); } + public void testSpacesBeforeAnonymousClassParen01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/spaces/spaceBeforeAnonymousClassParen01.php", options); + } + + public void testSpacesBeforeAnonymousClassParen02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.SPACE_BEFORE_ANONYMOUS_CLASS_PAREN, true); + reformatFileContents("testfiles/formatting/spaces/spaceBeforeAnonymousClassParen02.php", options); + } + + public void testSpacesWithinAnonymousClassParen01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/spaces/spaceWithinAnonymousClassParen01.php", options); + } + + public void testSpacesWithinAnonymousClassParen02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.SPACE_WITHIN_ANONYMOUS_CLASS_PARENS, true); + reformatFileContents("testfiles/formatting/spaces/spaceWithinAnonymousClassParen02.php", options); + } + + public void testSpacesWithinAnonymousClassParen03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/spaces/spaceWithinAnonymousClassParen03.php", options); + } + + public void testSpacesWithinAnonymousClassParen04() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.SPACE_WITHIN_ANONYMOUS_CLASS_PARENS, true); + reformatFileContents("testfiles/formatting/spaces/spaceWithinAnonymousClassParen04.php", options); + } + } diff --git a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java --- a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java +++ b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java @@ -671,4 +671,33 @@ HashMap options = new HashMap<>(FmtOptions.getDefaults()); reformatFileContents("testfiles/formatting/issue247047.php", options); } + + public void testAnonymousClass() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/anonymousClass.php", options); + } + + public void testAnonymousClassBracePlacement_01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE); + reformatFileContents("testfiles/formatting/anonymousClassBP_01.php", options); + } + + public void testAnonymousClassBracePlacement_02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.PRESERVE_EXISTING); + reformatFileContents("testfiles/formatting/anonymousClassBP_02.php", options); + } + + public void testAnonymousClassBracePlacement_03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.SAME_LINE); + reformatFileContents("testfiles/formatting/anonymousClassBP_03.php", options); + } + + public void testAnonymousClassBracePlacement_04() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.ANONYMOUS_CLASS_BRACE_PLACEMENT, CodeStyle.BracePlacement.NEW_LINE_INDENTED); + reformatFileContents("testfiles/formatting/anonymousClassBP_04.php", options); + } } diff --git a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterWrappingTest.java b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterWrappingTest.java --- a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterWrappingTest.java +++ b/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterWrappingTest.java @@ -78,6 +78,18 @@ reformatFileContents("testfiles/formatting/wrapping/methodCallArg05.php", options); } + public void testWrapMethodCallArgWithAnonymousClass01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.WRAP_METHOD_CALL_ARGS, CodeStyle.WrapStyle.WRAP_ALWAYS); + reformatFileContents("testfiles/formatting/wrapping/methodCallArgWithAnonymousClass01.php", options); + } + + public void testWrapMethodCallArgWithAnonymousClass02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.WRAP_METHOD_CALL_ARGS, CodeStyle.WrapStyle.WRAP_NEVER); + reformatFileContents("testfiles/formatting/wrapping/methodCallArgWithAnonymousClass02.php", options); + } + public void testWrapMethodParams01() throws Exception { HashMap options = new HashMap(FmtOptions.getDefaults()); options.put(FmtOptions.WRAP_METHOD_PARAMS, CodeStyle.WrapStyle.WRAP_ALWAYS);