├── .gitignore ├── AUTHORS ├── LICENSE ├── README.md ├── build.xml ├── buildScripts ├── ivy-repo │ ├── com.github.parboiled.custom-parboiled-0.9.7.2.xml │ ├── com.zwitserloot-cmdreader-1.2.xml │ ├── junit-ivy-4.8.1.xml │ ├── net.java.openjdk.custom-javac6-1.6.0.18.xml │ └── projectlombok.org-jsch-ant-fixed-0.1.42.xml ├── ivy.xml └── ivysettings.xml ├── doc ├── .gitignore └── maven-pom.xml ├── src ├── ecjTransformer │ └── lombok │ │ └── ast │ │ └── ecj │ │ ├── EcjTreeBuilder.java │ │ ├── EcjTreeConverter.java │ │ ├── EcjTreeOperations.java │ │ ├── EcjTreePrinter.java │ │ ├── EcjTreeVisitor.java │ │ └── GenerateEcjTreeVisitorCode.java ├── javacTransformer │ └── lombok │ │ └── ast │ │ └── javac │ │ ├── JcTreeBuilder.java │ │ ├── JcTreeConverter.java │ │ └── JcTreePrinter.java ├── main │ └── lombok │ │ └── ast │ │ ├── AbstractNode.java │ │ ├── AnnotationValue.java │ │ ├── Ast.java │ │ ├── AstException.java │ │ ├── AstVisitor.java │ │ ├── BinaryOperator.java │ │ ├── ConversionPositionInfo.java │ │ ├── DanglingNodes.java │ │ ├── DescribedNode.java │ │ ├── Expression.java │ │ ├── FloatingPointLiteral.java │ │ ├── ForwardingAstVisitor.java │ │ ├── FunctionalExpression.java │ │ ├── IntegralLiteral.java │ │ ├── JavadocContainer.java │ │ ├── ListAccessor.java │ │ ├── Literal.java │ │ ├── LiteralType.java │ │ ├── Message.java │ │ ├── MessageKey.java │ │ ├── Node.java │ │ ├── NullLiteral.java │ │ ├── Position.java │ │ ├── PositionFactory.java │ │ ├── RawListAccessor.java │ │ ├── ResolutionException.java │ │ ├── Statement.java │ │ ├── StrictListAccessor.java │ │ ├── Template.java │ │ ├── Templates.java │ │ ├── TypeBody.java │ │ ├── TypeDeclaration.java │ │ ├── TypeMember.java │ │ ├── UnaryOperator.java │ │ ├── Version.java │ │ ├── WildcardKind.java │ │ ├── app │ │ ├── EcjBugsNormalization.java │ │ └── Main.java │ │ ├── grammar │ │ ├── BasicsActions.java │ │ ├── BasicsParser.java │ │ ├── ExpressionsActions.java │ │ ├── ExpressionsParser.java │ │ ├── LiteralsActions.java │ │ ├── LiteralsParser.java │ │ ├── ParseProblem.java │ │ ├── ParserGroup.java │ │ ├── ProfilerParseRunner.java │ │ ├── Source.java │ │ ├── SourceActions.java │ │ ├── SourceStructure.java │ │ ├── StatementsActions.java │ │ ├── StatementsParser.java │ │ ├── StructuresActions.java │ │ ├── StructuresParser.java │ │ ├── TemporaryNodes.java │ │ ├── TypesActions.java │ │ └── TypesParser.java │ │ ├── resolve │ │ ├── AnnotationClassNotAvailableException.java │ │ ├── AnnotationProxy.java │ │ └── Resolver.java │ │ └── syntaxChecks │ │ ├── BasicChecks.java │ │ ├── KeywordChecks.java │ │ ├── LiteralValidityChecks.java │ │ ├── MessageKey.java │ │ ├── StatementChecks.java │ │ ├── StructuralChecks.java │ │ ├── SyntacticValidityVisitorBase.java │ │ ├── TypeChecks.java │ │ └── UnreachableStatementsChecks.java ├── printer │ └── lombok │ │ └── ast │ │ └── printer │ │ ├── HtmlFormatter.java │ │ ├── SourceFormatter.java │ │ ├── SourcePrinter.java │ │ ├── StructureFormatter.java │ │ ├── TextFormatter.java │ │ └── web │ │ ├── ast.css │ │ ├── ast.html │ │ ├── ast.js │ │ └── jquery.js └── template │ └── lombok │ └── ast │ └── template │ ├── CopyMethod.java │ ├── ForcedType.java │ ├── GenerateAstNode.java │ ├── Mandatory.java │ ├── NotChildOfNode.java │ ├── ParentAccessor.java │ ├── SyntaxCheck.java │ ├── SyntaxValidityCheckerGenerator.java │ ├── TemplateProcessor.java │ └── package-info.java └── test ├── .gitignore ├── resources ├── alias │ ├── A001_PackageAndImports.java │ ├── A002_BasicEmptyClass.1.java │ ├── A002_BasicEmptyClass.2.java │ ├── A002_BasicEmptyClass.3.java │ ├── A003_Initializers.1.java │ ├── A003_Initializers.2.java │ ├── B001_PrimitiveTypes.java │ ├── B002_SimpleTypes.java │ ├── B003_ParameterizedTypes.java │ ├── B004_TypeVariables.java │ ├── B005_ArrayTypes.java │ ├── C003_SimpleExpressions.java │ ├── C004_ComplexExpressions.java │ ├── E001_MethodDeclarations.java │ ├── E007_ArrayMethodDeclarations.java │ ├── F001_Annotations.java │ ├── H003_Annotations.java │ └── ZComplex1.java ├── idempotency │ ├── A001_PackageAndImports.java │ ├── A002_BasicEmptyClass.java │ ├── A003_EmptyStatements.java │ ├── A003_Initializers.java │ ├── A004_MultipleClasses.java │ ├── B001_PrimitiveTypes.java │ ├── B002_SimpleTypes.java │ ├── B003_ParameterizedTypes.java │ ├── B004_TypeVariables.java │ ├── B005_ArrayTypes.java │ ├── C001_NumberLiterals.java │ ├── C002_ExtremeIntegralLiterals.java │ ├── C002_Parentheses.java │ ├── C002_TextLiterals.java │ ├── C003_Casts.java │ ├── C003_SimpleExpressions.java │ ├── C003_StringConcatExpressions.java │ ├── C004_ComplexExpressions.java │ ├── C005_ArrayInitialization.java │ ├── C006_Parens.java │ ├── C007_ThisLiteral.java │ ├── C008_ClassLiterals.java │ ├── C009_ArrayAccess.java │ ├── C010_CombinedBinaryExpressions.java │ ├── D001_BasicStatements.java │ ├── D001_VariableDeclarations.java │ ├── D001_VariableDeclarationsEclipseHasBugs.java │ ├── D002_Assert.java │ ├── D002_AssertInner.java │ ├── D002_Do.java │ ├── D002_ForEach.java │ ├── D002_If.java │ ├── D002_Label.java │ ├── D002_StandardFor.java │ ├── D002_Switch.java │ ├── D002_Synchronized.java │ ├── D002_Try.java │ ├── D002_While.java │ ├── D003_LabelledBreaksAndContinues.java │ ├── E001_ConstructorDeclarations.java │ ├── E001_MethodDeclarations.java │ ├── E002_ModifiersConstructorDeclarations.java │ ├── E002_ModifiersMethodDeclaration.java │ ├── E003_ThrowsConstructorDeclarations.java │ ├── E003_ThrowsMethodDeclaration.java │ ├── E004_ParameterConstructorDeclarations.java │ ├── E004_ParameterMethodDeclarations.java │ ├── E005_TypeParametersConstructorDeclaration.java │ ├── E005_TypeParametersMethodDeclaration.java │ ├── E006_TypeParametersOnGenericTypesMethodDeclaration.java │ ├── E007_ArrayMethodDeclarations.java │ ├── F001_Annotations.java │ ├── G001_SimpleFieldDeclarations.java │ ├── G002_InitializedFieldDeclarations.java │ ├── G002_ModifiersFieldDeclarations.java │ ├── G003_MultipleFieldDeclarations.java │ ├── G004_AnonymousInnerClasses.java │ ├── H001_Interfaces.java │ ├── H002_Enums.java │ ├── H003_Annotations.java │ ├── H004_MultiGenerics.java │ ├── H005_SimpleConstructors.java │ ├── H006_ComplexConstructors.java │ ├── H007_SuperAndThisQualifier.java │ ├── H008_SimpleMethods.java │ ├── H009_ComplexMethods.java │ ├── H010_Javadoc.java │ ├── I001_AnnotationsAndTypeParametersMethodDeclaration.java │ ├── I001_ComplexAsserts1.java │ ├── I001_Deprecated.java │ ├── I002_ComplexAsserts2.java │ ├── I002_ConditionalExpressions.java │ ├── J001_ExplicitDeclarations.java │ ├── ZComplex1.java │ └── package-info.java ├── parseErrors │ ├── Bad1.java │ └── ConditionalExpressionsPrecedence.java ├── performance │ ├── LongIdentifier.java │ ├── LongString.java │ ├── ZLongComment.java │ └── extra166y │ │ ├── AbstractParallelAnyArray.java │ │ └── PAS.java └── special │ ├── AbstractMethodAndComment.java │ ├── AnnotationsWithComments.java │ ├── BackslashU.java │ ├── CastPlusUnary.java │ ├── ChainedMethodsWithSuper.java │ ├── ExtensiveJavadoc.java │ ├── LesserThanPlusComma.java │ ├── ManyCommentsEclipseHasBugs.java │ ├── ParenthesizedCast.java │ └── PassthroughAssignmentInInlineIf.java └── src └── lombok └── ast ├── ListAccessorTest.java ├── TemplateTest.java ├── grammar ├── AliasTest.java ├── AlternativeStringConcatEcjTreeBuilderTest.java ├── AlternativeStringConcatEcjTreeConverterType2Test.java ├── ContentBasedJavaFileObject.java ├── EcjCompilerTest.java ├── EcjTreeBuilderTest.java ├── EcjTreeConverterType1Test.java ├── EcjTreeConverterType2Test.java ├── IdempotencyTest.java ├── IntegralLiteralTest.java ├── JavaCompilerTest.java ├── JcTreeBuilderTest.java ├── JcTreeConverterType1Test.java ├── JcTreeConverterType2Test.java ├── ParboiledJavaGrammar.java ├── PerformanceTest.java ├── PositionCheckingFormatter.java ├── PositionTest.java ├── RunForEachFileInDirRunner.java ├── SyntaxCheckClearsOnIdempotencyTest.java └── TreeBuilderRunner.java └── resolve └── TypesMatchTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings 2 | /.project 3 | /.classpath 4 | /.factorypath 5 | /bin 6 | /build 7 | /dist 8 | /report 9 | /lib 10 | .apt_generated 11 | *.class 12 | /cobertura.ser 13 | /ivyCache 14 | escudo-upload.key 15 | /.idea 16 | /lombok.ast.iml 17 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Lombok AST contributors: 2 | 3 | Robbert Jan Grootjans 4 | Roel Spilker 5 | Sander Koning 6 | 7 | By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010-2011 The Project Lombok Authors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # android-retrolambda-lombok 2 | A modified version of lombok ast that allows lint to run on java 8 sources without error. 3 | 4 | ## Usage 5 | All you have to do is modify you `build.gradle` as such 6 | ```groovy 7 | buildscript { 8 | repositories { 9 | jcenter() 10 | ... 11 | } 12 | 13 | dependencies { 14 | classpath 'com.android.tools.build:gradle:' 15 | classpath "me.tatarka:gradle-retrolambda:" 16 | classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2' 17 | } 18 | 19 | // Exclude the version that the android plugin depends on. 20 | configurations.classpath.exclude group: 'com.android.tools.external.lombok' 21 | } 22 | ``` 23 | ## Additional Lint Configuration 24 | Lint doesn't realize that try-with-resources are backported by retrolambda. You can ignore just that while keeping the rest of the `NewApi` lint check by adding the following to your `lint.xml`. 25 | ```xml 26 | 27 | 28 | 29 | ``` 30 | 31 | ## Limitations 32 | - Currently you must run gradle with java 8. This may or may not be fixed in the future depending on if I can get lombok to compile with a lower java version. 33 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/com.github.parboiled.custom-parboiled-0.9.7.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/com.zwitserloot-cmdreader-1.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/junit-ivy-4.8.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/net.java.openjdk.custom-javac6-1.6.0.18.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/projectlombok.org-jsch-ant-fixed-0.1.42.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /buildScripts/ivy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /buildScripts/ivysettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | jls 2 | api 3 | -------------------------------------------------------------------------------- /doc/maven-pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | me.tatarka.retrolambda.projectlombok 5 | lombok.ast 6 | jar 7 | @VERSION@ 8 | Project Lombok - AST 9 | http://projectlombok.org 10 | An abstract syntax tree for java source code, including a parser and converters to/from ecj (eclipse) and javac. 11 | 12 | 13 | 14 | The MIT License 15 | http://projectlombok.org/LICENSE 16 | repo 17 | 18 | 19 | 20 | scm:git:git://github.com/rzwitserloot/lombok.ast.git 21 | http://github.com/rzwitserloot/lombok.ast 22 | 23 | 24 | Google Code 25 | http://code.google.com/p/projectlombok/issues 26 | 27 | 28 | 29 | rzwitserloot 30 | Reinier Zwitserloot 31 | reinier@projectlombok.org 32 | http://zwitserloot.com 33 | +1 34 | 35 | 36 | rspilker 37 | Roel Spilker 38 | roel@projectlombok.org 39 | +1 40 | 41 | 42 | rgrootjans 43 | Robbert Jan Grootjans 44 | +1 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/lombok/ast/AnnotationValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface AnnotationValue extends Node { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Ast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | /** 25 | * Contains utility methods for traversing and manipulating ASTs. 26 | */ 27 | public class Ast { 28 | /** 29 | * Sets the position of {@code node} to {@code position}, and then does the same for all of {@code node}'s children, recursively. 30 | */ 31 | public static Node setAllPositions(Node node, Position position) { 32 | node.setPosition(position); 33 | for (Node child : node.getChildren()) setAllPositions(child, position); 34 | return node; 35 | } 36 | 37 | /** 38 | * Get the current lombok.ast version. 39 | */ 40 | public static String getVersion() { 41 | return Version.getVersion(); 42 | } 43 | 44 | public static CompilationUnit upToTop(Node node) { 45 | while (node != null && !(node instanceof CompilationUnit)) node = node.getParent(); 46 | return (CompilationUnit) node; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/lombok/ast/AstException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import lombok.EqualsAndHashCode; 25 | 26 | @EqualsAndHashCode(callSuper=false) 27 | public class AstException extends RuntimeException { 28 | private final Node problemNode; 29 | private final String message; 30 | 31 | public AstException(Node problemNode, String message) { 32 | super(message); 33 | this.message = message; 34 | this.problemNode = problemNode; 35 | } 36 | 37 | @Override public String toString() { 38 | if (problemNode == null && getMessage() == null) return "AstException (unknown cause)"; 39 | if (problemNode == null) return "AstException: " + getMessage(); 40 | String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); 41 | try { 42 | nodeDescription = problemNode.toString(); 43 | } catch (Throwable ignore) { 44 | //throwing exceptions in toString() is bad. 45 | } 46 | if (getMessage() == null) return "AstException at " + nodeDescription; 47 | return String.format("AstException: %s (at %s)", getMessage(), nodeDescription); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/lombok/ast/BinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public enum BinaryOperator { 25 | PLUS_ASSIGN("+=", 14), MINUS_ASSIGN("-=", 14), MULTIPLY_ASSIGN("*=", 14), DIVIDE_ASSIGN("/=", 14), REMAINDER_ASSIGN("%=", 14), AND_ASSIGN("&=", 14), XOR_ASSIGN("^=", 14), OR_ASSIGN("|=", 14), SHIFT_LEFT_ASSIGN("<<=", 14), SHIFT_RIGHT_ASSIGN(">>=", 14), BITWISE_SHIFT_RIGHT_ASSIGN(">>>=", 14), ASSIGN("=", 14), 26 | LOGICAL_OR("||", 12), 27 | LOGICAL_AND("&&", 11), 28 | BITWISE_OR("|", 10), 29 | BITWISE_XOR("^", 9), 30 | BITWISE_AND("&", 8), 31 | EQUALS("==", 7), NOT_EQUALS("!=", 7), 32 | GREATER(">", 6), GREATER_OR_EQUAL(">=", 6), LESS("<", 6), LESS_OR_EQUAL("<=", 6), 33 | SHIFT_LEFT("<<", 5), SHIFT_RIGHT(">>", 5), BITWISE_SHIFT_RIGHT(">>>", 5), 34 | PLUS("+", 4), MINUS("-", 4), 35 | MULTIPLY("*", 3), DIVIDE("/", 3), REMAINDER("%", 3); 36 | 37 | private final String symbol; 38 | private final int pLevel; 39 | 40 | BinaryOperator(String symbol, int pLevel) { 41 | this.symbol = symbol; 42 | this.pLevel = pLevel; 43 | } 44 | 45 | public String getSymbol() { 46 | return symbol; 47 | } 48 | 49 | public boolean isAssignment() { 50 | return pLevel == ASSIGN.pLevel; 51 | } 52 | 53 | public static BinaryOperator fromSymbol(String symbol) { 54 | for (BinaryOperator op : values()) { 55 | if (op.symbol.equals(symbol)) return op; 56 | } 57 | 58 | return null; 59 | } 60 | 61 | int pLevel() { 62 | return pLevel; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/lombok/ast/ConversionPositionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2011 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.WeakHashMap; 27 | 28 | /** 29 | * Lombok.ast node objects built via conversion from other ast APIs can have associated position info which 30 | * is useful for conversion back to the original AST. 31 | */ 32 | public class ConversionPositionInfo { 33 | private static WeakHashMap> store = new WeakHashMap>(); 34 | 35 | public static void setConversionPositionInfo(Node on, String key, Position position) { 36 | if (on instanceof AbstractNode) { 37 | ((AbstractNode) on).addConversionPositionInfo(key, position); 38 | } else { 39 | synchronized (store) { 40 | Map map = store.get(on); 41 | if (map == null) { 42 | map = new HashMap(); 43 | store.put(on, map); 44 | } 45 | map.put(key, position); 46 | } 47 | } 48 | } 49 | 50 | public static Position getConversionPositionInfo(Node on, String key) { 51 | if (on instanceof AbstractNode) { 52 | return ((AbstractNode) on).getConversionPositionInfo(key); 53 | } else { 54 | synchronized (store) { 55 | Map map = store.get(on); 56 | if (map == null) return null; 57 | return map.get(key); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/lombok/ast/DanglingNodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2011 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Collections; 26 | import java.util.List; 27 | import java.util.WeakHashMap; 28 | 29 | /** 30 | * Lombok.ast node objects can have associated 'dangling nodes'. These are nodes that are parsed within or around that node which aren't supposed to be there, such as 31 | * statements in between 2 method declarations. 32 | */ 33 | public class DanglingNodes { 34 | private static WeakHashMap> store = new WeakHashMap>(); 35 | 36 | public static void addDanglingNode(Node on, Node danglingNode) { 37 | if (on instanceof AbstractNode) { 38 | ((AbstractNode) on).addDanglingNode(danglingNode); 39 | } else { 40 | synchronized (store) { 41 | List list = store.get(on); 42 | if (list == null) { 43 | list = new ArrayList(); 44 | store.put(on, list); 45 | } 46 | list.add(danglingNode); 47 | } 48 | } 49 | } 50 | 51 | public static List getDanglingNodes(Node on) { 52 | if (on instanceof AbstractNode) { 53 | return ((AbstractNode) on).getDanglingNodes(); 54 | } else { 55 | synchronized (store) { 56 | List list = store.get(on); 57 | if (list == null) return Collections.emptyList(); 58 | return Collections.unmodifiableList(list); 59 | } 60 | } 61 | } 62 | 63 | public static void removeDanglingNode(Node on, Node danglingNode) { 64 | if (on instanceof AbstractNode) { 65 | ((AbstractNode) on).removeDanglingNode(danglingNode); 66 | } else { 67 | List list = store.get(on); 68 | if (list != null) list.remove(danglingNode); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/lombok/ast/DescribedNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface DescribedNode extends Node { 25 | /** 26 | * A very short string that is particularly useful in describing this node. 27 | * Can always be {@code null} to indicate this particular instance has no useful name (usually, but not neccessarily, because it is not valid). 28 | * 29 | * NB: This method should never throw an exception! 30 | */ 31 | String getDescription(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import java.util.List; 25 | 26 | public interface Expression extends Node, AnnotationValue { 27 | /** 28 | * Returns the actual amount of parentheses physically around this expression. 29 | * 30 | * @see #astParensPositions() 31 | * @see #getIntendedParens() 32 | */ 33 | int getParens(); 34 | 35 | /** 36 | * Returns the same value as {@link #getParens()}, unless that method returns {@code 0}, 37 | * and {@link #needsParentheses()} is {@code true}, then this method returns {@code 1}. 38 | */ 39 | int getIntendedParens(); 40 | 41 | /** 42 | * Returns the start/end position of each paren pair around this node. The only canonical aspect 43 | * of this list is the size of it. The positions are set to appropriate files after parsing, from 44 | * the innermost parens at index 0 to the outermost at the final index. 45 | * 46 | * @see #getParens() 47 | */ 48 | List astParensPositions(); 49 | 50 | /** 51 | * Returns {@code true} if the expression would need parentheses because without them the interpretation 52 | * of this node would be different, due to operator precedence rules. 53 | * 54 | * @see #getIntendedParens() 55 | */ 56 | boolean needsParentheses(); 57 | 58 | /** 59 | * Returns true if the given expression is a valid statement expression. 60 | * Statement expressions can be executed as statements simply by appending a semicolon to them. 61 | */ 62 | boolean isStatementExpression(); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/lombok/ast/FunctionalExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface FunctionalExpression extends Expression { 25 | } 26 | -------------------------------------------------------------------------------- /src/main/lombok/ast/JavadocContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface JavadocContainer extends Node { 25 | Comment astJavadoc(); 26 | Node rawJavadoc(); 27 | Node astJavadoc(Comment javadoc); 28 | Node rawJavadoc(Node javadoc); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Literal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface Literal extends Node { 25 | public String rawValue(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/LiteralType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public enum LiteralType { 25 | DECIMAL, HEXADECIMAL, OCTAL; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import lombok.AccessLevel; 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | 28 | @Data 29 | @RequiredArgsConstructor(access = AccessLevel.PRIVATE) 30 | public class Message { 31 | public enum MessageType { 32 | ERROR, WARNING; 33 | } 34 | 35 | private final MessageType type; 36 | private final MessageKey key; 37 | private final String message; 38 | 39 | public static Message warning(MessageKey key, String message) { 40 | return new Message(MessageType.WARNING, key, message); 41 | } 42 | 43 | public static Message error(MessageKey key, String message) { 44 | return new Message(MessageType.ERROR, key, message); 45 | } 46 | 47 | public static Message warning(String message) { 48 | return new Message(MessageType.WARNING, null, message); 49 | } 50 | 51 | public static Message error(String message) { 52 | return new Message(MessageType.ERROR, null, message); 53 | } 54 | 55 | public boolean isError() { 56 | return MessageType.ERROR == type; 57 | } 58 | 59 | public boolean isWarning() { 60 | return MessageType.WARNING == type; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return key == null ? message : String.format("[%s %s] %s", type, key, message); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/lombok/ast/MessageKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface MessageKey { 25 | public String getKey(); 26 | 27 | public String toString(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/lombok/ast/NullLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public class NullLiteral extends AbstractNode.WithParens implements Literal, Expression { 25 | private String rawValue = "null"; 26 | private String errorReasonForValue; 27 | 28 | @Override 29 | public boolean isStatementExpression() { 30 | return false; 31 | } 32 | 33 | public String getErrorReasonForValue() { 34 | return errorReasonForValue; 35 | } 36 | 37 | public NullLiteral rawValue(String raw) { 38 | if (raw == null) { 39 | this.rawValue = null; 40 | this.errorReasonForValue = "Missing value"; 41 | } else { 42 | this.rawValue = raw; 43 | String v = raw.trim(); 44 | if (!v.equals("null")) { 45 | this.errorReasonForValue = "Only 'null' is a valid null literal, not: " + v; 46 | } else { 47 | this.errorReasonForValue = null; 48 | } 49 | } 50 | 51 | return this; 52 | } 53 | 54 | @Override 55 | public String rawValue() { 56 | return rawValue; 57 | } 58 | 59 | public boolean astIsValid() { 60 | return errorReasonForValue == null; 61 | } 62 | 63 | @Override 64 | public void accept(AstVisitor visitor) { 65 | if (!visitor.visitNullLiteral(this)) visitor.endVisit(this); 66 | visitor.afterVisitNullLiteral(this); 67 | } 68 | 69 | @Override 70 | public NullLiteral copy() { 71 | NullLiteral result = new NullLiteral(); 72 | result.rawValue = rawValue; 73 | result.errorReasonForValue = errorReasonForValue; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import lombok.Data; 25 | 26 | /** 27 | * The position information which lets you find the raw characters that represent this node in a source file. 28 | * For generated nodes, {@code generatedBy} is set to non-{@code null} and the {@code start} and {@code end} 29 | * refer to the places where the node would have appeared if it wasn't generated. 30 | */ 31 | @Data 32 | public final class Position { 33 | private final int start, end; 34 | private final Node generatedBy; 35 | 36 | public static Position UNPLACED = new Position(-1, -1); 37 | 38 | public Position(int start, int end) { 39 | this.start = start; 40 | this.end = end; 41 | this.generatedBy = null; 42 | } 43 | 44 | public Position(int start, int end, Node generatedBy) { 45 | this.start = start; 46 | this.end = end; 47 | this.generatedBy = generatedBy; 48 | } 49 | 50 | public int size() { 51 | return end - start; 52 | } 53 | 54 | public boolean isUnplaced() { 55 | return start == UNPLACED.start && end == UNPLACED.end; 56 | } 57 | 58 | public Position withGeneratedBy(Node generatedBy) { 59 | return new Position(start, end, generatedBy); 60 | } 61 | 62 | public Position withoutGeneratedBy() { 63 | return new Position(start, end); 64 | } 65 | 66 | public Position withEnd(int position) { 67 | return new Position(start, position, generatedBy); 68 | } 69 | 70 | public Position withStart(int position) { 71 | return new Position(position, end, generatedBy); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/lombok/ast/PositionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | /** A factory which can create position information for nodes */ 25 | public class PositionFactory { 26 | /** Returns the {@link Position} corresponding to the given node */ 27 | public Position getPosition(Node node) { 28 | return null; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/lombok/ast/RawListAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface RawListAccessor extends Iterable { 25 | P up(); 26 | Node owner(); 27 | void clear(); 28 | boolean isEmpty(); 29 | int size(); 30 | Node first(); 31 | Node last(); 32 | boolean contains(Node source); 33 | P migrateAllFrom(RawListAccessor otherList); 34 | P addToStart(Node... node); 35 | P addToEnd(Node... node); 36 | P addBefore(Node ref, Node... node); 37 | P addAfter(Node ref, Node... node); 38 | boolean replace(Node source, Node replacement); 39 | boolean remove(Node source); 40 | StrictListAccessor asStrictAccessor(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/lombok/ast/ResolutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import lombok.EqualsAndHashCode; 25 | 26 | @EqualsAndHashCode(callSuper=false) 27 | public class ResolutionException extends RuntimeException { 28 | private final Node problemNode; 29 | private final String message; 30 | 31 | public ResolutionException(Node problemNode, String message) { 32 | super(message); 33 | this.message = message; 34 | this.problemNode = problemNode; 35 | } 36 | 37 | @Override public String toString() { 38 | if (problemNode == null && getMessage() == null) return "ResolutionException (unknown cause)"; 39 | if (problemNode == null) return "AstException: " + getMessage(); 40 | String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); 41 | try { 42 | nodeDescription = problemNode.toString(); 43 | } catch (Throwable ignore) { 44 | //throwing exceptions in toString() is bad. 45 | } 46 | if (getMessage() == null) return "ResolutionException at " + nodeDescription; 47 | return String.format("ResolutionException: %s (at %s)", getMessage(), nodeDescription); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/lombok/ast/Statement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface Statement extends Node { 25 | public Block upToBlock(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/StrictListAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import java.util.NoSuchElementException; 25 | 26 | public interface StrictListAccessor extends Iterable { 27 | P up(); 28 | Node owner(); 29 | void clear(); 30 | boolean isEmpty(); 31 | int size(); 32 | T first(); 33 | T last(); 34 | boolean contains(Node source); 35 | P migrateAllFrom(StrictListAccessor otherList); 36 | P addToStart(T... node); 37 | P addToEnd(T... node); 38 | P addBefore(Node ref, T... node); 39 | P addAfter(Node ref, T... node); 40 | void replace(Node source, T replacement) throws NoSuchElementException; 41 | void remove(Node source) throws NoSuchElementException; 42 | RawListAccessor asRawAccessor(); 43 | } -------------------------------------------------------------------------------- /src/main/lombok/ast/TypeBody.java: -------------------------------------------------------------------------------- 1 | package lombok.ast; 2 | 3 | import lombok.ast.template.ParentAccessor; 4 | 5 | public interface TypeBody extends Node { 6 | @ParentAccessor 7 | StrictListAccessor astMembers(); 8 | RawListAccessor rawMembers(); 9 | 10 | ConstructorInvocation upIfAnonymousClassToConstructorInvocation(); 11 | EnumConstant upToEnumConstant(); 12 | TypeDeclaration upToTypeDeclaration(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/lombok/ast/TypeDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | import lombok.ast.template.ParentAccessor; 25 | 26 | /** 27 | * Common interface shared by all type declaration nodes. 28 | */ 29 | public interface TypeDeclaration extends Node, DescribedNode, JavadocContainer { 30 | Comment astJavadoc(); 31 | Node rawJavadoc(); 32 | TypeDeclaration astJavadoc(Comment comment); 33 | TypeDeclaration rawJavadoc(Node comment); 34 | 35 | @ParentAccessor Modifiers astModifiers(); 36 | TypeDeclaration astModifiers(Modifiers modifiers); 37 | 38 | Identifier astName(); 39 | TypeDeclaration astName(Identifier name); 40 | 41 | @ParentAccessor TypeBody astBody(); 42 | Node rawBody(); 43 | 44 | CompilationUnit upIfTopLevelToCompilationUnit(); 45 | Block upToBlock(); 46 | 47 | boolean isInterface(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/lombok/ast/TypeMember.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public interface TypeMember extends Node { 25 | TypeBody upToTypeBody(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public enum UnaryOperator { 25 | BINARY_NOT("~", false), LOGICAL_NOT("!", false), UNARY_PLUS("+", false), UNARY_MINUS("-", false), 26 | PREFIX_INCREMENT("++", false), PREFIX_DECREMENT("--", false), POSTFIX_INCREMENT("++", true), POSTFIX_DECREMENT("--", true); 27 | 28 | private final String symbol; 29 | private final boolean postfix; 30 | 31 | UnaryOperator(String symbol, boolean postfix) { 32 | this.symbol = symbol; 33 | this.postfix = postfix; 34 | } 35 | 36 | public String getSymbol() { 37 | return symbol; 38 | } 39 | 40 | public boolean isPostfix() { 41 | return postfix; 42 | } 43 | 44 | public static UnaryOperator fromSymbol(String symbol, boolean postfix) { 45 | for (UnaryOperator op : values()) { 46 | if (op.symbol.equals(symbol) && op.postfix == postfix) return op; 47 | } 48 | 49 | return null; 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/lombok/ast/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2011 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | /** 25 | * This class just holds lombok.ast's current version. 26 | */ 27 | public class Version { 28 | // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). 29 | // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. 30 | // Official builds always end in an even number. 31 | private static final String VERSION = "0.2.3.a2"; 32 | 33 | private Version() { 34 | //Prevent instantiation 35 | } 36 | 37 | /** 38 | * Prints the version followed by a newline, and exits. 39 | */ 40 | public static void main(String[] args) { 41 | System.out.println(VERSION); 42 | } 43 | 44 | /** 45 | * Get the current lombok.ast version. 46 | */ 47 | public static String getVersion() { 48 | return VERSION; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/lombok/ast/WildcardKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast; 23 | 24 | public enum WildcardKind { 25 | NONE, EXTENDS, SUPER, UNBOUND; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/BasicsActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.ast.Comment; 25 | import lombok.ast.Identifier; 26 | import lombok.ast.Node; 27 | import lombok.ast.Position; 28 | 29 | public class BasicsActions extends SourceActions { 30 | public BasicsActions(Source source) { 31 | super(source); 32 | } 33 | 34 | public Node createIdentifier(String text, org.parboiled.Node rawIdentifier) { 35 | Identifier id = new Identifier(); 36 | if (text != null) id.astValue(text); 37 | 38 | int start = rawIdentifier.getStartIndex(); 39 | int end = Math.max(start, rawIdentifier.getEndIndex()); 40 | id.setPosition(new Position(start, end)); 41 | return id; 42 | } 43 | 44 | public boolean checkIfKeyword(String text) { 45 | return text == null || !BasicsParser.KEYWORDS.contains(text); 46 | } 47 | 48 | public boolean logComment(String text) { 49 | if (text.startsWith("//")) return logLineComment(text); 50 | else return logBlockComment(text); 51 | } 52 | 53 | public boolean logBlockComment(String text) { 54 | if (text.startsWith("/*")) text = text.substring(2); 55 | if (text.endsWith("*/")) text = text.substring(0, text.length() - 2); 56 | Comment c = new Comment().astBlockComment(true).astContent(text); 57 | c.setPosition(new Position(startPos(), currentPos())); 58 | source.registerComment(getContext(), c); 59 | return true; 60 | } 61 | 62 | public boolean logLineComment(String text) { 63 | if (text.startsWith("//")) text = text.substring(2); 64 | Comment c = new Comment().astBlockComment(false).astContent(text); 65 | c.setPosition(new Position(startPos(), currentPos())); 66 | source.registerComment(getContext(), c); 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/LiteralsActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.ast.BooleanLiteral; 25 | import lombok.ast.CharLiteral; 26 | import lombok.ast.FloatingPointLiteral; 27 | import lombok.ast.IntegralLiteral; 28 | import lombok.ast.Node; 29 | import lombok.ast.NullLiteral; 30 | import lombok.ast.StringLiteral; 31 | 32 | public class LiteralsActions extends SourceActions { 33 | public LiteralsActions(Source source) { 34 | super(source); 35 | } 36 | 37 | public Node createNullLiteral(String raw) { 38 | return posify(new NullLiteral().rawValue(raw)); 39 | } 40 | 41 | public Node createStringLiteral(String raw) { 42 | return posify(new StringLiteral().rawValue(raw)); 43 | } 44 | 45 | public Node createCharLiteral(String raw) { 46 | return posify(new CharLiteral().rawValue(raw)); 47 | } 48 | 49 | public Node createBooleanLiteral(String raw) { 50 | return posify(new BooleanLiteral().rawValue(raw)); 51 | } 52 | 53 | public Node createNumberLiteral(String raw) { 54 | if (raw == null) return posify(new IntegralLiteral()); 55 | 56 | String v = raw.trim().toLowerCase(); 57 | 58 | if (v.startsWith("0x")) { 59 | if (v.contains("p")) return posify(new FloatingPointLiteral().rawValue(raw)); 60 | return posify(new IntegralLiteral().rawValue(raw)); 61 | } 62 | 63 | if (v.contains(".") || v.endsWith("d") || v.endsWith("f") || v.contains("e")) { 64 | return posify(new FloatingPointLiteral().rawValue(raw)); 65 | } 66 | else return posify(new IntegralLiteral().rawValue(raw)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/ParseProblem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.Data; 25 | import lombok.ast.Position; 26 | 27 | @Data 28 | public class ParseProblem { 29 | private final Position position; 30 | private final String message; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/ParserGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.Getter; 25 | 26 | import org.parboiled.Parboiled; 27 | 28 | public class ParserGroup { 29 | @Getter private final Source source; 30 | public final BasicsParser basics; 31 | public final LiteralsParser literals; 32 | public final TypesParser types; 33 | public final ExpressionsParser expressions; 34 | public final StatementsParser statements; 35 | public final StructuresParser structures; 36 | 37 | public ParserGroup(Source source) { 38 | this.source = source; 39 | basics = Parboiled.createParser(BasicsParser.class, this); 40 | literals = Parboiled.createParser(LiteralsParser.class, this); 41 | types = Parboiled.createParser(TypesParser.class, this); 42 | expressions = Parboiled.createParser(ExpressionsParser.class, this); 43 | statements = Parboiled.createParser(StatementsParser.class, this); 44 | structures = Parboiled.createParser(StructuresParser.class, this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/SourceActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.ast.DanglingNodes; 25 | import lombok.ast.Identifier; 26 | import lombok.ast.Modifiers; 27 | import lombok.ast.Node; 28 | import lombok.ast.Position; 29 | 30 | import org.parboiled.BaseActions; 31 | 32 | class SourceActions extends BaseActions { 33 | protected final Source source; 34 | 35 | SourceActions(Source source) { 36 | this.source = source; 37 | } 38 | 39 | Identifier createIdentifierIfNeeded(Node identifier, int pos) { 40 | if (identifier instanceof Identifier) return (Identifier)identifier; 41 | Identifier i = new Identifier(); 42 | i.setPosition(new Position(pos, pos)); 43 | DanglingNodes.addDanglingNode(i, identifier); 44 | return i; 45 | } 46 | 47 | Modifiers createModifiersIfNeeded(Node modifiers, int pos) { 48 | if (modifiers instanceof Modifiers) return (Modifiers)modifiers; 49 | Modifiers m = new Modifiers(); 50 | m.setPosition(new Position(pos, pos)); 51 | DanglingNodes.addDanglingNode(m, modifiers); 52 | return m; 53 | } 54 | 55 | T posify(T node) { 56 | int start = startPos(); 57 | int end = Math.max(start, currentPos()); 58 | node.setPosition(new Position(start, end)); 59 | return node; 60 | } 61 | 62 | int startPos() { 63 | return getContext().getStartIndex(); 64 | } 65 | 66 | int currentPos() { 67 | return getContext().getCurrentIndex(); 68 | } 69 | 70 | void positionSpan(Node target, org.parboiled.Node start, org.parboiled.Node end) { 71 | if (target == null || start == null || end == null) return; 72 | target.setPosition(new Position(start.getStartIndex(), end.getEndIndex())); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/lombok/ast/grammar/SourceStructure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.AccessLevel; 25 | import lombok.Data; 26 | import lombok.NonNull; 27 | import lombok.Setter; 28 | import lombok.ast.Position; 29 | 30 | @Data 31 | public final class SourceStructure { 32 | @Setter(AccessLevel.PACKAGE) 33 | @NonNull private Position position; 34 | @NonNull private final String content; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/lombok/ast/resolve/AnnotationClassNotAvailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.resolve; 23 | 24 | import java.util.List; 25 | 26 | import lombok.AccessLevel; 27 | import lombok.Getter; 28 | import lombok.Setter; 29 | import lombok.ast.Node; 30 | import lombok.ast.ResolutionException; 31 | 32 | /** 33 | * This exception can be thrown when a {@code Class} returning method is called on an 34 | * annotation instance from {@link Resolver#toAnnotationInstance(Class, lombok.ast.Annotation)}. 35 | * 36 | * You should use {@link Resolver#getAnnotationClassAsString(java.lang.annotation.Annotation, String)} instead. 37 | */ 38 | public class AnnotationClassNotAvailableException extends ResolutionException { 39 | @Getter private final String className; 40 | @Getter @Setter(AccessLevel.PACKAGE) private List classNames; 41 | 42 | public AnnotationClassNotAvailableException(Node problemNode, String className) { 43 | super(problemNode, "Class not available: " + className + " - use Resolver.getAnnotationClassAsString instead."); 44 | this.className = className; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/lombok/ast/syntaxChecks/BasicChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.syntaxChecks; 23 | 24 | import static lombok.ast.Message.*; 25 | import static lombok.ast.syntaxChecks.MessageKey.*; 26 | 27 | import lombok.ast.Identifier; 28 | import lombok.ast.Node; 29 | import lombok.ast.VariableDefinition; 30 | import lombok.ast.VariableDefinitionEntry; 31 | import lombok.ast.template.SyntaxCheck; 32 | 33 | @SyntaxCheck 34 | public class BasicChecks { 35 | public void checkNameOfIdentifier(Identifier identifier) { 36 | String n = identifier.astValue(); 37 | if (n.length() == 0) { 38 | identifier.addMessage(error(IDENTIFIER_EMPTY, "Empty Identifier")); 39 | return; 40 | } 41 | 42 | if (!Character.isJavaIdentifierStart(n.charAt(0))) { 43 | identifier.addMessage(error(IDENTIFIER_INVALID, "Not a legal start character for a java identifier: " + n.charAt(0))); 44 | return; 45 | } 46 | 47 | for (int i = 1; i < n.length(); i++) { 48 | if (!Character.isJavaIdentifierPart(n.charAt(i))) { 49 | identifier.addMessage(error(IDENTIFIER_INVALID, "Not a legal character in a java identifier: " + n.charAt(i))); 50 | return; 51 | } 52 | } 53 | } 54 | 55 | static void checkVarDefIsSimple(Node node, Node rawVarDef, String descriptionOfOuter, String descriptionOfRelation) { 56 | if (!(rawVarDef instanceof VariableDefinition)) return; 57 | switch (((VariableDefinition)rawVarDef).rawVariables().size()) { 58 | case 0: return; 59 | case 1: break; 60 | default: 61 | rawVarDef.addMessage(error(VARIABLEDEFINITION_ONLY_ONE, String.format("%s can only declare one %s variable", descriptionOfOuter, descriptionOfRelation))); 62 | } 63 | 64 | for (VariableDefinitionEntry entry : ((VariableDefinition)rawVarDef).astVariables()) { 65 | if (entry.rawInitializer() != null) entry.addMessage(error(VARIABLEDEFINITIONENTRY_INITIALIZER_NOT_ALLOWED, String.format( 66 | "%s can only declare %s variables without an initializer", descriptionOfOuter, descriptionOfRelation))); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/lombok/ast/syntaxChecks/LiteralValidityChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.syntaxChecks; 23 | 24 | import lombok.ast.template.SyntaxCheck; 25 | 26 | @SyntaxCheck 27 | public class LiteralValidityChecks { 28 | //TODO Add unified 'check any Node object with a getErrorReasonForValue() method. 29 | } 30 | -------------------------------------------------------------------------------- /src/main/lombok/ast/syntaxChecks/MessageKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.syntaxChecks; 23 | 24 | public enum MessageKey implements lombok.ast.MessageKey { 25 | /** Signals an identifier node has zero characters in it. */ 26 | IDENTIFIER_EMPTY("empty"), 27 | 28 | /** Signals an identifier node is not a valid java identifier. */ 29 | IDENTIFIER_INVALID("invalid"), 30 | 31 | /** Signals that only one variable name is legal in a given definition, but there is more than one. */ 32 | VARIABLEDEFINITION_ONLY_ONE("only one"), 33 | 34 | VARIABLEDEFINITION_EMPTY("empty"), 35 | 36 | VARIABLEDEFINITION_VARARGS_NOT_LEGAL_HERE("not legal here"), 37 | 38 | /** Signals some variable definition has an initializer but those aren't allowed there. */ 39 | VARIABLEDEFINITIONENTRY_INITIALIZER_NOT_ALLOWED("initializer not allowed"), 40 | 41 | VARIABLEDEFINITIONENTRY_EXTENDED_DIMENSIONS_NOT_LEGAL("extended dimensions not legal"), 42 | 43 | DECLARATION_NOT_ALLOWED("Declarations are not allowed here"), 44 | 45 | MODIFIERS_DUPLICATE_KEYWORD("duplicate keyword"), 46 | 47 | MODIFIERS_STATIC_CHAIN("static chain"), 48 | 49 | MODIFIERS_ABSTRACT_NOT_ALLOWED("Abstract is not allowed here"), 50 | 51 | INITIALIZER_STATIC_IN_NON_STATIC_TYPE("static initializer in non static type"), 52 | 53 | MODIFIERS_EMPTY_MODIFIER("empty modifier"), 54 | 55 | MODIFIERS_UNKNOWN_MODIFIER("unknown modifier"), 56 | 57 | MODIFIERS_MODIFIER_NOT_ALLOWED("modifier not allowed"), 58 | 59 | MODIFIERS_MODIFIER_CONFLICT("modifier conflicts with another modifier"), 60 | 61 | TRY_LONE_TRY("try without catch or finally"), 62 | 63 | STATEMENT_ONLY_LEGAL_IN_SWITCH("statement only legal inside switch"), 64 | 65 | SWITCH_DOES_NOT_START_WITH_CASE("switch does not start with case or default"), 66 | 67 | INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY("initializer blocks must complete normally"), 68 | 69 | CONSTRUCTOR_INVOCATION_NOT_LEGAL_HERE("constructor invocation not legal here"), 70 | 71 | TYPEARGUMENT_PRIMITIVE_NOT_ALLOWED("primitive not allowed"), 72 | 73 | TYPEVARIABLE_PRIMITIVE_NOT_ALLOWED("primitive not allowed"), 74 | 75 | TYPEREFERENCE_VOID_NOT_ALLOWED("void not allowed"), 76 | 77 | STATEMENT_UNREACHABLE("unreachable"), 78 | 79 | NODE_MISSING_MANDATORY_CHILD("missing child node"), 80 | 81 | NODE_CHILD_TYPE_INCORRECT("child type incorrect"), 82 | 83 | PARSEARTEFACT("parse artefact"), 84 | 85 | TERMINAL_MISSING("missing"), 86 | 87 | TERMINAL_INVALID("invalid"), 88 | 89 | ; 90 | 91 | private final String key; 92 | 93 | MessageKey(String key) { 94 | this.key = key; 95 | } 96 | 97 | public String getKey() { 98 | return key; 99 | } 100 | 101 | @Override 102 | public String toString() { 103 | return key; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/lombok/ast/syntaxChecks/TypeChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.syntaxChecks; 23 | 24 | import static lombok.ast.syntaxChecks.MessageKey.*; 25 | import static lombok.ast.Message.*; 26 | 27 | import lombok.ast.TypeReference; 28 | import lombok.ast.template.SyntaxCheck; 29 | 30 | @SyntaxCheck 31 | public class TypeChecks { 32 | public void checkNoPrimitivesInGenerics(TypeReference node) { 33 | if (!node.isPrimitive()) return; 34 | 35 | if (node.upIfTypeArgumentToTypeReferencePart() != null) { 36 | node.addMessage(error(TYPEARGUMENT_PRIMITIVE_NOT_ALLOWED, "Primitive types aren't allowed in type arguments.")); 37 | return; 38 | } 39 | 40 | if (node.upIfTypeVariableBoundToTypeVariable() != null) { 41 | node.addMessage(error(TYPEVARIABLE_PRIMITIVE_NOT_ALLOWED, "Primitive types aren't allowed in type variable bounds.")); 42 | return; 43 | } 44 | } 45 | 46 | public void checkVoidNotLegalJustAboutEverywhere(TypeReference node) { 47 | if (!node.isVoid()) return; 48 | if (node.astArrayDimensions() > 0) { 49 | node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "Array of void type is not legal.")); 50 | return; 51 | } 52 | 53 | if (node.upIfReturnTypeToMethodDeclaration() != null) return; 54 | 55 | if (node.upToClassLiteral() != null) return; 56 | 57 | node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "The void type is not legal here.")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/lombok/ast/syntaxChecks/UnreachableStatementsChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.syntaxChecks; 23 | 24 | import static lombok.ast.syntaxChecks.MessageKey.*; 25 | import static lombok.ast.Message.*; 26 | 27 | import lombok.ast.Block; 28 | import lombok.ast.Break; 29 | import lombok.ast.Continue; 30 | import lombok.ast.Node; 31 | import lombok.ast.Return; 32 | import lombok.ast.Statement; 33 | import lombok.ast.template.SyntaxCheck; 34 | 35 | @SyntaxCheck 36 | public class UnreachableStatementsChecks { 37 | public void unreachablesAfterBreak(Break statement) { 38 | checkForUnreachables(statement); 39 | } 40 | 41 | public void unreachablesAfterContinue(Continue statement) { 42 | checkForUnreachables(statement); 43 | } 44 | 45 | public void unreachableAfterReturn(Return statement) { 46 | checkForUnreachables(statement); 47 | } 48 | 49 | private void checkForUnreachables(Statement n) { 50 | Block b = n.upToBlock(); 51 | if (b == null) return; 52 | 53 | boolean found = false; 54 | for (Node s : b.rawContents()) { 55 | if (found) { 56 | s.addMessage(error(STATEMENT_UNREACHABLE, "Unreachable code")); 57 | return; 58 | } 59 | if (s == n) found = true; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/printer/lombok/ast/printer/web/ast.css: -------------------------------------------------------------------------------- 1 | #tree div { 2 | padding-left: 4px; 3 | margin-left: 1em; 4 | } 5 | 6 | #tree>div { 7 | padding-left: 0px; 8 | margin-left: 0px; 9 | } 10 | 11 | #tree div.collapsed div { 12 | display: none; 13 | } 14 | 15 | .highlight { 16 | background-color: #ffbcff; 17 | } 18 | 19 | #tree .treeNodeArrow { 20 | padding: 0; 21 | margin: 0 2px 0 0; 22 | width: 10px; 23 | height: 16px; 24 | display: block; 25 | float: left; 26 | } 27 | 28 | #tree div.collapsed>.treeNodeArrow { 29 | background: url("data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/7u7u2ZmZt3d3f///wAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMVGLrM0+7BMIpsg1iYBeDeNHwTOUEJADs=") no-repeat 0 3px; 30 | } 31 | 32 | #tree div.expanded>.treeNodeArrow { 33 | background: url("data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/2ZmZt3d3f///wAAAAAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMUGLrc/rCJSecCJBPQwBicA4RRuSQAOw==") no-repeat 0 3px; 34 | } 35 | 36 | #tree div.leaf>.treeNodeArrow { 37 | background: url("data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/2ZmZt3d3f///wAAAAAAAAAAACH5BAEAAAEALAAAAAAKAAoAAAMVGLrc/k6IJwiZDFgLGhhD5wAiZDYJADs=") no-repeat 0 3px; 38 | } 39 | 40 | #source { 41 | font-family: "Inconsolata", "DejaVu Sans Mono", "Consolidas", "Monaco", monospace; 42 | font-size: 18px; 43 | } 44 | 45 | .outlined { 46 | outline: solid black 1px; 47 | } 48 | 49 | #source div { 50 | margin-left: 2em; 51 | } 52 | 53 | #source div.Node { 54 | margin-left: 0; 55 | } 56 | 57 | .keyword { 58 | color: maroon; 59 | } 60 | 61 | .Literal { 62 | color: DarkBlue; 63 | } 64 | 65 | #source span.blockSuppress>div { 66 | display: inline; 67 | margin-left: 0; 68 | } 69 | 70 | #source div.indentSuppress { 71 | margin-left: -2em; 72 | } 73 | 74 | .rawSource { 75 | width: 80%; 76 | height: 600px; 77 | } 78 | 79 | #main { 80 | height: 67%; 81 | width: 95%; 82 | position: fixed; 83 | overflow: scroll; 84 | } 85 | 86 | #tree { 87 | position: fixed; 88 | height: 30%; 89 | top: 69%; 90 | width: 95%; 91 | padding: 0; 92 | margin: 0; 93 | border-top: 2px solid #222; 94 | overflow: scroll; 95 | } 96 | -------------------------------------------------------------------------------- /src/printer/lombok/ast/printer/web/ast.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 26 | {{@title}} 27 | 31 | 35 | 38 | 39 | 40 |
41 |

HTML tree for source file: {{@file}}

42 |
43 | {{@body}} 44 |
45 |

Parse Errors

46 | {{@errors}} 47 |

Time taken

48 | {{@timeTaken}} 49 |

raw source

50 | 51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /src/printer/lombok/ast/printer/web/ast.js: -------------------------------------------------------------------------------- 1 | 2 | (function() { 3 | $(function() { 4 | parenHighlighting(); 5 | makeTree(); 6 | }); 7 | 8 | function parenHighlighting() { 9 | $(".open, .clos").hover(function(evt) { 10 | var me = $(evt.currentTarget); 11 | var i = me.attr("id"); 12 | if (!i) return; 13 | i = i.substring(5); 14 | $("#clos_" + i + ", #open_" + i).toggleClass("outlined"); 15 | }); 16 | } 17 | 18 | function makeTree() { 19 | var ctr = 0; 20 | var currentHighlight = $(); 21 | 22 | function makeTreeElement(elem) { 23 | var e = $(elem); 24 | var kind = e.attr("kind"); 25 | var desc = e.attr("description"); 26 | 27 | if (!kind) { 28 | var passon = $(); 29 | e.children().each(function() { 30 | var child = makeTreeElement(this); 31 | $(child).each(function() { 32 | passon = passon.add(this); 33 | }); 34 | }); 35 | return passon; 36 | } 37 | 38 | var txt = e.attr("relation"); 39 | txt = txt ? (txt + ": ") : ""; 40 | txt += kind; 41 | if (desc) txt += " " + desc; 42 | ctr++; 43 | var out = $("
").addClass("expanded").attr("id", "treeNode" + ctr); 44 | out.append($("").addClass("treeNodeDescription").text(txt).hover(function (evt) { 45 | e.toggleClass("highlight"); 46 | })); 47 | e.data("treeKey", "treeNode" + ctr); 48 | var arrowNeeded = false; 49 | e.children().each(function() { 50 | var c = makeTreeElement(this); 51 | if (c) { 52 | if ($(c).size() > 0) arrowNeeded = true; 53 | out.append(c); 54 | } 55 | }); 56 | if (arrowNeeded) { 57 | out.prepend($("").addClass("treeNodeArrow").click(function(evt) { 58 | $(this).parent().toggleClass("expanded").toggleClass("collapsed"); 59 | evt.preventDefault()})); 60 | } else { 61 | out.prepend($("").addClass("treeNodeArrow")); 62 | out.addClass("leaf"); 63 | } 64 | return out; 65 | } 66 | 67 | $("#source>.Node").each(function() { 68 | var elem = makeTreeElement(this); 69 | if (elem) $("#tree").append(elem); 70 | }); 71 | 72 | var $tree = $("#tree"); 73 | 74 | $("#source .Node").mouseover(function(evt) { 75 | var key = evt.currentTarget ? $(evt.currentTarget).data("treeKey") : ""; 76 | if (!key) return; 77 | evt.stopPropagation(); 78 | currentHighlight.removeClass("highlight"); 79 | currentHighlight = $("#" + key).addClass("highlight"); 80 | }).dblclick(function(evt) { 81 | var key = evt.currentTarget ? $(evt.currentTarget).data("treeKey") : ""; 82 | if (!key) return; 83 | evt.stopPropagation(); 84 | var t = $("#" + key); 85 | t.parents(".collapsed").removeClass("collapsed").addClass("expanded"); 86 | var s = t.offset().top - $tree.offset().top; 87 | $tree.animate({scrollTop: "+=" + s + "px"}, 250); 88 | }); 89 | } 90 | })(); 91 | 92 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/CopyMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Tells the template framework to generate a method in the class to be generated that simply wraps around the annotated method. 31 | * 32 | * Normally the generated method is not static, and the node instance is passed as first parameter to your annotated static method.
33 | * However, you may also set {@code isStatic} to true, in which case the generated method will also be static and the instance is not 34 | * passed along as first parameter. 35 | */ 36 | @Retention(RetentionPolicy.SOURCE) 37 | @Target(ElementType.METHOD) 38 | public @interface CopyMethod { 39 | String accessModifier() default "public"; 40 | boolean isStatic() default false; 41 | } 42 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/ForcedType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | /** 25 | * Flag interface which tells the template system that this particular field must always be of the right type and does not come in an off-type flavour. 26 | */ 27 | public @interface ForcedType { 28 | } 29 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/GenerateAstNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Tells the templating system to take the annotated type and use it to generate a {@link lombok.ast.AbstractNode} subclass. 31 | *

32 | * See the other annotations in this package for the various ways you can configure the way the class is generated. 33 | *

34 | * Each field in the class is treated as a subnode. Any field name may end in a number, in which case that number indicates its relative ordering to the other fields. 35 | * unnumbered fields are considered to have order number '0'. Fields with the same order number are compared lexically. The generated {@code accept} method will for example 36 | * walk through the fields in this order. 37 | *

38 | */ 39 | @Retention(RetentionPolicy.SOURCE) 40 | @Target(ElementType.TYPE) 41 | public @interface GenerateAstNode { 42 | /** 43 | * By default AST nodes extend {@link lombok.ast.AbstractNode}, but you can pick a more specific subclass if you'd like. 44 | */ 45 | String extending() default ""; 46 | 47 | /** 48 | * List any interfaces this node is to implement. 49 | */ 50 | Class[] implementing() default {}; 51 | 52 | /** 53 | * A nifty feature that treats members in any listed type as virtually part of this node as well. You can include fields as well as 54 | * methods annotated with {@code @CopyMethod} in the mixed in types. Types in the original class (the one annotated with this {@code @GenerateAstNode} 55 | * annotation) win out over duplicates - like overriding. 56 | */ 57 | Class[] mixin() default {}; 58 | } 59 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/Mandatory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Indicates that a certain field in a {@code lombok.ast.Node} template, as generated by {@link GenerateAstNode} is mandatory. This means that, if the 31 | * field contains {@code null}, the tree is considered not syntactically valid. 32 | */ 33 | @Retention(RetentionPolicy.SOURCE) 34 | @Target(ElementType.FIELD) 35 | public @interface Mandatory { 36 | /** 37 | * Allows you to configure a default value for the marked field. The {@code value} of this annotation should contain 38 | * a string literal that would be parsed as a legal java expression in a java source file. For example: {@code "new Modifiers()"}. 39 | * 40 | * This expression is used as initial value, and also as replacement value if the field is set (via setter) to null. If the field 41 | * is not also marked {@code @NotChildOfNode} the expression will be wrapped with {@code adopt(expr-goes-here)}. 42 | */ 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/NotChildOfNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Indicates that a certain field in a {@code lombok.ast.Node} template, as generated by {@link GenerateAstNode} is not itself a child of {@code lombok.ast.Node}, 31 | * but something else, such as a raw string or an enum. This is generally used for the most specific nodes, such as {@link lombok.ast.Identifier} and 32 | * {@link lombok.ast.IntegralLiteral}. 33 | */ 34 | @Retention(RetentionPolicy.SOURCE) 35 | @Target(ElementType.FIELD) 36 | public @interface NotChildOfNode { 37 | /** 38 | * If you'd like to allow a 'raw form' concept, set both {@code rawFormParser} and {@code rawFormGenerator} to a method name that takes care of parsing/generating 39 | * the raw form to/from its value form. For example, for character literals, The actual string {@code '\n'}, including a literal backslash and quote symbols, 40 | * is the raw form, but the single character 'newline' is the value form. To signal that a raw form is malformed, throw a {@code IllegalArgumentException} 41 | * with the reason as the message. 42 | * 43 | * Either leave both {@code rawFormParser} and {@code rawFormGenerator} blank as they are by default, or set them both. 44 | * 45 | * @see #rawFormGenerator() 46 | */ 47 | String rawFormParser() default ""; 48 | 49 | /** 50 | * @see #rawFormParser() 51 | */ 52 | String rawFormGenerator() default ""; 53 | 54 | /** 55 | * Tells the template generator to generate only a getter for this field. Intended primarily for fields of mutable types. 56 | */ 57 | boolean suppressSetter() default false; 58 | 59 | /** 60 | * Supply some raw java code here that copies the field when the entire node is {@link lombok.ast.Node#copy()}ied. 61 | * By default this is just the {@code this.fieldName} (resulting in {@code copy.fieldName = this.fieldName}). 62 | *

63 | * Example for a list: {@code new java.util.ArrayList(this.fieldName)} 64 | */ 65 | String codeToCopy() default ""; 66 | } 67 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/ParentAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Marks a field in a template to indicate there should be a method in the 'child' class that returns the parent, if this is indeed the parent/child relation. 31 | */ 32 | @Retention(RetentionPolicy.SOURCE) 33 | @Target({ElementType.FIELD, ElementType.METHOD}) 34 | public @interface ParentAccessor { 35 | /** An optional descriptive name for the relation; it will be part of the method name. */ 36 | String value() default ""; 37 | } 38 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/SyntaxCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.template; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Mark a method or a class to indicate a syntactic check. 31 | * 32 | * There are two options:

    33 | *
  • mark a static method that takes 2 arguments; the first a concrete type that subclasses {@link lombok.ast.Node}, the second a {@code List}. 34 | *
  • mark a class containing non-static methods that take 1 argument, a concrete type that subclasses {@link lombok.ast.Node}, which has a constructor that 35 | * takes one parameter, a {@code List}.
36 | *

37 | * Each method should analyse the node (but not its children), and if there are any syntactic problems with it, create {@link lombok.ast.SyntaxProblem} objects 38 | * and add them to the list. 39 | *

40 | * Chaining to children has already been taken care of, as well as the expected type of children, so there's no need to e.g. test if the {@code condition} part of 41 | * an {@code If} node is in fact an instance of {@link lombok.at.Expression}. 42 | */ 43 | @Retention(RetentionPolicy.SOURCE) 44 | @Target({ElementType.METHOD, ElementType.TYPE}) 45 | public @interface SyntaxCheck { 46 | } 47 | -------------------------------------------------------------------------------- /src/template/lombok/ast/template/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains an Annotation Processor that will turn AST Node templates into the actual AST Node source files. 3 | * This package is only required to process the source files; it should not be included in the runtime distribution of {@code lombok.ast}. 4 | *

5 | * To create an AST Node template for a hypothetical node named {@code If}, create a class annotated with {@link GenerateAstNode} whose name 6 | * ends in {@code Template}. Each field then represents an AST field and will automatically be treated as such. Methods are normally ignored 7 | * unless you annotate them with one of the annotations in this package. Specifically: 8 | *

9 | *
{@link lombok.ast.template.CopyMethod}
10 | *
A wrapper method will be generated in the AST Node class that calls this method. It has the same name. Annotated method must be static, 11 | * and the first parameter must be the generated type, e.g. {@code @CopyMethod public static boolean foo(If self, int someOtherParam) ...}.
12 | *
{@link lombok.ast.template.InitialValue}
13 | *
Use to specify a default initial value for the field. By default there is no initial value (JVM default of null).
14 | *
{@link lombok.ast.template.NotChildOfNode}
15 | *
Use to specify a field does not contain an AST Node but a terminal, such as for example the name of an identifier node.
16 | *
{@link lombok.ast.template.SyntaxCheck}
17 | *
Annotates a method to indicate it must be called to check if the node is syntactically valid. Can also be put on a type to indicate all methods in it are syntax checks.
18 | *
{@link lombok.ast.template.Mandatory}
19 | *
Indicates the field would not be {@code null} in a syntactically valid AST tree.
20 | *
21 | * See the javadoc of each annotation for more detailed information about how to use them. 22 | * 23 | * Examples can be found in {@code src/main/lombok/ast/Templates.java}. 24 | */ 25 | package lombok.ast.template; 26 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | reports 2 | 3 | -------------------------------------------------------------------------------- /test/resources/alias/A001_PackageAndImports.java: -------------------------------------------------------------------------------- 1 | package packageDeclaration ; 2 | 3 | import java . util . * ; 4 | import static java.util.Collections .*; 5 | import static java.lang.String . CASE_INSENSITIVE_ORDER; 6 | 7 | 8 | 9 | import java . 10 | net.Socket ; 11 | 12 | -------------------------------------------------------------------------------- /test/resources/alias/A002_BasicEmptyClass.1.java: -------------------------------------------------------------------------------- 1 | class A002_BasicEmptyClass { 2 | 3 | 4 | } -------------------------------------------------------------------------------- /test/resources/alias/A002_BasicEmptyClass.2.java: -------------------------------------------------------------------------------- 1 | class A002_BasicEmptyClass{ 2 | 3 | 4 | 5 | } -------------------------------------------------------------------------------- /test/resources/alias/A002_BasicEmptyClass.3.java: -------------------------------------------------------------------------------- 1 | class A002_BasicEmptyClass{} -------------------------------------------------------------------------------- /test/resources/alias/A003_Initializers.1.java: -------------------------------------------------------------------------------- 1 | class A003_Initializers{ 2 | {}static{ 3 | 4 | 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/alias/A003_Initializers.2.java: -------------------------------------------------------------------------------- 1 | class A003_Initializers{ 2 | { 3 | 4 | } 5 | 6 | static {} 7 | } -------------------------------------------------------------------------------- /test/resources/alias/B001_PrimitiveTypes.java: -------------------------------------------------------------------------------- 1 | class B001_PrimitiveTypes {{int i;boolean z;float f; 2 | double d; 3 | short s; 4 | char c; 5 | byte b; 6 | long l;}} -------------------------------------------------------------------------------- /test/resources/alias/B002_SimpleTypes.java: -------------------------------------------------------------------------------- 1 | class B002_SimpleTypes { 2 | { 3 | String s;java . lang .Number n; 4 | } 5 | } -------------------------------------------------------------------------------- /test/resources/alias/B003_ParameterizedTypes.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | class B003_ParameterizedTypes { 4 | { 5 | java.util.List < ? > list; 6 | java.util.Listlist2; 7 | java.util.Map map; 8 | java.util.Map< 9 | List, List>> map2; 10 | java.util.List extending; 11 | java.util.List< ?super Integer> withSuper; 12 | java.util.List< ? extends List > list3; 13 | java.util.List < ? > [ 14 | ] arrayOfLists ; 15 | } 16 | } -------------------------------------------------------------------------------- /test/resources/alias/B004_TypeVariables.java: -------------------------------------------------------------------------------- 1 | class B004_1{}class B004_2 { 2 | } 3 | 4 | class B004_3< A,B > { 5 | } 6 | 7 | class B004_4&java.util.RandomAccess> { 8 | } 9 | 10 | class B004_5> { 11 | } 12 | 13 | class B004_6> { 14 | } -------------------------------------------------------------------------------- /test/resources/alias/B005_ArrayTypes.java: -------------------------------------------------------------------------------- 1 | class B005_ArrayTypes { 2 | { 3 | int[]simple; 4 | int postfix []; 5 | int[ ] postfix2[ 6 | ] ; 7 | java .lang.String [] oneDimensional ; 8 | java.lang.String[] 9 | [] twoDimensional; 10 | java.lang.String twoDimensional2[][] ; 11 | java.util.List < int [ ] > generified; 12 | java.util . List[]generifiedArraysAreABadIdeaButLegal; 13 | } 14 | } -------------------------------------------------------------------------------- /test/resources/alias/C003_SimpleExpressions.java: -------------------------------------------------------------------------------- 1 | class C003_SimpleExpressions { 2 | { 3 | int primitive0=0; 4 | int primitive1 = primitive0; 5 | int unary1 = - 1; 6 | int unary2 = ~ unary1 ; 7 | int unary3 = ++unary2; 8 | int unary4 = --unary3; 9 | int unary5 = unary2 ++; 10 | int unary6 = unary3--; 11 | int unary7 = + 5; 12 | int unary8 = + unary1; 13 | char 14 | theLetterA = 'b'-1; 15 | int weird =- 'a'; 16 | boolean unary9=!true; 17 | int unary10 =( int )1.1; 18 | int negativeInt = - 10; 19 | float negativeFloat = - 20.5F; 20 | byte negativeByte = - 12; 21 | short negativeShort = - 32000; 22 | long negativeLong=-111111L ; 23 | double negativeDouble=- 8.5 ; 24 | Object constructor = new Object ( ) ; 25 | Object memberAccess = java.lang. String .CASE_INSENSITIVE_ORDER; 26 | int p3a = 5*2; 27 | int p3b =5 / 2; 28 | int p3c = 5 % 2; 29 | int p4a = 5 + 2; 30 | int p4b = 5 - 2; 31 | String p4c = "a" + "b"; 32 | String p4d = "a" + 10; 33 | String p4e = 10 + "b"; 34 | int p5a = 5<<2; 35 | int p5b = 5>>2; 36 | int p5c = 5>>>2; 37 | boolean p6a = 5 < 2; 38 | boolean p6b = 5 > 2; 39 | boolean p6c = 5 <= 2; 40 | boolean p6d = 5 >= 2; 41 | boolean p6e = "a"instanceof String; 42 | boolean p7a = 1== 1; 43 | boolean p7b = 5!= 2; 44 | boolean p8a = true&false; 45 | int p8b = 5 & 2; 46 | boolean p9a = true ^ false; 47 | int p9b = 5 ^ 2; 48 | boolean p10a = true | false; 49 | int p10b = 5 | 2; 50 | boolean p11 = true&&false; 51 | boolean p12 = true || false; 52 | int p13 = true?5:2 ; 53 | boolean p14a = p11 = true; 54 | int p14b = p3a += p3b; 55 | int p14c = p3a -= p3b; 56 | int p14d = p3a *= p3b; 57 | int p14e = p3a /= 4; 58 | int p14f = p3a%=10; 59 | int p14g = p3a <<= p3b; 60 | int p14h = p3a >>= p3b; 61 | int p14i = p3a >>>= p3b; 62 | int p14j = p3a &= p3b; 63 | int p14k = p3a ^= p3b; 64 | int p14l = p3a |= p3b; 65 | } 66 | } -------------------------------------------------------------------------------- /test/resources/alias/C004_ComplexExpressions.java: -------------------------------------------------------------------------------- 1 | class C004_ComplexExpressions { 2 | { 3 | int ex = 1 + 2 + 3 + 4 + 5 + 6; 4 | int brace1 =5+ ( 2+3); 5 | int brace2 = (5 + 2) * 3; 6 | int chained1 = 5+2 + 3; 7 | int chained2 = 5*2 + 3; 8 | int chained3 = 5 * - ( 2 + 3) + ~ 3 -(int)1.1; 9 | double doubleCast = (double )( int )1.1; 10 | int chainedAssign = chained1 = chained2 = chained3; 11 | int bracedAssign = 3 + ( chained1=5); 12 | int chainedCast = ~( int) 1.5; 13 | int bracedCast = ((Object) "foo") . hashCode (); 14 | int chainedTernary = 1==2?10:2== 2 ?1:2; 15 | int bracedTernary = 5 + (1 == 1 ? (2 == 3 ? 5 : 7) : 8); 16 | int multipleAssignments=ex=brace1 = brace2*=chained1+= 10; 17 | int postfixChained = ~brace1++; 18 | double postfixChained2 = (double) brace1++; 19 | int selfAssign = brace1 ; 20 | } 21 | } -------------------------------------------------------------------------------- /test/resources/alias/E001_MethodDeclarations.java: -------------------------------------------------------------------------------- 1 | abstract class E001_MethodDeclarations { 2 | void method ( ) { 3 | } 4 | 5 | abstract void abstractMethod() ; 6 | } -------------------------------------------------------------------------------- /test/resources/alias/E007_ArrayMethodDeclarations.java: -------------------------------------------------------------------------------- 1 | class E004_ArrayMethodDeclarations { 2 | String oneParameter(int one)[] { 3 | return null; 4 | } 5 | 6 | String[] oneParameter2(int one)[] { 7 | return null; 8 | } 9 | 10 | String twoParameters(int one, String two)[] { 11 | return null; 12 | } 13 | 14 | String[] twoParameters2(int one, String two)[] { 15 | return null; 16 | } 17 | 18 | String varArgs(String... two)[] { 19 | return null; 20 | } 21 | 22 | String[] varArgs2(String... two)[] { 23 | return null; 24 | } 25 | 26 | String varArgsArray(String[]... two)[] { 27 | return null; 28 | } 29 | 30 | String[] varArgsArray2(String[]... two)[] { 31 | return null; 32 | } 33 | 34 | String simpleGenericParameter(int one, String two, java.util.List three)[] { 35 | return null; 36 | } 37 | 38 | String[] simpleGenericParameter2(int one, String two, java.util.List three)[] { 39 | return null; 40 | } 41 | 42 | public String publicMethod(int one, String two, java.util.List three, boolean isPublic)[] { 43 | return null; 44 | } 45 | 46 | public String[] publicMethod2(int one, String two, java.util.List three, boolean isPublic)[] { 47 | return null; 48 | } 49 | 50 | String typeArgumentExtends(java.util.List list)[] { 51 | return null; 52 | } 53 | 54 | String[] typeArgumentExtends2(java.util.List list)[] { 55 | return null; 56 | } 57 | 58 | String typeArgumentSuper(Class clazz)[] { 59 | return null; 60 | } 61 | 62 | String[] typeArgumentSuper2(Class clazz)[] { 63 | return null; 64 | } 65 | 66 | R returnTypeParameter()[] { 67 | return null; 68 | } 69 | 70 | R[] returnTypeParameter2()[] { 71 | return null; 72 | } 73 | 74 | R returnAndParameterTypeParameter(T arg)[] { 75 | return null; 76 | } 77 | 78 | R[] returnAndParameterTypeParameter2(T arg)[] { 79 | return null; 80 | } 81 | 82 | String throwsMethod()[] throws Exception { 83 | return null; 84 | } 85 | 86 | String[] throwsMethod2()[] throws Exception { 87 | return null; 88 | } 89 | 90 | R throwsReturnsAndParameter(T arg)[] throws E, NullPointerException { 91 | return null; 92 | } 93 | 94 | R[] throwsReturnsAndParameter2(T arg)[] throws E, NullPointerException { 95 | return null; 96 | } 97 | } -------------------------------------------------------------------------------- /test/resources/alias/F001_Annotations.java: -------------------------------------------------------------------------------- 1 | class F001_Annotations { 2 | { 3 | @SuppressWarnings("all") 4 | int i = 5; 5 | @SuppressWarnings({"all", "non-existent"}) 6 | int more = 5; 7 | @SuppressWarnings(value = "all") 8 | int single = 5; 9 | @SuppressWarnings(value = {"all", "non-existent"}) 10 | int full = 5; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return null; 16 | } 17 | 18 | @SuppressWarnings("serial") 19 | @Override() 20 | public int hashCode() { 21 | return 0; 22 | } 23 | 24 | @ SuppressWarnings ( "all" ) 25 | void foo ( ) { 26 | } 27 | } -------------------------------------------------------------------------------- /test/resources/alias/H003_Annotations.java: -------------------------------------------------------------------------------- 1 | public @ interface H003_Annotations { 2 | int value() default 10; 3 | } 4 | 5 | @ java . lang.annotation.Target ( java.lang.annotation.ElementType . TYPE ) 6 | @ interface ComplexAnnotation { 7 | int x = 10; 8 | 9 | String v1()[]; 10 | 11 | Class clazz() default Object.class; 12 | 13 | Class < ? > [ ] clazzArray ( ) default { } ; 14 | 15 | public abstract H003_Annotations ann(); 16 | 17 | String v2 ( ) [ ] default { "a" , "b" , "c" } ; 18 | } -------------------------------------------------------------------------------- /test/resources/alias/ZComplex1.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import java.util.*; 4 | import static java.util.Collections.sort; 5 | import java.io.File; 6 | 7 | public class ZComplex1 { 8 | public void test() { 9 | java.lang.String x = null; 10 | int z = 0x20; 11 | float a = 1.234F; 12 | java.util.List[] q; 13 | } 14 | } 15 | 16 | class ZComplex1Extra { 17 | { 18 | int x = 10 + 20 + 30; 19 | if (x >>> 2 < 10) { 20 | System.out.println("Whoa!"); 21 | } else System.exit(0); 22 | if (x >>> 2 < 10) { 23 | System.out.println("Whoa!"); 24 | } 25 | int y = 10 + 20 + 30; 26 | int z =( 10+ 20 ) + 30; 27 | int a = 10 + (20 + 30); 28 | int b = 10 + 20 * 30; 29 | int c = (10 + 20) * 30; 30 | boolean d = "" + b instanceof CharSequence; 31 | boolean g = a < 0; 32 | boolean e = a > 0 ? true : b < 0 ? true : false; 33 | boolean f = (a > 0 ? true : b < 0) ? true : false; 34 | 35 | y++; 36 | 37 | for ( int i = 0, j=1 ; i < 10; i++, j++ ) for (String name : Collections.emptyList()) { 38 | System.out.println(i); 39 | } 40 | 41 | try { 42 | something(); 43 | } catch (Exception ex) { 44 | somethingElse(); 45 | } catch (java.lang.Throwable ex) { 46 | somethingElseEntirely(); 47 | } finally { 48 | nothing(); 49 | } 50 | } 51 | 52 | void something() { 53 | } 54 | 55 | void somethingElse() 56 | {} 57 | 58 | void somethingElseEntirely() {} 59 | 60 | void nothing() { 61 | 62 | } 63 | 64 | static { 65 | int y = 20; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/resources/idempotency/A001_PackageAndImports.java: -------------------------------------------------------------------------------- 1 | package packageDeclaration; 2 | 3 | import java.util.*; 4 | import static java.util.Collections.*; 5 | import static java.lang.String.CASE_INSENSITIVE_ORDER; 6 | import java.net.Socket; -------------------------------------------------------------------------------- /test/resources/idempotency/A002_BasicEmptyClass.java: -------------------------------------------------------------------------------- 1 | class A002_BasicEmptyClass { 2 | } -------------------------------------------------------------------------------- /test/resources/idempotency/A003_EmptyStatements.java: -------------------------------------------------------------------------------- 1 | public class A003_EmptyStatements { 2 | { 3 | ; 4 | } 5 | 6 | ; 7 | } 8 | 9 | ; -------------------------------------------------------------------------------- /test/resources/idempotency/A003_Initializers.java: -------------------------------------------------------------------------------- 1 | class A003_Initializers { 2 | { 3 | } 4 | 5 | static { 6 | } 7 | } -------------------------------------------------------------------------------- /test/resources/idempotency/A004_MultipleClasses.java: -------------------------------------------------------------------------------- 1 | class A004_1 { 2 | } 3 | 4 | class A004_2 { 5 | } -------------------------------------------------------------------------------- /test/resources/idempotency/B001_PrimitiveTypes.java: -------------------------------------------------------------------------------- 1 | class B001_PrimitiveTypes { 2 | { 3 | int i; 4 | boolean z; 5 | float f; 6 | double d; 7 | short s; 8 | char c; 9 | byte b; 10 | long l; 11 | } 12 | } -------------------------------------------------------------------------------- /test/resources/idempotency/B002_SimpleTypes.java: -------------------------------------------------------------------------------- 1 | class B002_SimpleTypes { 2 | { 3 | String s; 4 | java.lang.Number n; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/B003_ParameterizedTypes.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | class B003_ParameterizedTypes { 4 | { 5 | java.util.List list; 6 | java.util.List list2; 7 | java.util.Map map; 8 | java.util.Map, List>> map2; 9 | java.util.List extending; 10 | java.util.List withSuper; 11 | java.util.List> list3; 12 | java.util.List[] arrayOfLists; 13 | } 14 | } -------------------------------------------------------------------------------- /test/resources/idempotency/B004_TypeVariables.java: -------------------------------------------------------------------------------- 1 | class B004_1 { 2 | } 3 | 4 | class B004_2 { 5 | } 6 | 7 | class B004_3 { 8 | } 9 | 10 | class B004_4 & java.util.RandomAccess> { 11 | } 12 | 13 | class B004_5> { 14 | } 15 | 16 | class B004_6> { 17 | } -------------------------------------------------------------------------------- /test/resources/idempotency/B005_ArrayTypes.java: -------------------------------------------------------------------------------- 1 | class B005_ArrayTypes { 2 | { 3 | int[] simple; 4 | int postfix[]; 5 | int[] postfix2[]; 6 | java.lang.String[] oneDimensional; 7 | java.lang.String[][] twoDimensional; 8 | java.lang.String twoDimensional2[][]; 9 | java.util.List generified; 10 | java.util.List[] generifiedArraysAreABadIdeaButLegal; 11 | } 12 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C001_NumberLiterals.java: -------------------------------------------------------------------------------- 1 | class C001_NumberLiterals { 2 | { 3 | int x = 0; 4 | int y = 1000000; 5 | long z = 100000000000L; 6 | int a = 0x1fa1; 7 | int b = 0100; 8 | double c = 100.0; 9 | double d = 0.0; 10 | double e = 123e10; 11 | double f = 123e-10; 12 | double g = 123e+10; 13 | double h = 0x1p1; 14 | float i = 123F; 15 | float j = 0xap-1F; 16 | boolean b1 = true; 17 | boolean b2 = false; 18 | Object o = null; 19 | } 20 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C002_ExtremeIntegralLiterals.java: -------------------------------------------------------------------------------- 1 | class C002_ExtremeIntegralLiterals { 2 | { 3 | int minHexInt = 0x80000000; 4 | int minOctInt = 020000000000; 5 | int maxHexInt = 0x7fffffff; 6 | int maxOctInt = 017777777777; 7 | int minusOneHexInt = 0xffffffff; 8 | int minusOneOctInt = 037777777777; 9 | int minDecInt = -2147483648; 10 | long minHexLong = 0x8000000000000000L; 11 | long minOctLong = 01000000000000000000000L; 12 | long maxHexLong = 0x7fffffffffffffffL; 13 | long maxOctLong = 0777777777777777777777L; 14 | long minusOneHexLong = 0xffffffffffffffffL; 15 | long minusOneOctLong = 01777777777777777777777L; 16 | long minDecLong = -9223372036854775808L; 17 | } 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C002_Parentheses.java: -------------------------------------------------------------------------------- 1 | class C002_Parentheses { 2 | { 3 | int x = 10; 4 | int y = (x); 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C002_TextLiterals.java: -------------------------------------------------------------------------------- 1 | class C002_TextLiterals { 2 | { 3 | char a = 'a'; 4 | char b = '\n'; 5 | char c = '\t'; 6 | char d = '\0'; 7 | char e = '\10'; 8 | char f = '\\'; 9 | char g = '\''; 10 | String z = ""; 11 | String y = "Simple string"; 12 | String w = "With escapes \\ \" \n \t \0 \7 \10 \11 \f \r "; 13 | String v = ";"; 14 | } 15 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C003_Casts.java: -------------------------------------------------------------------------------- 1 | class C003_Casts { 2 | { 3 | Object foo; 4 | Object foo2 = (Object) null; 5 | Object foo3 = (java.lang.Object) null; 6 | Object foo4 = (java.util.List) null; 7 | Object foo5 = (String[]) null; 8 | Object foo6 = (java.lang.String[]) null; 9 | Object foo7 = (java.util.List[]) null; 10 | } 11 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C003_SimpleExpressions.java: -------------------------------------------------------------------------------- 1 | class C003_SimpleExpressions { 2 | { 3 | int primitive0 = 0; 4 | int primitive1 = primitive0; 5 | int unary1 = -1; 6 | int unary2 = ~unary1; 7 | int unary3 = ++unary2; 8 | int unary4 = --unary3; 9 | int unary5 = unary2++; 10 | int unary6 = unary3--; 11 | int unary7 = +5; 12 | int unary8 = +unary1; 13 | char theLetterA = 'b' - 1; 14 | int weird = -'a'; 15 | boolean unary9 = !true; 16 | int unary10 = (int) 1.1; 17 | int negativeInt = -10; 18 | float negativeFloat = -20.5F; 19 | byte negativeByte = -12; 20 | short negativeShort = -32000; 21 | long negativeLong = -111111L; 22 | double negativeDouble = -8.5; 23 | Object constructor = new Object(); 24 | Object memberAccess = java.lang.String.CASE_INSENSITIVE_ORDER; 25 | int p3a = 5 * 2; 26 | int p3b = 5 / 2; 27 | int p3c = 5 % 2; 28 | int p4a = 5 + 2; 29 | int p4b = 5 - 2; 30 | String p4c = "a" + "b"; 31 | String p4d = "a" + 10; 32 | String p4e = 10 + "b"; 33 | int p5a = 5 << 2; 34 | int p5b = 5 >> 2; 35 | int p5c = 5 >>> 2; 36 | boolean p6a = 5 < 2; 37 | boolean p6b = 5 > 2; 38 | boolean p6c = 5 <= 2; 39 | boolean p6d = 5 >= 2; 40 | boolean p6e = "a" instanceof String; 41 | boolean p7a = 1 == 1; 42 | boolean p7b = 5 != 2; 43 | boolean p8a = true & false; 44 | int p8b = 5 & 2; 45 | boolean p9a = true ^ false; 46 | int p9b = 5 ^ 2; 47 | boolean p10a = true | false; 48 | int p10b = 5 | 2; 49 | boolean p11 = true && false; 50 | boolean p12 = true || false; 51 | int p13 = true ? 5 : 2; 52 | boolean p14a = p11 = true; 53 | int p14b = p3a += p3b; 54 | int p14c = p3a -= p3b; 55 | int p14d = p3a *= p3b; 56 | int p14e = p3a /= 4; 57 | int p14f = p3a %= 10; 58 | int p14g = p3a <<= p3b; 59 | int p14h = p3a >>= p3b; 60 | int p14i = p3a >>>= p3b; 61 | int p14j = p3a &= p3b; 62 | int p14k = p3a ^= p3b; 63 | int p14l = p3a |= p3b; 64 | } 65 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C003_StringConcatExpressions.java: -------------------------------------------------------------------------------- 1 | class C003_StringConcatExpressions { 2 | { 3 | String a = "foo" + "bar"; 4 | String b = "" + "foo" + "bar" + "baz" + 10; 5 | String b2 = ("" + "foo" + "bar" + "baz") + 10; 6 | String c = 10 + "" + "a" + "foo"; 7 | String c2 = 10 + ("" + "a" + "foo"); 8 | String c3 = "a" + "b" + ("c" + "d"); 9 | String c4 = ("a" + "b") + "c" + "d"; 10 | String c5 = "a" + ("b" + "c") + "d"; 11 | String c6 = "a" + "b" + "c" + "d"; 12 | String c7 = ("a" + "b" + "c") + "d" + "e"; 13 | String d = "foo" + "bar" + "baz"; 14 | boolean e = "" + "a" + "foo" instanceof String; 15 | String e2 = "foo" + ("bar"); 16 | String f = new String("a" + "b" + "c"); 17 | f += "d" + "e" + "f"; 18 | String g = f += "d" + "e" + "f"; 19 | boolean h = "d" + "e" + "f" == "g"; 20 | String i = (String) "a" + "b" + "c"; 21 | String j = "a" + "b" + 'c'; 22 | String k = "a" + 'b' + "c"; 23 | int l = 'a' + 'b' + 'c'; 24 | } 25 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C004_ComplexExpressions.java: -------------------------------------------------------------------------------- 1 | class C004_ComplexExpressions { 2 | { 3 | int ex = 1 + 2 + 3 + 4 + 5 + 6; 4 | int brace1 = 5 + (2 + 3); 5 | int brace2 = (5 + 2) * 3; 6 | int chained1 = 5 + 2 + 3; 7 | int chained2 = 5 * 2 + 3; 8 | int chained3 = 5 * -(2 + 3) + ~3 - (int) 1.1; 9 | double doubleCast = (double) (int) 1.1; 10 | int chainedAssign = chained1 = chained2 = chained3; 11 | int bracedAssign = 3 + (chained1 = 5); 12 | int chainedCast = ~(int) 1.5; 13 | int bracedCast = ((Object) "foo").hashCode(); 14 | int chainedTernary = 1 == 2 ? 10 : 2 == 2 ? 1 : 2; 15 | int bracedTernary = 5 + (1 == 1 ? (2 == 3 ? 5 : 7) : 8); 16 | int multipleAssignments = ex = brace1 = brace2 *= chained1 += 10; 17 | int postfixChained = ~brace1++; 18 | double postfixChained2 = (double) brace1++; 19 | int selfAssign = brace1; 20 | } 21 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C005_ArrayInitialization.java: -------------------------------------------------------------------------------- 1 | class C005_ArrayInitialization { 2 | { 3 | String[] names = {"Reinier", "Roel"}; 4 | String[] names2 = new String[] {"Reinier", "Roel"}; 5 | String[] names3 = new java.lang.String[] {"Reinier", "Roel"}; 6 | int[] sized = new int[0]; 7 | int[][] sizedTwoDimensions = new int[0][0]; 8 | int[][] sizedTwoDimensions2 = new int[0][]; 9 | int[][][] sizedThreeDimensions = new int[0][][]; 10 | int[][] empty = {{}}; 11 | int[][] ints = new int[][] {{}}; 12 | int[] singleInts = new int[] {}; 13 | int more[] = {}; 14 | int[] more2[] = {{}}; 15 | } 16 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C006_Parens.java: -------------------------------------------------------------------------------- 1 | class C006_Parens { 2 | { 3 | int brace1 = ((5 + (2 + 3))); 4 | int brace2 = (5 + 2) * 3; 5 | int chained1 = (5 + 2) + 3; 6 | int chained2 = ((5 * 2) + 3); 7 | int chained3 = 5 * (-((2) + 3)) + (~(3)) - (int) 1.1; 8 | double doubleCast = (double) (((int) (1.1))); 9 | int chainedAssign = ((chained1 = (chained2 = chained3))); 10 | int bracedAssign = 3 + (chained1 = 5); 11 | int chainedCast = ~((int) 1.5); 12 | int bracedCast = (((Object) "foo")).hashCode(); 13 | int chainedTernary = (1 == 2) ? 10 : (2 == 2 ? 1 : (2)); 14 | int bracedTernary = 5 + (1 == 1 ? (2 == 3 ? 5 : 7) : 8); 15 | int postfixChained = ~(brace1++); 16 | double postfixChained2 = ((double) (brace1++)); 17 | } 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C007_ThisLiteral.java: -------------------------------------------------------------------------------- 1 | class C007_ThisLiteral { 2 | class Inner { 3 | { 4 | java.lang.String str = ""; 5 | Object a = this; 6 | Object b = C007_ThisLiteral.this; 7 | Object c = C007_ThisLiteral.Inner.this; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C008_ClassLiterals.java: -------------------------------------------------------------------------------- 1 | class C008_ClassLiterals { 2 | { 3 | Object o = String.class; 4 | Object p = java.lang.Object.class; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C009_ArrayAccess.java: -------------------------------------------------------------------------------- 1 | class C009_ArrayAccess { 2 | { 3 | int[] x = new int[10]; 4 | x[9] = 5; 5 | int y = x[5]; 6 | int[][] z = new int[2][1]; 7 | z[0][0] = 1; 8 | ((z)[0])[0] = 1; 9 | int b = ((z)[0])[0]; 10 | int c = z[0][0]; 11 | } 12 | } -------------------------------------------------------------------------------- /test/resources/idempotency/C010_CombinedBinaryExpressions.java: -------------------------------------------------------------------------------- 1 | class C010_CombinedBinaryExpressions { 2 | { 3 | int five = 5; 4 | int ten = 10; 5 | int binaryOrCombined = 20 | five | ten; 6 | int binaryPlusCombined = 20 + five + ten; 7 | int veryLongCombined = five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten; 8 | int veryVeryLongCombined = five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten + five + ten; 9 | } 10 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D001_BasicStatements.java: -------------------------------------------------------------------------------- 1 | class D001_BasicStatements { 2 | { 3 | int a = 10; 4 | { 5 | a++; 6 | --a; 7 | "a".toString(); 8 | a = 20; 9 | ++a; 10 | a--; 11 | new Object(); 12 | } 13 | ; 14 | ; 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D001_VariableDeclarations.java: -------------------------------------------------------------------------------- 1 | class D001_VariableDeclarations { 2 | { 3 | boolean c; 4 | boolean[] c1; 5 | boolean c2[]; 6 | String[][] allNames = {{"Reinier", "Roel"}}; 7 | String x, y; 8 | final int a = 10, b[] = {20}; 9 | int m, n[], o; 10 | boolean s[], t[]; 11 | } 12 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D001_VariableDeclarationsEclipseHasBugs.java: -------------------------------------------------------------------------------- 1 | class D001_VariableDeclarations { 2 | { 3 | java.lang.String[] f, g[], h[][], i, j[], k; 4 | int[] p[], q, r[]; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Assert.java: -------------------------------------------------------------------------------- 1 | class D002_Assert { 2 | { 3 | assert 1 < 5; 4 | assert false: "This assert will fail"; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_AssertInner.java: -------------------------------------------------------------------------------- 1 | class D002_AssertInner { 2 | static class Inner { 3 | { 4 | assert 1 < 5; 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Do.java: -------------------------------------------------------------------------------- 1 | class D002_Do { 2 | { 3 | do { 4 | continue; 5 | } while (System.currentTimeMillis() > 0); 6 | do { 7 | break; 8 | } while (System.currentTimeMillis() < 0); 9 | int x = 0; 10 | do { 11 | x++; 12 | } while (x < 10); 13 | } 14 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_ForEach.java: -------------------------------------------------------------------------------- 1 | class D002_ForEach { 2 | { 3 | String x; 4 | for (Object o : java.util.Collections.emptyList()) { 5 | } 6 | String[][] allNames = {{"Reinier", "Roel"}}; 7 | for (String[] names : allNames) { 8 | for (String name : names) { 9 | x = name; 10 | } 11 | } 12 | for (String names[] : allNames) { 13 | for (String name : names) { 14 | x = name; 15 | } 16 | } 17 | Object object; 18 | for (Object o : java.util.Collections.emptyList()) object = o; 19 | } 20 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_If.java: -------------------------------------------------------------------------------- 1 | class D002_If { 2 | { 3 | if (1 < 2) ; 4 | if (1 < 2) { 5 | } 6 | if (1 < 2) ; else ; 7 | if (1 < 2) { 8 | } else { 9 | } 10 | if (1 < 2) ; else if (3 < 1) ; 11 | if (1 < 2) ; else if (3 < 1) ; else ; 12 | if (1 < 2) { 13 | } else if (3 < 1) { 14 | } 15 | if (1 < 2) { 16 | } else if (3 < 1) { 17 | } else { 18 | } 19 | if (1 < 2) { 20 | } else if (3 < 1) { 21 | } else if (4 < 1) { 22 | } else { 23 | } 24 | if (1 < 3) { 25 | if (3 < 1) { 26 | } else { 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Label.java: -------------------------------------------------------------------------------- 1 | class D002_Label { 2 | { 3 | int i = 5; 4 | label1: 5 | i++; 6 | label2: 7 | ; 8 | label3: 9 | label4: 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_StandardFor.java: -------------------------------------------------------------------------------- 1 | class D002_StandardFor { 2 | { 3 | for (int i = 0; i < 10; i++) { 4 | continue; 5 | } 6 | for (int i = 0, j = 0; i < 10; i++, j++) { 7 | break; 8 | } 9 | int a = 10; 10 | for (a = 10, "a".toString(), a++;;) { 11 | break; 12 | } 13 | for (;;) { 14 | break; 15 | } 16 | for (;;) { 17 | int foo = 0; 18 | break; 19 | } 20 | for (;;) { 21 | { 22 | int foo = 0; 23 | break; 24 | } 25 | } 26 | for (int i = 0; i < 3; i++) System.out.println(i); 27 | } 28 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Switch.java: -------------------------------------------------------------------------------- 1 | class D002_Switch { 2 | { 3 | int i = 0; 4 | switch (i) { 5 | } 6 | switch (i) { 7 | default: 8 | ; 9 | } 10 | switch (i) { 11 | case 1: 12 | ; 13 | default: 14 | ; 15 | } 16 | switch (i) { 17 | default: 18 | ; 19 | case 1: 20 | ; 21 | } 22 | switch (i) { 23 | case 1: 24 | { 25 | ; 26 | } 27 | default: 28 | { 29 | } 30 | } 31 | switch (i) { 32 | case 1: 33 | { 34 | break; 35 | } 36 | default: 37 | { 38 | break; 39 | } 40 | } 41 | switch (i) { 42 | case 1: 43 | int j = 3; 44 | } 45 | switch (i) { 46 | case 1: 47 | { 48 | int j = 3; 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Synchronized.java: -------------------------------------------------------------------------------- 1 | class D002_Synchronized { 2 | { 3 | synchronized (this) { 4 | } 5 | int i = 0; 6 | synchronized (this) { 7 | i++; 8 | } 9 | synchronized (new int[0]) { 10 | i++; 11 | } 12 | synchronized (new int[0]) { 13 | synchronized (new int[0]) { 14 | i++; 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_Try.java: -------------------------------------------------------------------------------- 1 | class D002_Try { 2 | { 3 | try { 4 | } finally { 5 | } 6 | try { 7 | } catch (Exception e) { 8 | } 9 | try { 10 | } catch (NullPointerException e) { 11 | } catch (Exception e) { 12 | } 13 | try { 14 | } catch (NullPointerException e) { 15 | } catch (Exception e) { 16 | } finally { 17 | } 18 | int i = 0; 19 | try { 20 | i++; 21 | } finally { 22 | i++; 23 | } 24 | try { 25 | i++; 26 | } catch (Exception e) { 27 | i++; 28 | } 29 | try { 30 | i++; 31 | } catch (NullPointerException e) { 32 | i++; 33 | } catch (Exception e) { 34 | i++; 35 | } 36 | try { 37 | i++; 38 | } catch (NullPointerException e) { 39 | i++; 40 | throw e; 41 | } catch (Exception e) { 42 | i++; 43 | } finally { 44 | i++; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D002_While.java: -------------------------------------------------------------------------------- 1 | class D002_While { 2 | { 3 | while (System.currentTimeMillis() < 0) { 4 | continue; 5 | } 6 | while (System.currentTimeMillis() > 0) { 7 | break; 8 | } 9 | int i = 0; 10 | while (i < 10) i++; 11 | i = 0; 12 | while (i < 10) { 13 | i++; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /test/resources/idempotency/D003_LabelledBreaksAndContinues.java: -------------------------------------------------------------------------------- 1 | class D003_LabelledBreaksAndContinues { 2 | { 3 | label1: 4 | do { 5 | continue label1; 6 | } while (System.currentTimeMillis() > 0); 7 | label2: 8 | do { 9 | break label2; 10 | } while (System.currentTimeMillis() < 0); 11 | } 12 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E001_ConstructorDeclarations.java: -------------------------------------------------------------------------------- 1 | class E001_ConstructorDeclarations { 2 | E001_ConstructorDeclarations() { 3 | } 4 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E001_MethodDeclarations.java: -------------------------------------------------------------------------------- 1 | abstract class E001_MethodDeclarations { 2 | void method() { 3 | } 4 | 5 | abstract void abstractMethod(); 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E002_ModifiersConstructorDeclarations.java: -------------------------------------------------------------------------------- 1 | class E001_ModifiersConstructorDeclarations1 { 2 | public E001_ModifiersConstructorDeclarations1() { 3 | } 4 | } 5 | 6 | class E001_ModifiersConstructorDeclarations2 { 7 | protected E001_ModifiersConstructorDeclarations2() { 8 | } 9 | } 10 | 11 | class E001_ModifiersConstructorDeclarations3 { 12 | E001_ModifiersConstructorDeclarations3() { 13 | } 14 | } 15 | 16 | class E001_ModifiersConstructorDeclarations4 { 17 | private E001_ModifiersConstructorDeclarations4() { 18 | } 19 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E002_ModifiersMethodDeclaration.java: -------------------------------------------------------------------------------- 1 | class E002_ModifiersMethodDeclatations { 2 | public int publicInt() { 3 | return 5; 4 | } 5 | 6 | protected int protectedInt() { 7 | return 5; 8 | } 9 | 10 | int defaultInt() { 11 | return 5; 12 | } 13 | 14 | private int privateInt() { 15 | return 5; 16 | } 17 | 18 | public final int publicFinalInt() { 19 | return 5; 20 | } 21 | 22 | final int defaultFinalInt() { 23 | return 5; 24 | } 25 | 26 | public synchronized int publicSynchronizedInt() { 27 | return 5; 28 | } 29 | 30 | synchronized int defaultSynchronizedInt() { 31 | return 5; 32 | } 33 | 34 | public final synchronized int publicFinalSynchronizedInt() { 35 | return 5; 36 | } 37 | 38 | final synchronized int defaultFinalSynchronizedInt() { 39 | return 5; 40 | } 41 | 42 | public static int publicStaticInt() { 43 | return 5; 44 | } 45 | 46 | static int defaultStaticInt() { 47 | return 5; 48 | } 49 | 50 | public static final int publicStaticFinalInt() { 51 | return 5; 52 | } 53 | 54 | static final int defaultStaticFinalInt() { 55 | return 5; 56 | } 57 | 58 | public static final synchronized int publicStaticFinalSynchronizedInt() { 59 | return 5; 60 | } 61 | 62 | static final synchronized int defaultStaticFinalSynchronizedInt() { 63 | return 5; 64 | } 65 | 66 | public native int publicNativeInt(); 67 | 68 | native int defaultNativeInt(); 69 | 70 | public strictfp int publicStrictFpInt() { 71 | return 5; 72 | } 73 | 74 | strictfp int defaultStrictFpInt() { 75 | return 5; 76 | } 77 | 78 | public static final synchronized strictfp int publicLotsInt() { 79 | return 5; 80 | } 81 | 82 | static final synchronized strictfp int defaultLotsInt() { 83 | return 5; 84 | } 85 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E003_ThrowsConstructorDeclarations.java: -------------------------------------------------------------------------------- 1 | class E003_ThrowsConstructorDeclarations1 { 2 | public E003_ThrowsConstructorDeclarations1() throws Throwable { 3 | } 4 | } 5 | 6 | class E003_ThrowsConstructorDeclarations2 { 7 | E003_ThrowsConstructorDeclarations2() throws Throwable { 8 | } 9 | } 10 | 11 | class E003_ThrowsConstructorDeclarations3 { 12 | public E003_ThrowsConstructorDeclarations3() throws NullPointerException, NumberFormatException { 13 | } 14 | } 15 | 16 | class E003_ThrowsConstructorDeclarations4 { 17 | E003_ThrowsConstructorDeclarations4() throws NullPointerException, NumberFormatException { 18 | } 19 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E003_ThrowsMethodDeclaration.java: -------------------------------------------------------------------------------- 1 | abstract class E003_ThrowsMethodDeclaration { 2 | public int publicThrowable() throws Throwable { 3 | return 5; 4 | } 5 | 6 | int defaultThrowable() throws Throwable { 7 | return 5; 8 | } 9 | 10 | public abstract int publicAbstractThrowable() throws Throwable; 11 | 12 | abstract int defaultAbstractThrowable() throws Throwable; 13 | 14 | public int publicThrowables() throws NullPointerException, NumberFormatException { 15 | return 5; 16 | } 17 | 18 | int defaultThrowables() throws NullPointerException, NumberFormatException { 19 | return 5; 20 | } 21 | 22 | public abstract int publicAbstractThrowables() throws NullPointerException, NumberFormatException; 23 | 24 | abstract int defaultAbstractThrowables() throws NullPointerException, NumberFormatException; 25 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E004_ParameterConstructorDeclarations.java: -------------------------------------------------------------------------------- 1 | class E004_ParameterConstructorDeclarations { 2 | E004_ParameterConstructorDeclarations(int one) { 3 | } 4 | 5 | E004_ParameterConstructorDeclarations(int one, String two) { 6 | } 7 | 8 | E004_ParameterConstructorDeclarations(int one, String two, java.util.List three) { 9 | } 10 | 11 | public E004_ParameterConstructorDeclarations(int one, String two, java.util.List three, boolean isPublic) { 12 | } 13 | 14 | E004_ParameterConstructorDeclarations(java.util.List list) { 15 | } 16 | 17 | E004_ParameterConstructorDeclarations(Class clazz) { 18 | } 19 | 20 | E004_ParameterConstructorDeclarations(String... args) { 21 | } 22 | 23 | E004_ParameterConstructorDeclarations(int one, String... args) { 24 | } 25 | 26 | E004_ParameterConstructorDeclarations(String[]... args) { 27 | } 28 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E004_ParameterMethodDeclarations.java: -------------------------------------------------------------------------------- 1 | class E004_ParameterMethodDeclarations { 2 | void oneParameter(int one) { 3 | } 4 | 5 | void twoParameters(int one, String two) { 6 | } 7 | 8 | void simpleGenericParameter(int one, String two, java.util.List three) { 9 | } 10 | 11 | public void publicMethod(int one, String two, java.util.List three, boolean isPublic) { 12 | } 13 | 14 | void typeArgumentExtends(java.util.List list) { 15 | } 16 | 17 | void typeArgumentSuper(Class clazz) { 18 | } 19 | 20 | void array(int[] one) { 21 | } 22 | 23 | void twoDimensionalArray(int[] one[]) { 24 | } 25 | 26 | void varArgsOneParameter(String... two) { 27 | } 28 | 29 | void varArgsMoreParameters(int one, String... two) { 30 | } 31 | 32 | void varArgsArray(int one, String[]... two) { 33 | } 34 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E005_TypeParametersConstructorDeclaration.java: -------------------------------------------------------------------------------- 1 | class E005_TypeParametersConstructorDeclaration { 2 | E005_TypeParametersConstructorDeclaration(T arg) { 3 | } 4 | 5 | E005_TypeParametersConstructorDeclaration(int type, T arg) { 6 | } 7 | 8 | E005_TypeParametersConstructorDeclaration() throws T { 9 | } 10 | 11 | E005_TypeParametersConstructorDeclaration(boolean type, T arg) { 12 | } 13 | 14 | E005_TypeParametersConstructorDeclaration(T arg0, U arg1) { 15 | } 16 | 17 | E005_TypeParametersConstructorDeclaration(int type, T arg0, U arg1) { 18 | } 19 | 20 | E005_TypeParametersConstructorDeclaration(String type, T arg0) throws E { 21 | } 22 | 23 | E005_TypeParametersConstructorDeclaration(float type, T arg0, U arg1) throws E { 24 | } 25 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E005_TypeParametersMethodDeclaration.java: -------------------------------------------------------------------------------- 1 | class E005_TypeParametersMethodDeclaration { 2 | T simpleGenericReturn() { 3 | return null; 4 | } 5 | 6 | T genericExtendsReturn() { 7 | return null; 8 | } 9 | 10 | void simpleGenericParameter(T arg) { 11 | } 12 | 13 | void genericExtendsParameter(T arg) { 14 | } 15 | 16 | void genericThrows() throws T { 17 | } 18 | 19 | void genericExtendsMoreParameter(T arg) { 20 | } 21 | 22 | void genericMoreParameter(T arg0, U arg1) { 23 | } 24 | 25 | void genericExtendsMoreParameter(T arg0, U arg1) { 26 | } 27 | 28 | U genericExtendsMoreParameterAndReturns(T arg0) { 29 | return null; 30 | } 31 | 32 | U genericFun(T arg0) throws E { 33 | return null; 34 | } 35 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E006_TypeParametersOnGenericTypesMethodDeclaration.java: -------------------------------------------------------------------------------- 1 | class E006_TypeParametersOnGenericTypesMethodDeclaration { 2 | U genericFun(java.util.Map arg0) throws E, X { 3 | return null; 4 | } 5 | } -------------------------------------------------------------------------------- /test/resources/idempotency/E007_ArrayMethodDeclarations.java: -------------------------------------------------------------------------------- 1 | class E004_ArrayMethodDeclarations { 2 | String[] oneParameter(int one) { 3 | return null; 4 | } 5 | 6 | String[][] oneParameter2(int one) { 7 | return null; 8 | } 9 | 10 | String[] twoParameters(int one, String two) { 11 | return null; 12 | } 13 | 14 | String[][] twoParameters2(int one, String two) { 15 | return null; 16 | } 17 | 18 | String[] varArgs(String... two) { 19 | return null; 20 | } 21 | 22 | String[][] varArgs2(String... two) { 23 | return null; 24 | } 25 | 26 | String[] varArgsArray(String[]... two) { 27 | return null; 28 | } 29 | 30 | String[][] varArgsArray2(String[]... two) { 31 | return null; 32 | } 33 | 34 | String[] simpleGenericParameter(int one, String two, java.util.List three) { 35 | return null; 36 | } 37 | 38 | String[][] simpleGenericParameter2(int one, String two, java.util.List three) { 39 | return null; 40 | } 41 | 42 | public String[] publicMethod(int one, String two, java.util.List three, boolean isPublic) { 43 | return null; 44 | } 45 | 46 | public String[][] publicMethod2(int one, String two, java.util.List three, boolean isPublic) { 47 | return null; 48 | } 49 | 50 | String[] typeArgumentExtends(java.util.List list) { 51 | return null; 52 | } 53 | 54 | String[][] typeArgumentExtends2(java.util.List list) { 55 | return null; 56 | } 57 | 58 | String[] typeArgumentSuper(Class clazz) { 59 | return null; 60 | } 61 | 62 | String[][] typeArgumentSuper2(Class clazz) { 63 | return null; 64 | } 65 | 66 | R[] returnTypeParameter() { 67 | return null; 68 | } 69 | 70 | R[][] returnTypeParameter2() { 71 | return null; 72 | } 73 | 74 | R[] returnAndParameterTypeParameter(T arg) { 75 | return null; 76 | } 77 | 78 | R[][] returnAndParameterTypeParameter2(T arg) { 79 | return null; 80 | } 81 | 82 | String[] throwsMethod() throws Exception { 83 | return null; 84 | } 85 | 86 | String[][] throwsMethod2() throws Exception { 87 | return null; 88 | } 89 | 90 | R[] throwsReturnsAndParameter(T arg) throws E, NullPointerException { 91 | return null; 92 | } 93 | 94 | R[][] throwsReturnsAndParameter2(T arg) throws E, NullPointerException { 95 | return null; 96 | } 97 | } -------------------------------------------------------------------------------- /test/resources/idempotency/F001_Annotations.java: -------------------------------------------------------------------------------- 1 | class F001_Annotations { 2 | { 3 | @SuppressWarnings("all") 4 | int i = 5; 5 | @SuppressWarnings({"all", "non-existent"}) 6 | int more = 5; 7 | @SuppressWarnings(value = "all") 8 | int single = 5; 9 | @SuppressWarnings(value = {"all", "non-existent"}) 10 | int full = 5; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return null; 16 | } 17 | 18 | @SuppressWarnings("serial") 19 | @Override 20 | public int hashCode() { 21 | return 0; 22 | } 23 | 24 | @SuppressWarnings("all") 25 | void foo() { 26 | } 27 | } -------------------------------------------------------------------------------- /test/resources/idempotency/G001_SimpleFieldDeclarations.java: -------------------------------------------------------------------------------- 1 | class G001_SimpleFieldDeclaration { 2 | int i; 3 | 4 | boolean z; 5 | 6 | float f; 7 | 8 | double d; 9 | 10 | short s; 11 | 12 | char c; 13 | 14 | byte b; 15 | 16 | long l; 17 | 18 | String o; 19 | } -------------------------------------------------------------------------------- /test/resources/idempotency/G002_InitializedFieldDeclarations.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class G002_InitializedFieldDeclaration { 4 | public int publicI = 1 * 4; 5 | 6 | private static final long loadTime = System.currentTimeMillis(); 7 | 8 | String[] names = {"Reinier", "Roel"}; 9 | 10 | String[] lastNames = new String[] {"Zwitserloot", "Spilker"}; 11 | 12 | String empty[] = {}; 13 | 14 | String[] doubleEmpty[] = {{}}; 15 | 16 | Collection emptyCollection = Collections.emptyList(); 17 | 18 | @SuppressWarnings("all") 19 | Collection otherCollection = Collections.emptyList(); 20 | } -------------------------------------------------------------------------------- /test/resources/idempotency/G002_ModifiersFieldDeclarations.java: -------------------------------------------------------------------------------- 1 | class G002_ModifiersFieldDeclaration { 2 | public int publicI; 3 | 4 | protected int protectedI; 5 | 6 | private int privateI; 7 | 8 | final int finalI = 0; 9 | 10 | transient int transientI; 11 | 12 | volatile int volatileI; 13 | 14 | static int staticI; 15 | 16 | @SuppressWarnings("all") 17 | public static final transient int lots = -1; 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/G003_MultipleFieldDeclarations.java: -------------------------------------------------------------------------------- 1 | class G003_MultipleFieldDeclaration { 2 | private int x = 0, y; 3 | 4 | int z, k[] = {}; 5 | 6 | boolean[] a[][], b[]; 7 | 8 | @SuppressWarnings("all") 9 | public final String[] name = null, names[] = {{}}; 10 | } -------------------------------------------------------------------------------- /test/resources/idempotency/G004_AnonymousInnerClasses.java: -------------------------------------------------------------------------------- 1 | class G004_AnonymousInnerClasses { 2 | { 3 | Object o = new Object() { 4 | }; 5 | new java.lang.Object() { 6 | int x = 10; 7 | 8 | void test() { 9 | } 10 | }.test(); 11 | int y = new java.lang.Object() { 12 | int go() { 13 | return 10; 14 | } 15 | }.go(); 16 | } 17 | 18 | public void testMethod() { 19 | Object o = new Object() { 20 | }; 21 | int y = 10; 22 | Object o2 = new Object(); 23 | } 24 | 25 | public G004_AnonymousInnerClasses() { 26 | Object o = new Object() { 27 | }; 28 | int y = 10; 29 | Object o2 = new Object(); 30 | } 31 | 32 | static { 33 | Object o = new Object() { 34 | }; 35 | int y = 10; 36 | Object o2 = new Object(); 37 | } 38 | 39 | private final Object testObject = new Object() { 40 | }; 41 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H001_Interfaces.java: -------------------------------------------------------------------------------- 1 | public interface H001_Interfaces extends java.util.RandomAccess, java.io.Serializable { 2 | int field = 0; 3 | 4 | void x(); 5 | } 6 | 7 | interface H001_Interfaces2 { 8 | } 9 | 10 | interface H001_Interfaces3 { 11 | interface InnerInterface { 12 | static interface InnerInnerInterface { 13 | } 14 | } 15 | 16 | class InnerClass { 17 | interface InnerClassInnerInterface { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H002_Enums.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("all") 2 | public enum H002_Enums implements java.util.RandomAccess { 3 | A, 4 | B, 5 | C 6 | } 7 | 8 | enum SemiComplexEnum { 9 | SCE_A(10), 10 | SCE_B(20), 11 | SCE_C(30 + 10); 12 | 13 | private final int x; 14 | 15 | SemiComplexEnum(int x) { 16 | this.x = x; 17 | } 18 | 19 | public int foo() { 20 | return x; 21 | } 22 | } 23 | 24 | enum TrivialEnum { 25 | } 26 | 27 | enum ReallyComplexEnum { 28 | RCE_A(10) { 29 | void bar() { 30 | } 31 | }, 32 | RCE_B, 33 | RCE_C { 34 | void baz() { 35 | } 36 | }; 37 | 38 | ReallyComplexEnum() { 39 | } 40 | 41 | ReallyComplexEnum(int x) { 42 | } 43 | } 44 | 45 | enum AnnsOnEnumValues { 46 | AOEV_A, 47 | @Deprecated 48 | @SuppressWarnings("all") 49 | AOEV_B, 50 | @Deprecated 51 | AOEV_C 52 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H003_Annotations.java: -------------------------------------------------------------------------------- 1 | public @interface H003_Annotations { 2 | int value() default 10; 3 | } 4 | 5 | @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE) 6 | @interface ComplexAnnotation { 7 | int x = 10; 8 | 9 | String[] v1(); 10 | 11 | Class clazz() default Object.class; 12 | 13 | Class[] clazzArray() default {}; 14 | 15 | public abstract H003_Annotations ann(); 16 | 17 | String[] v2() default {"a", "b", "c"}; 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H004_MultiGenerics.java: -------------------------------------------------------------------------------- 1 | class H004_MultiGenerics { 2 | class Inner { 3 | } 4 | 5 | class Inner2 extends H004_MultiGenerics.Inner { 6 | } 7 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H005_SimpleConstructors.java: -------------------------------------------------------------------------------- 1 | class H005_SimpleConstructors { 2 | H005_SimpleConstructors(String in) { 3 | } 4 | 5 | H005_SimpleConstructors() { 6 | this(""); 7 | } 8 | 9 | static class Inner extends H005_SimpleConstructors { 10 | Inner() { 11 | super(""); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H006_ComplexConstructors.java: -------------------------------------------------------------------------------- 1 | class H006_ComplexConstructors { 2 | public H006_ComplexConstructors(T t, V v) { 3 | } 4 | 5 | { 6 | H006_ComplexConstructors x = new H006_ComplexConstructors(0, ""); 7 | } 8 | 9 | public H006_ComplexConstructors() { 10 | this(null, ""); 11 | int x = 5; 12 | } 13 | 14 | static class Inner1 { 15 | class InnerInner { 16 | InnerInner(C x) { 17 | } 18 | } 19 | } 20 | 21 | static class Inner2 extends Inner1.InnerInner { 22 | Inner2() { 23 | new Inner1().super(""); 24 | int x = 5; 25 | } 26 | } 27 | 28 | class Inner3 { 29 | Inner3(int x) { 30 | System.out.println(x); 31 | } 32 | 33 | { 34 | H006_ComplexConstructors instance = new H006_ComplexConstructors(0, ""); 35 | Object o = instance.new Inner3(5).new InnerInner3("hey"); 36 | } 37 | 38 | class InnerInner3 { 39 | InnerInner3(D in) { 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H007_SuperAndThisQualifier.java: -------------------------------------------------------------------------------- 1 | class H007_SuperAndThisQualifier { 2 | int x; 3 | 4 | void test() { 5 | } 6 | 7 | static class Inner extends H007_SuperAndThisQualifier { 8 | int y; 9 | 10 | void test() { 11 | super.test(); 12 | this.y = super.x; 13 | } 14 | 15 | void test2() { 16 | this.test(); 17 | } 18 | 19 | class InnerInner { 20 | { 21 | Inner.this.test(); 22 | Inner.super.test(); 23 | } 24 | 25 | void test() { 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H008_SimpleMethods.java: -------------------------------------------------------------------------------- 1 | import static java.util.Collections.*; 2 | import java.util.*; 3 | 4 | class H008_SimpleMethods { 5 | private int x; 6 | 7 | public int test(int z) { 8 | this.x = z; 9 | return -z; 10 | } 11 | 12 | private String name = "Test"; 13 | 14 | public void set() { 15 | int y = test(01); 16 | unmodifiableSet(new HashSet()); 17 | } 18 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H009_ComplexMethods.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.List; 3 | import java.util.Map; 4 | 5 | class H009_ComplexMethods { 6 | private int x; 7 | 8 | public void noargs() { 9 | this.x = 0; 10 | return; 11 | } 12 | 13 | public java.util.List retVal() { 14 | return null; 15 | } 16 | 17 | public void twoArgs(List one, java.lang.String two) { 18 | } 19 | 20 | @SuppressWarnings("all") 21 | public > Map complex(V in, List in2, int x) { 22 | return new HashMap(); 23 | } 24 | 25 | public void testInvocations() { 26 | noargs(); 27 | retVal(); 28 | Object o = retVal(); 29 | this.twoArgs(new java.util.ArrayList(20), ""); 30 | new H009_ComplexMethods().>complex((Number) Integer.valueOf(20), new java.util.ArrayList>(), 10); 31 | } 32 | 33 | static class H009_ComplexMethodsInners extends H009_ComplexMethods { 34 | @Override 35 | public void noargs() { 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /test/resources/idempotency/H010_Javadoc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * jdoc1 3 | * multiliner 4 | */ 5 | class H010_Javadoc { 6 | /** jdoc2 */ 7 | int x; 8 | 9 | /** jdoc3foo */ 10 | class A { 11 | } 12 | 13 | /** jdoc4 */ 14 | interface B { 15 | } 16 | 17 | /** jdoc5 */ 18 | @interface C { 19 | /** jdoc8 */ 20 | int foo() default 5; 21 | } 22 | 23 | /** jdoc6 */ 24 | enum D { 25 | } 26 | 27 | /** jdoc7 28 | * @throws NumberFormatException foo 29 | */ 30 | void test() { 31 | } 32 | 33 | /** {@inheritDoc} */ 34 | void test2() { 35 | } 36 | } -------------------------------------------------------------------------------- /test/resources/idempotency/I001_AnnotationsAndTypeParametersMethodDeclaration.java: -------------------------------------------------------------------------------- 1 | class I001_AnnotationsAndTypeParametersMethodDeclaration { 2 | @Deprecated 3 | T getValue(T key) { 4 | return key; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/I001_ComplexAsserts1.java: -------------------------------------------------------------------------------- 1 | class I001_ComplexAsserts1 { 2 | public void test() { 3 | while (1 > System.currentTimeMillis()) { 4 | if (System.currentTimeMillis() == 1) { 5 | assert true: "Testing asserts"; 6 | } 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /test/resources/idempotency/I001_Deprecated.java: -------------------------------------------------------------------------------- 1 | class I001_Deprecated { 2 | @Deprecated 3 | int x; 4 | 5 | /** 6 | * @deprecated 7 | */ 8 | int y; 9 | 10 | /** 11 | * @deprecated 12 | */ 13 | class Inner { 14 | /** 15 | * @deprecated 16 | */ 17 | Inner() { 18 | } 19 | 20 | /** 21 | * @deprecated 22 | */ 23 | int test() { 24 | return 0; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /test/resources/idempotency/I002_ComplexAsserts2.java: -------------------------------------------------------------------------------- 1 | class I002_ComplexAsserts2 { 2 | interface Inner1 { 3 | class Inner2 { 4 | public void innerMethod() { 5 | if (1 == System.currentTimeMillis()) assert true: "InnerInner assert"; 6 | } 7 | } 8 | } 9 | 10 | static class Inner3 { 11 | static { 12 | assert true: "StaticInstance"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /test/resources/idempotency/I002_ConditionalExpressions.java: -------------------------------------------------------------------------------- 1 | class I002_ConditionalExpressions { 2 | { 3 | int a = 10; 4 | int b = a == 10 ? a = 5 : 2; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/idempotency/J001_ExplicitDeclarations.java: -------------------------------------------------------------------------------- 1 | class J001_ExplicitDeclarations { 2 | public void method0() { 3 | int x; 4 | } 5 | 6 | public void method1() { 7 | int x, y; 8 | } 9 | 10 | public void method2() { 11 | class Local { 12 | } 13 | } 14 | 15 | public void method3() { 16 | int x, y; 17 | class Local { 18 | } 19 | } 20 | 21 | public void method4() { 22 | new Object() { 23 | }.toString(); 24 | } 25 | 26 | public void method5() { 27 | for (int x = 0; x < 12; x++) { 28 | } 29 | } 30 | 31 | public void method6() { 32 | for (int x = 0, y = 2; x < 12; x++) { 33 | } 34 | } 35 | 36 | public void method7() { 37 | for (int x : new int[] {1, 2}) { 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /test/resources/idempotency/ZComplex1.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import java.util.*; 4 | import static java.util.Collections.sort; 5 | import java.io.File; 6 | 7 | public class ZComplex1 { 8 | public void test() { 9 | java.lang.String x = null; 10 | int z = 0x20; 11 | float a = 1.234F; 12 | java.util.List[] q; 13 | } 14 | } 15 | 16 | class ZComplex1Extra { 17 | { 18 | int x = 10 + 20 + 30; 19 | if (x >>> 2 < 10) { 20 | System.out.println("Whoa!"); 21 | } else System.exit(0); 22 | if (x >>> 2 < 10) { 23 | System.out.println("Whoa!"); 24 | } 25 | int y = 10 + 20 + 30; 26 | int z = (10 + 20) + 30; 27 | int a = 10 + (20 + 30); 28 | int b = 10 + 20 * 30; 29 | int c = (10 + 20) * 30; 30 | boolean d = "" + b instanceof CharSequence; 31 | boolean g = a < 0; 32 | boolean e = a > 0 ? true : b < 0 ? true : false; 33 | boolean f = (a > 0 ? true : b < 0) ? true : false; 34 | y++; 35 | for (int i = 0, j = 1; i < 10; i++, j++) for (String name : Collections.emptyList()) { 36 | System.out.println(i); 37 | } 38 | try { 39 | something(); 40 | } catch (Exception ex) { 41 | somethingElse(); 42 | } catch (java.lang.Throwable ex) { 43 | somethingElseEntirely(); 44 | } finally { 45 | nothing(); 46 | } 47 | } 48 | 49 | void something() { 50 | } 51 | 52 | void somethingElse() { 53 | } 54 | 55 | void somethingElseEntirely() { 56 | } 57 | 58 | void nothing() { 59 | } 60 | 61 | static { 62 | int y = 20; 63 | } 64 | } -------------------------------------------------------------------------------- /test/resources/idempotency/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * package-level javadoc 3 | */ 4 | @SuppressWarnings("all") 5 | package example.packageDeclaration; -------------------------------------------------------------------------------- /test/resources/parseErrors/Bad1.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import java.util.*; 4 | import static java.util.Collections.sort; 5 | import java.io.File; 6 | 7 | public class Test1 { 8 | public void test0() { 9 | java.lang.String x = null; 10 | int z = 0x20; 11 | float a = 1.234F; 12 | java.util.List[] q; 13 | } 14 | 15 | public void test() { 16 | java.lang.String x = null; 17 | int z = 0x20; 18 | float a = 1.234F; 19 | java.util.List[] q; 20 | 21 | public void test2() { 22 | java.lang.String x = null; 23 | int z = 0x20; 24 | float a = 1.234F; 25 | java.util.List[] q; 26 | } 27 | } 28 | 29 | class X { 30 | { 31 | int x = 10 + 20 + 30; 32 | if (x <<< 2 < 10) { 33 | System.out.println("Whoa!"); 34 | } else System.exit(0); 35 | if (x <<< 2 < 10) { 36 | System.out.println("Whoa!"); 37 | } 38 | int y = (10 + 20) + 30; 39 | int z = ((10 + 20) + 30); 40 | int a = 10 + (20 + 30); 41 | int b = 10 + 20 * 30; 42 | int c = (10 + 20) * 30; 43 | boolean d = (c + d) instanceof Integer; 44 | boolean g = a < 0; 45 | int e = a > 0 ? true : b < 0 ? true : false; 46 | int f = (a > 0 ? true : b < 0) ? true : false; 47 | 48 | for ( int i = 0, j=1 ; i < 10; i++, j++ ) for (String x : Collections.emptyList()) { 49 | System.out.println(i); 50 | } 51 | 52 | try { 53 | something(); 54 | } catch (Exception e) { 55 | somethingElse(); 56 | } catch (java.lang.Throwable e) { 57 | somethingElseEntirely(); 58 | } finally { 59 | nothing(); 60 | } 61 | } 62 | 63 | static { 64 | int y = 20; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/resources/parseErrors/ConditionalExpressionsPrecedence.java: -------------------------------------------------------------------------------- 1 | class ConditionalExpressionsPrecedence { 2 | { 3 | int a = 10; 4 | int b = a == 9 ? 5 : a = 4; 5 | } 6 | } -------------------------------------------------------------------------------- /test/resources/special/AbstractMethodAndComment.java: -------------------------------------------------------------------------------- 1 | abstract class AbstractMethodAndComment { 2 | /** comment 1 */ 3 | abstract void test(); 4 | 5 | //Fool 6 | } -------------------------------------------------------------------------------- /test/resources/special/AnnotationsWithComments.java: -------------------------------------------------------------------------------- 1 | class AnnotationsWithComments { 2 | @SuppressWarnings("all") /* Block Comment */ 3 | private void test1() {} 4 | 5 | @SuppressWarnings("all") // Line Comment 6 | private void test2() {} 7 | } -------------------------------------------------------------------------------- /test/resources/special/BackslashU.java: -------------------------------------------------------------------------------- 1 | class BackslashU { 2 | void test() { 3 | String x = "\u00A0"; 4 | int y = 10; 5 | y = (12); 6 | } 7 | } -------------------------------------------------------------------------------- /test/resources/special/CastPlusUnary.java: -------------------------------------------------------------------------------- 1 | class CastPlusUnary { 2 | { 3 | int a = 10, b = 20; 4 | int y = (a)+b; 5 | int z = (int)+b; 6 | int Integer = 10; 7 | int z2 = (Integer) -b; 8 | } 9 | } -------------------------------------------------------------------------------- /test/resources/special/ChainedMethodsWithSuper.java: -------------------------------------------------------------------------------- 1 | class ChainedMethodsWithSuper { 2 | ChainedMethodsWithSuper test1() { 3 | return this; 4 | } 5 | 6 | ChainedMethodsWithSuper test2() { 7 | return this; 8 | } 9 | 10 | ChainedMethodsWithSuper test3() { 11 | return this; 12 | } 13 | 14 | ChainedMethodsWithSuper x = this; 15 | 16 | static class Inner extends ChainedMethodsWithSuper { 17 | { 18 | Object y = super.test1().x.x; 19 | Object z = super.x.x; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /test/resources/special/ExtensiveJavadoc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main javadoc {@code description}. 3 | * 4 | * @param T a type parameter 5 | * @author author tag 6 | * @since since tag 7 | * @see link 8 | */ 9 | public class ExtensiveJavadoc { 10 | /** 11 | * Javadoc containing a value tag that's not in a legal location. 12 | * 13 | * @value Description of this constant's value. 14 | */ 15 | private int test; 16 | 17 | /** Javadoc on a compound field declaration. */ 18 | private int a, b; 19 | 20 | /** 21 | * Some javadoc containing links and some light html. 22 | * to {@link #test} a local field.
23 | * to {@link #foo(int)} a local method.
24 | * to {@link java.lang.String#CASE_INSENSITIVE_ORDER} a remote field.
25 | * to {@link java.lang.String} a remote class.
26 | * to {@link java.lang.String#toUpperCase()} a remote method.
27 | * 28 | * 29 | * @return foo 30 | */ 31 | public int bar() { 32 | return 0; 33 | } 34 | 35 | /** 36 | * @param in A method level param tag. 37 | * @throws NumberFormatException A throws tag. 38 | * @return A return tag. 39 | */ 40 | public int foo(int in) throws NumberFormatException { 41 | return 0; 42 | } 43 | 44 | /** 45 | * A deprecated method. 46 | * 47 | * @deprecated Deprecated description. 48 | */ 49 | public void deprecatedMethod() { 50 | } 51 | } 52 | 53 | /** 54 | * some interface javadoc 55 | */ 56 | interface InterfaceJavadocTest { 57 | /** 58 | * some javadoc 59 | */ 60 | class InnerClassInInterfaceJavadocTest { 61 | } 62 | } 63 | 64 | /** 65 | * some javadoc 66 | */ 67 | enum EnumJavadocTest { 68 | /** 69 | * some javadoc 70 | */ 71 | FOO; 72 | 73 | /** 74 | * some javadoc 75 | */ 76 | public int foo() { 77 | return 10; 78 | } 79 | } 80 | 81 | /** 82 | * some javadoc 83 | */ 84 | @interface AnnDeclareJavadocTest { 85 | /** 86 | * some javadoc 87 | */ 88 | int foo() default 10; 89 | } 90 | -------------------------------------------------------------------------------- /test/resources/special/LesserThanPlusComma.java: -------------------------------------------------------------------------------- 1 | class LesserThanPlusComma { 2 | void test(boolean foo, String bar) { 3 | } 4 | { 5 | int a = 10; 6 | int b = 20; 7 | test(a < b, "c"); 8 | } 9 | } -------------------------------------------------------------------------------- /test/resources/special/ManyCommentsEclipseHasBugs.java: -------------------------------------------------------------------------------- 1 | //Comments before a class 2 | class ManyComments { 3 | int x; 4 | //Comment 1 5 | //Comment 2 6 | //Comment 3 7 | int y; 8 | } -------------------------------------------------------------------------------- /test/resources/special/ParenthesizedCast.java: -------------------------------------------------------------------------------- 1 | class ParenthesizedCast 2 | { 3 | { 4 | int a = 10; 5 | byte b = (byte)(a); 6 | } 7 | } -------------------------------------------------------------------------------- /test/resources/special/PassthroughAssignmentInInlineIf.java: -------------------------------------------------------------------------------- 1 | class PassthroughAssignmentInInlineIf { 2 | { 3 | int x = 10; 4 | int y = (10 == x) ? x = 20 : x; 5 | } 6 | } -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/AliasTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | import static lombok.ast.grammar.RunForEachFileInDirRunner.fixLineEndings; 26 | 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.util.Collection; 30 | import java.util.Collections; 31 | 32 | import lombok.ast.Node; 33 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 34 | import lombok.ast.printer.SourcePrinter; 35 | import lombok.ast.printer.TextFormatter; 36 | 37 | import org.junit.Test; 38 | import org.junit.runner.RunWith; 39 | 40 | @RunWith(RunForEachFileInDirRunner.class) 41 | public class AliasTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 42 | @Override 43 | protected Collection getDirDescriptors() { 44 | return Collections.singleton(DirDescriptor.of(new File("test/resources/idempotency"), true).withMirror(new File("test/resources/alias"))); 45 | } 46 | 47 | @Test 48 | public void testContentEqualsAfterParsePrintCycle(String expected, Source actual) throws IOException { 49 | actual.parseCompilationUnit(); 50 | 51 | if (!actual.getProblems().isEmpty()) { 52 | fail(actual.getProblems().get(0).toString()); 53 | } 54 | 55 | Node node = actual.getNodes().get(0); 56 | TextFormatter formatter = new TextFormatter(); 57 | node.accept(new SourcePrinter(formatter)); 58 | String actualString = formatter.finish(); 59 | 60 | assertEquals(fixLineEndings(expected), fixLineEndings(actualString)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/AlternativeStringConcatEcjTreeBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static java.util.Collections.singleton; 25 | 26 | import java.io.File; 27 | import java.util.Collection; 28 | import java.util.regex.Pattern; 29 | 30 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 31 | 32 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; 33 | import org.junit.Test; 34 | import org.junit.runner.RunWith; 35 | 36 | @RunWith(RunForEachFileInDirRunner.class) 37 | public class AlternativeStringConcatEcjTreeBuilderTest extends EcjTreeBuilderTest { 38 | @Override protected Collection getDirDescriptors() { 39 | return singleton(DirDescriptor.of(new File("test/resources/idempotency"), true).withInclusion(Pattern.compile("^.*StringConcatExpressions.java$", Pattern.CASE_INSENSITIVE))); 40 | } 41 | 42 | @Test 43 | public boolean testAlternativeStringConcatEcjCompiler(Source source) throws Exception { 44 | return testCompiler(source); 45 | } 46 | 47 | @Override protected CompilerOptions ecjCompilerOptions() { 48 | CompilerOptions options = super.ecjCompilerOptions(); 49 | options.parseLiteralExpressionsAsConstants = false; 50 | return options; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/AlternativeStringConcatEcjTreeConverterType2Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import java.io.File; 25 | import java.util.Arrays; 26 | import java.util.Collection; 27 | import java.util.regex.Pattern; 28 | 29 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 30 | 31 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; 32 | import org.junit.Test; 33 | 34 | public class AlternativeStringConcatEcjTreeConverterType2Test extends EcjTreeConverterType2Test { 35 | @Test 36 | public boolean testEcjTreeConverter(Source source) throws Exception { 37 | return testCompiler(source); 38 | } 39 | 40 | @Override protected Collection getDirDescriptors() { 41 | return Arrays.asList( 42 | DirDescriptor.of(new File("test/resources/idempotency"), true).withInclusion(Pattern.compile("^.*StringConcatExpressions.java$", Pattern.CASE_INSENSITIVE)) 43 | ); 44 | } 45 | 46 | @Override protected CompilerOptions ecjCompilerOptions() { 47 | CompilerOptions options = super.ecjCompilerOptions(); 48 | options.parseLiteralExpressionsAsConstants = false; 49 | return options; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/ContentBasedJavaFileObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2011 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import javax.tools.SimpleJavaFileObject; 28 | 29 | public class ContentBasedJavaFileObject extends SimpleJavaFileObject { 30 | private final String content; 31 | 32 | public ContentBasedJavaFileObject(String name, String content) { 33 | super(new File(name).toURI(), Kind.SOURCE); 34 | this.content = content; 35 | } 36 | 37 | @Override 38 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 39 | return content; 40 | } 41 | } -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/EcjCompilerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.io.PrintWriter; 29 | import java.util.Arrays; 30 | import java.util.Collection; 31 | 32 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 33 | 34 | import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 35 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; 36 | import org.junit.Test; 37 | import org.junit.runner.RunWith; 38 | 39 | @RunWith(RunForEachFileInDirRunner.class) 40 | public class EcjCompilerTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 41 | private static final boolean EXTENDED = System.getProperty("lombok.ast.test.extended") != null; 42 | 43 | @Override 44 | protected Collection getDirDescriptors() { 45 | return Arrays.asList( 46 | DirDescriptor.of(new File("test/resources/idempotency"), true), 47 | DirDescriptor.of(new File("test/resources/alias"), true)); 48 | } 49 | 50 | protected CompilerOptions ecjCompilerOptions() { 51 | CompilerOptions options = new CompilerOptions(); 52 | options.complianceLevel = ClassFileConstants.JDK1_6; 53 | options.sourceLevel = ClassFileConstants.JDK1_6; 54 | options.targetJDK = ClassFileConstants.JDK1_6; 55 | options.parseLiteralExpressionsAsConstants = true; 56 | return options; 57 | } 58 | 59 | @Test 60 | public boolean testEcjCompiler(File file) throws IOException { 61 | if (!EXTENDED) return false; 62 | org.eclipse.jdt.internal.compiler.batch.Main main = 63 | new org.eclipse.jdt.internal.compiler.batch.Main( 64 | new PrintWriter(System.out), new PrintWriter(System.err), 65 | false, null, null); 66 | File tempDir = getTempDir(); 67 | tempDir.mkdirs(); 68 | String[] argv = { 69 | "-d", tempDir.getAbsolutePath(), 70 | "-encoding", "UTF-8", 71 | "-proc:none", 72 | "-1.6", "-nowarn", "-enableJavadoc", 73 | file.getAbsolutePath() 74 | }; 75 | main.compile(argv); 76 | assertEquals("Errors occurred while compiling this file with ecj", 0, main.globalErrorsCount); 77 | return true; 78 | } 79 | 80 | private File getTempDir() { 81 | String[] rawDirs = { 82 | System.getProperty("java.io.tmpdir"), 83 | "/tmp", 84 | "C:\\Windows\\Temp" 85 | }; 86 | 87 | for (String dir : rawDirs) { 88 | if (dir == null) continue; 89 | File f = new File(dir); 90 | if (!f.isDirectory()) continue; 91 | return new File(f, "lombok.ast-test"); 92 | } 93 | 94 | return new File(getDirDescriptors().iterator().next().getDirectory(), "tmp"); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/IdempotencyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | import static lombok.ast.grammar.RunForEachFileInDirRunner.fixLineEndings; 26 | 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.util.Collection; 30 | import java.util.Collections; 31 | 32 | import lombok.ast.Node; 33 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 34 | import lombok.ast.printer.SourcePrinter; 35 | import lombok.ast.printer.TextFormatter; 36 | 37 | import org.junit.Test; 38 | import org.junit.runner.RunWith; 39 | 40 | @RunWith(RunForEachFileInDirRunner.class) 41 | public class IdempotencyTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 42 | @Override 43 | protected Collection getDirDescriptors() { 44 | return Collections.singleton(DirDescriptor.of(new File("test/resources/idempotency"), true)); 45 | } 46 | 47 | @Test 48 | public void testIdempotency(Source source) throws IOException { 49 | source.parseCompilationUnit(); 50 | 51 | if (!source.getProblems().isEmpty()) { 52 | fail(source.getProblems().get(0).toString()); 53 | } 54 | 55 | Node node = source.getNodes().get(0); 56 | TextFormatter formatter = new TextFormatter(); 57 | node.accept(new SourcePrinter(formatter)); 58 | String actual = fixLineEndings(formatter.finish()); 59 | String original = fixLineEndings(source.getRawInput()); 60 | try { 61 | assertEquals(original, actual); 62 | } catch (AssertionError e) { 63 | System.out.println("------------------RAW:"); 64 | System.out.println(original); 65 | System.out.println("-------PARSED-PRINTED:"); 66 | System.out.println(actual); 67 | System.out.println("----------------------"); 68 | throw e; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/JavaCompilerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.util.Arrays; 29 | import java.util.Collection; 30 | import java.util.Collections; 31 | import java.util.List; 32 | 33 | import javax.tools.JavaCompiler; 34 | import javax.tools.ToolProvider; 35 | import javax.tools.JavaCompiler.CompilationTask; 36 | 37 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 38 | 39 | import org.junit.Test; 40 | import org.junit.runner.RunWith; 41 | 42 | @RunWith(RunForEachFileInDirRunner.class) 43 | public class JavaCompilerTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 44 | @Override 45 | protected Collection getDirDescriptors() { 46 | return Arrays.asList( 47 | DirDescriptor.of(new File("test/resources/idempotency"), true), 48 | DirDescriptor.of(new File("test/resources/alias"), true)); 49 | } 50 | 51 | @Test 52 | public void testJavaCompiler(Source source) throws IOException { 53 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 54 | File tempDir = getTempDir(); 55 | tempDir.mkdirs(); 56 | List options = Arrays.asList("-proc:none", "-d", tempDir.getAbsolutePath()); 57 | CompilationTask task = compiler.getTask(null, null, null, options, null, Collections.singleton(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()))); 58 | assertTrue(task.call()); 59 | } 60 | 61 | private File getTempDir() { 62 | String[] rawDirs = { 63 | System.getProperty("java.io.tmpdir"), 64 | "/tmp", 65 | "C:\\Windows\\Temp" 66 | }; 67 | 68 | for (String dir : rawDirs) { 69 | if (dir == null) continue; 70 | File f = new File(dir); 71 | if (!f.isDirectory()) continue; 72 | return new File(f, "lombok.ast-test"); 73 | } 74 | 75 | return new File(getDirDescriptors().iterator().next().getDirectory(), "tmp"); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/JcTreeConverterType2Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import lombok.ast.javac.JcTreeBuilder; 25 | import lombok.ast.javac.JcTreeConverter; 26 | import lombok.ast.javac.JcTreePrinter; 27 | 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | 31 | import com.sun.tools.javac.main.JavaCompiler; 32 | import com.sun.tools.javac.main.OptionName; 33 | import com.sun.tools.javac.tree.JCTree; 34 | import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 35 | import com.sun.tools.javac.util.Context; 36 | import com.sun.tools.javac.util.Options; 37 | 38 | /** 39 | * Compares a JCTree AST parsed by javac with a JCTree AST parsed by javac, converted to lombok.ast, and converted back. 40 | */ 41 | @RunWith(RunForEachFileInDirRunner.class) 42 | public class JcTreeConverterType2Test extends TreeBuilderRunner { 43 | public JcTreeConverterType2Test() { 44 | super(true); 45 | } 46 | 47 | @Test 48 | public boolean testJcTreeConverter(Source source) throws Exception { 49 | return testCompiler(source); 50 | } 51 | 52 | protected String convertToString(JCTree tree) { 53 | JcTreePrinter printer = JcTreePrinter.printerWithPositions(); 54 | printer.visit(tree); 55 | String string = printer.toString(); 56 | return string; 57 | } 58 | 59 | protected boolean checkForLombokAstParseFailure() { 60 | return false; 61 | } 62 | 63 | protected JCTree parseWithLombok(Source source) { 64 | Context context = new Context(); 65 | 66 | Options.instance(context).put(OptionName.ENCODING, "UTF-8"); 67 | 68 | JavaCompiler compiler = new JavaCompiler(context); 69 | compiler.genEndPos = true; 70 | compiler.keepComments = true; 71 | 72 | JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput())); 73 | JcTreeConverter converter = new JcTreeConverter(); 74 | JcTreeBuilder builder = new JcTreeBuilder(); 75 | converter.visit(cu); 76 | builder.visit(converter.getResult()); 77 | return builder.get(); 78 | } 79 | 80 | protected JCTree parseWithTargetCompiler(Source source) { 81 | Context context = new Context(); 82 | 83 | Options.instance(context).put(OptionName.ENCODING, "UTF-8"); 84 | 85 | JavaCompiler compiler = new JavaCompiler(context); 86 | compiler.genEndPos = true; 87 | compiler.keepComments = true; 88 | 89 | JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput())); 90 | return cu; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/PositionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.util.Collection; 29 | import java.util.Collections; 30 | import java.util.List; 31 | 32 | import lombok.ast.AstException; 33 | import lombok.ast.Node; 34 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 35 | import lombok.ast.printer.SourcePrinter; 36 | import lombok.ast.printer.StructureFormatter; 37 | 38 | import org.junit.Test; 39 | import org.junit.runner.RunWith; 40 | 41 | @RunWith(RunForEachFileInDirRunner.class) 42 | public class PositionTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 43 | @Override 44 | protected Collection getDirDescriptors() { 45 | return Collections.singleton(DirDescriptor.of(new File("test/resources/idempotency"), true)); 46 | } 47 | 48 | @Test 49 | public void testPositions(Source source) throws IOException { 50 | source.parseCompilationUnit(); 51 | 52 | if (!source.getProblems().isEmpty()) { 53 | fail(source.getProblems().get(0).toString()); 54 | } 55 | 56 | Node node = source.getNodes().get(0); 57 | PositionCheckingFormatter formatter = new PositionCheckingFormatter(source); 58 | node.accept(new SourcePrinter(formatter)); 59 | List problems = formatter.getProblems(); 60 | try { 61 | if (!problems.isEmpty()) fail("position error: " + problems.get(0)); 62 | } catch (AssertionError e) { 63 | System.out.println("-------PARSED-PRINTED:"); 64 | StructureFormatter formatter2 = StructureFormatter.formatterWithPositions(); 65 | node.accept(new SourcePrinter(formatter2)); 66 | System.out.println(formatter2.finish()); 67 | System.out.println("--------------PRINTED:"); 68 | System.out.println(formatter.finish()); 69 | System.out.println("----------------------"); 70 | throw e; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/src/lombok/ast/grammar/SyntaxCheckClearsOnIdempotencyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Project Lombok Authors. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | package lombok.ast.grammar; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.util.Arrays; 29 | import java.util.Collection; 30 | 31 | import lombok.ast.ForwardingAstVisitor; 32 | import lombok.ast.Message; 33 | import lombok.ast.Node; 34 | import lombok.ast.grammar.RunForEachFileInDirRunner.DirDescriptor; 35 | import lombok.ast.syntaxChecks.SyntacticValidityVisitor; 36 | 37 | import org.junit.Test; 38 | import org.junit.runner.RunWith; 39 | 40 | @RunWith(RunForEachFileInDirRunner.class) 41 | public class SyntaxCheckClearsOnIdempotencyTest extends RunForEachFileInDirRunner.SourceFileBasedTester { 42 | @Override 43 | protected Collection getDirDescriptors() { 44 | return Arrays.asList( 45 | DirDescriptor.of(new File("test/resources/idempotency"), true), 46 | DirDescriptor.of(new File("test/resources/alias"), true)); 47 | } 48 | 49 | @Test 50 | public void testSyntaxCheckclearsOnIdempotency(final Source source) throws IOException { 51 | source.parseCompilationUnit(); 52 | 53 | if (!source.getProblems().isEmpty()) { 54 | fail(source.getProblems().get(0).toString()); 55 | } 56 | 57 | Node node = source.getNodes().get(0); 58 | node.accept(new SyntacticValidityVisitor(true)); 59 | node.accept(new ForwardingAstVisitor() { 60 | @Override public boolean visitNode(Node node) { 61 | for (Message m : node.getMessages()) if (m.isError()) { 62 | fail(String.format("Source: %s[%s]: %s: %s\n", source.getName(), node.getPosition(), node, m.getMessage())); 63 | 64 | } 65 | return false; 66 | } 67 | }); 68 | } 69 | } 70 | --------------------------------------------------------------------------------