From 02d49bfd0bf6e93ef63ddb1dc7c447925630a2ab Mon Sep 17 00:00:00 2001 From: sotty Date: Fri, 13 Jun 2014 01:16:33 +0100 Subject: [PATCH] Java Statement Fluent Model Update Copyright --- .../org/jboss/forge/roaster/model/Block.java | 29 ++ .../expressions/AbstractInvokeExpression.java | 16 + .../model/expressions/AccessBuilder.java | 30 ++ .../roaster/model/expressions/Accessor.java | 16 + .../roaster/model/expressions/Argument.java | 16 + .../model/expressions/ArgumentHolder.java | 15 + .../ArrayConstructorExpression.java | 18 ++ .../model/expressions/ArrayIndexer.java | 15 + .../roaster/model/expressions/ArrayInit.java | 22 ++ .../model/expressions/AssignExpression.java | 19 ++ .../roaster/model/expressions/Assignment.java | 36 +++ .../model/expressions/BareArgument.java | 21 ++ .../model/expressions/CastExpression.java | 15 + .../expressions/ChainableExpression.java | 17 + .../model/expressions/ClassLiteral.java | 16 + .../model/expressions/ConstructorBuilder.java | 22 ++ .../expressions/ConstructorExpression.java | 16 + .../model/expressions/DeclareExpression.java | 17 + .../roaster/model/expressions/Expression.java | 18 ++ .../model/expressions/ExpressionSource.java | 14 + .../model/expressions/Expressions.java | 170 ++++++++++ .../roaster/model/expressions/Field.java | 16 + .../roaster/model/expressions/Getter.java | 18 ++ .../expressions/InstanceofExpression.java | 15 + .../model/expressions/InvokeExpression.java | 17 + .../roaster/model/expressions/Literal.java | 14 + .../model/expressions/LiteralBuilder.java | 35 +++ .../model/expressions/MethodExpression.java | 19 ++ .../forge/roaster/model/expressions/Op.java | 42 +++ .../model/expressions/OperatorExpression.java | 18 ++ .../model/expressions/ParenExpression.java | 17 + .../roaster/model/expressions/PrefixOp.java | 29 ++ .../roaster/model/expressions/Setter.java | 17 + .../roaster/model/expressions/Super.java | 16 + .../model/expressions/TernaryExpression.java | 21 ++ .../model/expressions/UnaryExpression.java | 15 + .../roaster/model/expressions/Variable.java | 15 + .../roaster/model/expressions/Wireable.java | 20 ++ .../roaster/model/source/BlockHolder.java | 15 + .../roaster/model/source/MethodBody.java | 23 ++ .../roaster/model/source/MethodSource.java | 19 +- .../model/statements/AssertStatement.java | 22 ++ .../model/statements/AssignStatement.java | 24 ++ .../model/statements/BlockStatement.java | 23 ++ .../model/statements/BreakStatement.java | 20 ++ .../model/statements/ContinueStatement.java | 20 ++ .../model/statements/DeclareStatement.java | 27 ++ .../model/statements/DoWhileStatement.java | 23 ++ .../model/statements/ExpressionStatement.java | 16 + .../model/statements/ForEachStatement.java | 27 ++ .../model/statements/ForStatement.java | 28 ++ .../roaster/model/statements/IfStatement.java | 25 ++ .../model/statements/InvokeStatement.java | 25 ++ .../model/statements/ReturnStatement.java | 21 ++ .../roaster/model/statements/Statement.java | 28 ++ .../roaster/model/statements/Statements.java | 105 +++++++ .../model/statements/SuperStatement.java | 20 ++ .../model/statements/SwitchStatement.java | 26 ++ .../model/statements/SynchStatement.java | 23 ++ .../model/statements/ThisStatement.java | 20 ++ .../model/statements/ThrowStatement.java | 19 ++ .../model/statements/TryCatchStatement.java | 25 ++ .../model/statements/WhileStatement.java | 23 ++ .../forge/roaster/spi/ExpressionFactory.java | 73 +++++ .../forge/roaster/spi/StatementFactory.java | 109 +++++++ .../jboss/forge/roaster/model/ASTNode.java | 15 + .../roaster/model/impl/AnnotationImpl.java | 2 + .../forge/roaster/model/impl/BlockImpl.java | 40 +++ .../forge/roaster/model/impl/JDTHelper.java | 45 +++ .../forge/roaster/model/impl/MethodImpl.java | 35 ++- .../forge/roaster/model/impl/NodeImpl.java | 65 ++++ .../roaster/model/impl/ParameterImpl.java | 1 + .../expressions/AbstractMethodInvokeImpl.java | 46 +++ .../model/impl/expressions/AccessorImpl.java | 50 +++ .../model/impl/expressions/ArgumentImpl.java | 23 ++ .../impl/expressions/ArrayAccessImpl.java | 47 +++ .../model/impl/expressions/ArrayImpl.java | 88 ++++++ .../model/impl/expressions/ArrayInitImpl.java | 64 ++++ .../model/impl/expressions/AssignImpl.java | 61 ++++ .../impl/expressions/BaseInvokeableImpl.java | 30 ++ .../impl/expressions/BooleanLiteralImpl.java | 35 +++ .../model/impl/expressions/CastImpl.java | 49 +++ .../expressions/CharacterLiteralImpl.java | 36 +++ .../impl/expressions/ClassLiteralImpl.java | 40 +++ .../impl/expressions/ConstructorImpl.java | 60 ++++ .../expressions/DeclareExpressionImpl.java | 56 ++++ .../impl/expressions/DotAccessorImpl.java | 96 ++++++ .../impl/expressions/ExpressionImpl.java | 31 ++ .../model/impl/expressions/FieldImpl.java | 50 +++ .../model/impl/expressions/GetterImpl.java | 55 ++++ .../impl/expressions/InstanceofImpl.java | 45 +++ .../impl/expressions/InvokeableImpl.java | 32 ++ .../expressions/JdtExpressionWrapper.java | 23 ++ .../model/impl/expressions/LiteralImpl.java | 21 ++ .../impl/expressions/MethodInvokeImpl.java | 52 ++++ .../model/impl/expressions/NotImpl.java | 23 ++ .../impl/expressions/NullLiteralImpl.java | 31 ++ .../impl/expressions/NumberLiteralImpl.java | 35 +++ .../model/impl/expressions/OperatorImpl.java | 89 ++++++ .../model/impl/expressions/ParenImpl.java | 42 +++ .../model/impl/expressions/PostFixImpl.java | 43 +++ .../impl/expressions/SelfArgumentImpl.java | 40 +++ .../model/impl/expressions/SetterImpl.java | 44 +++ .../impl/expressions/SimpleAccessorImpl.java | 31 ++ .../expressions/StaticClassAccessorImpl.java | 45 +++ .../impl/expressions/StringLiteralImpl.java | 38 +++ .../impl/expressions/SuperFieldImpl.java | 56 ++++ .../impl/expressions/SuperGetterImpl.java | 52 ++++ .../model/impl/expressions/SuperImpl.java | 54 ++++ .../expressions/SuperMethodInvokeImpl.java | 41 +++ .../impl/expressions/SuperSetterImpl.java | 45 +++ .../model/impl/expressions/TernaryImpl.java | 66 ++++ .../model/impl/expressions/UnaryImpl.java | 46 +++ .../impl/expressions/VarArgumentImpl.java | 45 +++ .../impl/statements/AssertStatementImpl.java | 53 ++++ .../impl/statements/AssignStatementImpl.java | 62 ++++ .../impl/statements/BlockStatementImpl.java | 63 ++++ .../impl/statements/BreakStatementImpl.java | 44 +++ .../statements/ContinueStatementImpl.java | 44 +++ .../impl/statements/DeclareStatementImpl.java | 76 +++++ .../impl/statements/DoWhileStatementImpl.java | 58 ++++ .../statements/ExpressionStatementImpl.java | 39 +++ .../impl/statements/ForEachStatementImpl.java | 76 +++++ .../impl/statements/ForStatementImpl.java | 101 ++++++ .../impl/statements/IfStatementImpl.java | 68 ++++ .../impl/statements/InvokeStatementImpl.java | 78 +++++ .../impl/statements/JdtStatementWrapper.java | 17 + .../impl/statements/ReturnStatementImpl.java | 45 +++ .../impl/statements/StatementFactoryImpl.java | 145 +++++++++ .../model/impl/statements/StatementImpl.java | 64 ++++ .../impl/statements/SuperStatementImpl.java | 54 ++++ .../impl/statements/SwitchStatementImpl.java | 104 +++++++ .../impl/statements/SynchStatementImpl.java | 58 ++++ .../impl/statements/ThisStatementImpl.java | 54 ++++ .../impl/statements/ThrowStatementImpl.java | 43 +++ .../statements/TryCatchStatementImpl.java | 93 ++++++ .../impl/statements/WhileStatementImpl.java | 57 ++++ .../roaster/spi/ExpressionFactoryImpl.java | 290 ++++++++++++++++++ ....jboss.forge.roaster.spi.ExpressionFactory | 1 + ...g.jboss.forge.roaster.spi.StatementFactory | 1 + .../statements/ConstructorStatementsTest.java | 50 +++ .../statements/ControlFlowStatementsTest.java | 194 ++++++++++++ .../statements/DeclareStatementsTest.java | 84 +++++ .../model/statements/ForStatementsTest.java | 69 +++++ .../model/statements/IfStatementsTest.java | 95 ++++++ .../statements/InvokeStatementsTest.java | 122 ++++++++ .../statements/ReturnStatementsTest.java | 250 +++++++++++++++ .../roaster/model/statements/SuperTest.java | 78 +++++ .../model/statements/WhileStatementsTest.java | 59 ++++ 149 files changed, 6676 insertions(+), 3 deletions(-) create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/Block.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/AbstractInvokeExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/AccessBuilder.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Accessor.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Argument.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ArgumentHolder.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayConstructorExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayIndexer.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayInit.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/AssignExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Assignment.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/BareArgument.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/CastExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ChainableExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ClassLiteral.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorBuilder.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/DeclareExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Expression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ExpressionSource.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Expressions.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Field.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Getter.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/InstanceofExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/InvokeExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Literal.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/LiteralBuilder.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/MethodExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Op.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/OperatorExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/ParenExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/PrefixOp.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Setter.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Super.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/TernaryExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/UnaryExpression.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Variable.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/expressions/Wireable.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/source/BlockHolder.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/source/MethodBody.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/AssertStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/AssignStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/BlockStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/BreakStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ContinueStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/DeclareStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/DoWhileStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ExpressionStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ForEachStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ForStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/IfStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/InvokeStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ReturnStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/Statement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/Statements.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/SuperStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/SwitchStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/SynchStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ThisStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/ThrowStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/TryCatchStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/model/statements/WhileStatement.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactory.java create mode 100644 api/src/main/java/org/jboss/forge/roaster/spi/StatementFactory.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/ASTNode.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/BlockImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/NodeImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AbstractMethodInvokeImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AccessorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArgumentImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayAccessImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayInitImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AssignImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BaseInvokeableImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BooleanLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CastImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CharacterLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ClassLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ConstructorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DeclareExpressionImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DotAccessorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ExpressionImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/FieldImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/GetterImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InstanceofImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InvokeableImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/JdtExpressionWrapper.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/LiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/MethodInvokeImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NotImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NullLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NumberLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/OperatorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ParenImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/PostFixImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SelfArgumentImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SetterImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SimpleAccessorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StaticClassAccessorImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StringLiteralImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperFieldImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperGetterImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperMethodInvokeImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperSetterImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/TernaryImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/UnaryImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/VarArgumentImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssertStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssignStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BlockStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BreakStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ContinueStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DeclareStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DoWhileStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ExpressionStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForEachStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/IfStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/InvokeStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/JdtStatementWrapper.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ReturnStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementFactoryImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SuperStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SwitchStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SynchStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThisStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThrowStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/TryCatchStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/WhileStatementImpl.java create mode 100644 impl/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactoryImpl.java create mode 100644 impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.ExpressionFactory create mode 100644 impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.StatementFactory create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ConstructorStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ControlFlowStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/DeclareStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ForStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/IfStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/InvokeStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ReturnStatementsTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/SuperTest.java create mode 100644 impl/src/test/java/org/jboss/forge/test/roaster/model/statements/WhileStatementsTest.java diff --git a/api/src/main/java/org/jboss/forge/roaster/model/Block.java b/api/src/main/java/org/jboss/forge/roaster/model/Block.java new file mode 100644 index 00000000..aaa498cc --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/Block.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model; + +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.jboss.forge.roaster.model.statements.AssignStatement; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.DeclareStatement; +import org.jboss.forge.roaster.model.statements.ForEachStatement; +import org.jboss.forge.roaster.model.statements.ForStatement; +import org.jboss.forge.roaster.model.statements.IfStatement; +import org.jboss.forge.roaster.model.statements.InvokeStatement; +import org.jboss.forge.roaster.model.statements.ReturnStatement; +import org.jboss.forge.roaster.model.statements.Statement; +import org.jboss.forge.roaster.model.statements.WhileStatement; + +public interface Block, T extends BlockHolder> + extends Origin, + BlockHolder> { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/AbstractInvokeExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AbstractInvokeExpression.java new file mode 100644 index 00000000..1b285cf2 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AbstractInvokeExpression.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface AbstractInvokeExpression, T extends ExpressionSource> + extends Argument, + ChainableExpression { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/AccessBuilder.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AccessBuilder.java new file mode 100644 index 00000000..3c4752cf --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AccessBuilder.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface AccessBuilder, T extends ExpressionSource> + extends Expression { + + public Field field( String field ); + + public Getter getter( String field, String klass ); + + public Getter getter( String field, Class klass ); + + public Setter setter( String fldName, String type, Expression> value ); + + public Setter setter( String fldName, Class type, Expression> value ); + + public MethodExpression invoke( String method ); + + public AccessBuilder itemAt( Expression> index ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Accessor.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Accessor.java new file mode 100644 index 00000000..5d968f0d --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Accessor.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Accessor, T extends ExpressionSource> + extends Argument, + AccessBuilder { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Argument.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Argument.java new file mode 100644 index 00000000..51618123 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Argument.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Argument, T extends ExpressionSource> + extends Expression { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArgumentHolder.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArgumentHolder.java new file mode 100644 index 00000000..4ddfd2fb --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArgumentHolder.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ArgumentHolder, X extends ExpressionSource> { + + public ArgumentHolder addArgument( Argument arg ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayConstructorExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayConstructorExpression.java new file mode 100644 index 00000000..e2117e6d --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayConstructorExpression.java @@ -0,0 +1,18 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ArrayConstructorExpression, T extends ExpressionSource> + extends Argument { + + public ArrayConstructorExpression addDimension( Expression> dim ); + + public ArrayConstructorExpression init( ArrayInit> array ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayIndexer.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayIndexer.java new file mode 100644 index 00000000..85f2563e --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayIndexer.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ArrayIndexer, T extends ExpressionSource> + extends BareArgument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayInit.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayInit.java new file mode 100644 index 00000000..d8628ef4 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ArrayInit.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ArrayInit, T extends ExpressionSource> + extends ExpressionSource { + + public ArrayInit addElement( ArrayInit subRow ); + + public ArrayInit addElement( Expression subElement ); + + public int size(); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/AssignExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AssignExpression.java new file mode 100644 index 00000000..be188f98 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/AssignExpression.java @@ -0,0 +1,19 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface AssignExpression, T extends ExpressionSource> + extends ExpressionSource, + Argument { + + public AssignExpression setLeft( Accessor left ); + + public AssignExpression setRight( Expression right ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Assignment.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Assignment.java new file mode 100644 index 00000000..ff7855f5 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Assignment.java @@ -0,0 +1,36 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +public enum Assignment { + + ASSIGN( "=" ), + DIVIDE_ASSIGN( "/=" ), + PLUS_ASSIGN( "+=" ), + MINUS_ASSIGN( "-=" ), + TIMES_ASSIGN( "*=" ), + REMAINDER_ASSIGN( "%=" ), + + LEFT_SHIFT_ASSIGN( "<<=" ), + RIGHT_SHIFT_ASSIGN( ">>=" ), + RIGHT_SHIFT_UNSIGNED_ASSIGN( ">>>=" ), + BITWISE_XOR_ASSIGN( "^=" ), + BITWISE_AND_ASSIGN( "&=" ), + BITWISE_OR_ASSIGN( "|=" ); + + private String op; + + Assignment( String o ) { + op = o; + } + + public String getOp() { + return op; + } +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/BareArgument.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/BareArgument.java new file mode 100644 index 00000000..402980b7 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/BareArgument.java @@ -0,0 +1,21 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface BareArgument, T extends ExpressionSource> + extends Argument, + Accessor, + Wireable { + + public Argument inc(); + + public Argument dec(); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/CastExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/CastExpression.java new file mode 100644 index 00000000..8d2cdac6 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/CastExpression.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface CastExpression, T extends ExpressionSource> + extends Argument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ChainableExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ChainableExpression.java new file mode 100644 index 00000000..0214bf31 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ChainableExpression.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + + +public interface ChainableExpression, T extends ExpressionSource> { + + public Accessor dot(); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ClassLiteral.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ClassLiteral.java new file mode 100644 index 00000000..764a50fe --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ClassLiteral.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ClassLiteral, T extends ExpressionSource> + extends Literal, + Accessor { +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorBuilder.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorBuilder.java new file mode 100644 index 00000000..03197ff7 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorBuilder.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ConstructorBuilder, T extends ExpressionSource> { + + public ConstructorExpression newInstance( String klass ); + + public ConstructorExpression newInstance( Class klass ); + + public ArrayConstructorExpression newArray( Class klass ); + + public ArrayConstructorExpression newArray( String klass ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorExpression.java new file mode 100644 index 00000000..1d9a5c4b --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ConstructorExpression.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ConstructorExpression, T extends ExpressionSource> + extends Argument { + + public ConstructorExpression addArgument( Argument> arg ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/DeclareExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/DeclareExpression.java new file mode 100644 index 00000000..50d42d3a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/DeclareExpression.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface DeclareExpression, T extends ExpressionSource> + extends Argument { + + public DeclareExpression init( Expression expr ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expression.java new file mode 100644 index 00000000..474a04ba --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expression.java @@ -0,0 +1,18 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Expression, T extends ExpressionSource> + extends ExpressionSource, + Origin { + + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ExpressionSource.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ExpressionSource.java new file mode 100644 index 00000000..4cee0d02 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ExpressionSource.java @@ -0,0 +1,14 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ExpressionSource> { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expressions.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expressions.java new file mode 100644 index 00000000..7f8f8bae --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Expressions.java @@ -0,0 +1,170 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.spi.ExpressionFactory; + +import java.util.ServiceLoader; + +public abstract class Expressions { + + protected static ExpressionFactory factory; + + protected static ExpressionFactory getFactory() { + synchronized ( Expressions.class ) { + ServiceLoader sl = ServiceLoader.load( ExpressionFactory.class, Expressions.class.getClassLoader() ); + if ( sl.iterator().hasNext() ) { + factory = sl.iterator().next(); + } else { + throw new IllegalStateException( "No ExpressionFactory implementation available, unable to continue" ); + } + } + return factory; + } + + public static Literal literal( String val ) { + return getFactory().literal( val ); + } + + public static Literal literal( Number val ) { + return getFactory().literal( val ); + } + + public static Literal literal( Character val ) { + return getFactory().literal( val ); + } + + public static Literal literal( Boolean val ) { + return getFactory().literal( val ); + } + + public static Argument zeroLiteral( String klass ) { + return getFactory().zeroLiteral( klass ); + } + + public static Literal zeroLiteral( Class klass ) { + return getFactory().zeroLiteral( klass ); + } + + public static Accessor thisLiteral() { + return getFactory().thisLiteral(); + } + + public static Literal nullLiteral() { + return getFactory().nullLiteral(); + } + + public static ClassLiteral classLiteral( String klass ) { + return getFactory().classLiteral( klass ); + } + + public static ClassLiteral classLiteral( Class klass ) { + return getFactory().classLiteral( klass ); + } + + public static Accessor classStatic( String klass ) { + return getFactory().classStatic( klass ); + } + + public static Accessor classStatic( Class klass ) { + return getFactory().classStatic( klass ); + } + + public static ConstructorExpression newInstance( String klass ) { + return getFactory().newInstance( klass ); + } + + public static ConstructorExpression newInstance( Class klass ) { + return getFactory().newInstance( klass ); + } + + public static ArrayConstructorExpression newArray( String klass ) { + return getFactory().newArray( klass ); + } + + public static ArrayConstructorExpression newArray( Class klass ) { + return getFactory().newArray( klass ); + } + + public static ArrayInit vec() { + return getFactory().vec(); + } + + public static Variable var( String variable ) { + return getFactory().var( variable ); + } + + public static OperatorExpression operator( Op operator ) { + return getFactory().operator( operator ); + } + + public static UnaryExpression operator( PrefixOp operator, Argument arg ) { + return getFactory().operator( operator, arg ); + } + + public static TernaryExpression ternary() { + return getFactory().ternary(); + } + + public static Argument cast( String klass, Expression expression ) { + return getFactory().cast( klass, expression ); + } + + public static Argument cast( Class klass, Expression expression ) { + return getFactory().cast( klass, expression ); + } + + public static ParenExpression paren( Expression inner ) { + return getFactory().paren( inner ); + } + + public static UnaryExpression not( Argument inner ) { + return getFactory().not( inner ); + } + + public static AssignExpression assign( Assignment operator ) { + return getFactory().assign( operator ); + } + + public static DeclareExpression declare( String klass, String name ) { + return getFactory().declare( klass, name ); + } + + public static DeclareExpression declare( Class klass, String name ) { + return getFactory().declare( klass, name ); + } + + public static MethodExpression invoke( String method ) { + return getFactory().invoke( method ); + } + + public static Field field( String field ) { + return getFactory().field( field ); + } + + public static Getter getter( String field, String klass ) { + return getFactory().getter( field, klass ); + } + + public static Getter getter( String field, Class klass ) { + return getFactory().getter( field, klass ); + } + + public static Super sup() { + return getFactory().sup(); + } + + public static InstanceofExpression instanceOf( String klass, Expression expression ) { + return getFactory().instanceOf( klass, expression ); + } + + public static InstanceofExpression instanceOf( Class klass, Expression expression ) { + return getFactory().instanceOf( klass, expression ); + } + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Field.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Field.java new file mode 100644 index 00000000..a16b4dbd --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Field.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Field, T extends ExpressionSource> + extends BareArgument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Getter.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Getter.java new file mode 100644 index 00000000..7c2a126a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Getter.java @@ -0,0 +1,18 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Getter, T extends ExpressionSource> + extends Accessor, + InvokeExpression, + Wireable { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/InstanceofExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/InstanceofExpression.java new file mode 100644 index 00000000..dc6e5034 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/InstanceofExpression.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface InstanceofExpression, T extends ExpressionSource> + extends Argument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/InvokeExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/InvokeExpression.java new file mode 100644 index 00000000..35a42ad2 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/InvokeExpression.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface InvokeExpression, T extends ExpressionSource> + extends AbstractInvokeExpression { + + public InvokeExpression setTarget( Expression> target ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Literal.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Literal.java new file mode 100644 index 00000000..c79e6195 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Literal.java @@ -0,0 +1,14 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Literal, T extends ExpressionSource> + extends Argument { +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/LiteralBuilder.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/LiteralBuilder.java new file mode 100644 index 00000000..e37f35bf --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/LiteralBuilder.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface LiteralBuilder, T extends ExpressionSource> { + + public Literal literal( String val ); + + public Literal literal( Number val ); + + public Literal literal( Character val ); + + public Literal literal( Boolean val ); + + public Literal zeroLiteral( String klass ); + + public Literal zeroLiteral( Class klass ); + + public Accessor thisLiteral(); + + public Literal nullLiteral(); + + public ClassLiteral classLiteral( String klass ); + + public ClassLiteral classLiteral( Class klass ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/MethodExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/MethodExpression.java new file mode 100644 index 00000000..14149634 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/MethodExpression.java @@ -0,0 +1,19 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface MethodExpression, T extends ExpressionSource> + extends InvokeExpression, + ArgumentHolder> { + + public MethodExpression setTarget( Expression> target ); + + public MethodExpression addArgument( Argument> argument ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Op.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Op.java new file mode 100644 index 00000000..781567b4 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Op.java @@ -0,0 +1,42 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +public enum Op { + + TIMES( "*" ), + DIVIDE( "/" ), + REMAINDER( "%" ), + PLUS( "+" ), + MINUS( "-" ), + LEFT_SHIFT( "<<" ), + RIGHT_SHIFT_SIGNED( ">>" ), + RIGHT_SHIFT_UNSIGNED( ">>>" ), + LESS( "<" ), + GREATER( ">" ), + LESS_EQUALS( "<=" ), + GREATER_EQUALS( ">=" ), + EQUALS( "==" ), + NOT_EQUALS( "!=" ), + BITWISE_XOR( "^" ), + BITWISE_AND( "&" ), + BITWISE_OR( "|" ), + OR( "||" ), + AND( "&&" ); + + private String op; + + Op( String o ) { + op = o; + } + + public String getOp() { + return op; + } +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/OperatorExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/OperatorExpression.java new file mode 100644 index 00000000..74b9e93d --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/OperatorExpression.java @@ -0,0 +1,18 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface OperatorExpression, T extends ExpressionSource> + extends Argument, + ArgumentHolder> { + + public OperatorExpression addArgument( Argument> expression ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/ParenExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ParenExpression.java new file mode 100644 index 00000000..691d22c6 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/ParenExpression.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.spi.ExpressionFactory; + +public interface ParenExpression, T extends ExpressionSource> + extends ExpressionFactory, + Argument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/PrefixOp.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/PrefixOp.java new file mode 100644 index 00000000..4bd06794 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/PrefixOp.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +public enum PrefixOp { + + INC( "++" ), + DEC( "--" ), + PLUS( "+" ), + MINUS( "-" ), + NOT( "!" ), + NEG( "~" ); + + private String op; + + PrefixOp( String o ) { + op = o; + } + + public String getOp() { + return op; + } +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Setter.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Setter.java new file mode 100644 index 00000000..9f5cd005 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Setter.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Setter, T extends ExpressionSource> + extends Expression, + MethodExpression { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Super.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Super.java new file mode 100644 index 00000000..5c774dc9 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Super.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Super,T extends ExpressionSource> + extends AccessBuilder { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/TernaryExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/TernaryExpression.java new file mode 100644 index 00000000..b35a7bf1 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/TernaryExpression.java @@ -0,0 +1,21 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface TernaryExpression, T extends ExpressionSource> + extends Argument { + + public TernaryExpression setCondition( Expression expression ); + + public TernaryExpression setIfExpression( Expression onTrue ); + + public TernaryExpression setElseExpression( Expression onFalse ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/UnaryExpression.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/UnaryExpression.java new file mode 100644 index 00000000..1da8eff6 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/UnaryExpression.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface UnaryExpression, T extends ExpressionSource> + extends Argument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Variable.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Variable.java new file mode 100644 index 00000000..8d23d49b --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Variable.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Variable, T extends ExpressionSource> + extends BareArgument { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/expressions/Wireable.java b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Wireable.java new file mode 100644 index 00000000..27ad19d9 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/expressions/Wireable.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.expressions; + +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Wireable, T extends ExpressionSource> { + + void wireExpression( Expression child ); + + ExpressionSource getParent(); + + void wireParent( ExpressionSource parent ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/source/BlockHolder.java b/api/src/main/java/org/jboss/forge/roaster/model/source/BlockHolder.java new file mode 100644 index 00000000..40933fb1 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/source/BlockHolder.java @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.source; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.JavaType; + +public interface BlockHolder, T extends BlockHolder> { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/source/MethodBody.java b/api/src/main/java/org/jboss/forge/roaster/model/source/MethodBody.java new file mode 100644 index 00000000..23aa54eb --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/source/MethodBody.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.source; + +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.Method; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.source.MethodSource; + +/** + * The body of a method + */ +public interface MethodBody, T extends MethodSource> + extends BlockHolder, + Origin { + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/source/MethodSource.java b/api/src/main/java/org/jboss/forge/roaster/model/source/MethodSource.java index d6ef1cf7..3fb8c1f8 100644 --- a/api/src/main/java/org/jboss/forge/roaster/model/source/MethodSource.java +++ b/api/src/main/java/org/jboss/forge/roaster/model/source/MethodSource.java @@ -9,9 +9,12 @@ import java.util.List; +import org.jboss.forge.roaster.model.Block; import org.jboss.forge.roaster.model.JavaClass; import org.jboss.forge.roaster.model.JavaType; import org.jboss.forge.roaster.model.Method; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.statements.Statement; /** * Represents a Java Method in source form. @@ -21,7 +24,8 @@ */ public interface MethodSource> extends Method>, AbstractableSource>, - MemberSource>, GenericCapableSource> + MemberSource>, GenericCapableSource>, + BlockHolder> { /** * Set this {@link Method} to return the given type. @@ -104,4 +108,17 @@ public interface MethodSource> extends Method removeParameter(ParameterSource parameter); + + /** + * Opens a block of statements to define the method body + * @return + */ + MethodSource setBody( Statement block ); + + /** + * Opens a block of statements to define the method body + * @return + */ + MethodSource setBody( Expression expr ); + } \ No newline at end of file diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/AssertStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/AssertStatement.java new file mode 100644 index 00000000..3da9cd9a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/AssertStatement.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface AssertStatement, T extends Block>> + extends Statement> { + + AssertStatement setAssertion( Expression> expression ); + + AssertStatement setMessage( Expression> msg ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/AssignStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/AssignStatement.java new file mode 100644 index 00000000..ee2fb22a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/AssignStatement.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface AssignStatement, T extends Block>> + extends Statement> { + + public AssignStatement setLeft( Accessor left ); + + public AssignStatement setRight( Expression right ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/BlockStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/BlockStatement.java new file mode 100644 index 00000000..be8290b9 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/BlockStatement.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface BlockStatement, T extends Block>> + extends Statement>, + Block { + + BlockStatement addStatement( Statement statement ); + + BlockStatement addStatement( Expression statement ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/BreakStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/BreakStatement.java new file mode 100644 index 00000000..288cac57 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/BreakStatement.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface BreakStatement, T extends Block>> + extends Statement> { + + public BreakStatement setTarget( String label ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ContinueStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ContinueStatement.java new file mode 100644 index 00000000..dd5067cf --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ContinueStatement.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ContinueStatement, T extends Block>> + extends Statement> { + + public ContinueStatement setTarget( String label ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/DeclareStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/DeclareStatement.java new file mode 100644 index 00000000..22c45e72 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/DeclareStatement.java @@ -0,0 +1,27 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface DeclareStatement, T extends Block>> + extends Statement> { + + public DeclareStatement setVariable( Class klass, String name ); + + public DeclareStatement setVariable( String klass, String name ); + + public DeclareStatement setInitExpression( Expression init ); + + public DeclareStatement setDefaultInitExpression(); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/DoWhileStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/DoWhileStatement.java new file mode 100644 index 00000000..e134157d --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/DoWhileStatement.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface DoWhileStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + DoWhileStatement setCondition( Expression expr ); + + DoWhileStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ExpressionStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ExpressionStatement.java new file mode 100644 index 00000000..e919543c --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ExpressionStatement.java @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ExpressionStatement, T extends Block>> + extends Statement> { +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ForEachStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ForEachStatement.java new file mode 100644 index 00000000..d268a8fe --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ForEachStatement.java @@ -0,0 +1,27 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ForEachStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + ForEachStatement setIterator( String klass, String name ); + + ForEachStatement setIterator( Class klass, String name ); + + ForEachStatement setSource( Expression expr ); + + ForEachStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ForStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ForStatement.java new file mode 100644 index 00000000..3ed70d34 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ForStatement.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ForStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + ForStatement addDeclaration( DeclareExpression declaration ); + + ForStatement setCondition( Expression booleanExpression ); + + ForStatement addUpdate( Expression expression ); + + ForStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/IfStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/IfStatement.java new file mode 100644 index 00000000..a7e455dc --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/IfStatement.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface IfStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + IfStatement setCondition( Expression condition ); + + IfStatement setThen( Statement block ); + + IfStatement setElse( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/InvokeStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/InvokeStatement.java new file mode 100644 index 00000000..5dbe3d73 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/InvokeStatement.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface InvokeStatement, T extends Block>> + extends Statement> { + + public InvokeStatement setMethod( String method ); + + public InvokeStatement setTarget( Accessor target ); + + public InvokeStatement addArgument( Argument argument ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ReturnStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ReturnStatement.java new file mode 100644 index 00000000..da9b91c8 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ReturnStatement.java @@ -0,0 +1,21 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ReturnStatement, T extends Block>> + extends Statement> { + + public ReturnStatement setReturn( Expression expr ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/Statement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/Statement.java new file mode 100644 index 00000000..652cc334 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/Statement.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + + +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface Statement, T extends Block>, S extends Statement> + extends Origin, + ExpressionSource { + + public BlockStatement wrap(); + + public S setLabel( String label ); + + public String getLabel(); + + public boolean hasLabel(); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/Statements.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/Statements.java new file mode 100644 index 00000000..96b8543c --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/Statements.java @@ -0,0 +1,105 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.spi.StatementFactory; + +import java.util.ServiceLoader; + +public abstract class Statements { + + protected static StatementFactory factory; + + protected static StatementFactory getFactory() { + synchronized ( Statements.class ) { + ServiceLoader sl = ServiceLoader.load( StatementFactory.class, Statements.class.getClassLoader() ); + if ( sl.iterator().hasNext() ) { + factory = sl.iterator().next(); + } else { + throw new IllegalStateException( "No StatementFactory implementation available, unable to continue" ); + } + } + return factory; + } + + public static ReturnStatement newReturn() { + return getFactory().newReturn(); + } + + public static IfStatement newIf() { + return getFactory().newIf(); + } + + public static AssignStatement newAssign() { + return getFactory().newAssign(); + } + + public static DeclareStatement newDeclare() { + return getFactory().newDeclare(); + } + + public static ForStatement newFor() { + return getFactory().newFor(); + } + + public static ForEachStatement newForEach() { + return getFactory().newForEach(); + } + + public static InvokeStatement newInvoke() { + return getFactory().newInvoke(); + } + + public static WhileStatement newWhile() { + return getFactory().newWhile(); + } + + public static DoWhileStatement newDoWhile() { + return getFactory().newDoWhile(); + } + + public static BlockStatement newBlock() { + return getFactory().newBlock(); + } + + public static BreakStatement newBreak() { + return getFactory().newBreak(); + } + + public static ContinueStatement newContinue() { + return getFactory().newContinue(); + } + + public static ThrowStatement newThrow() { + return getFactory().newThrow(); + } + + public static TryCatchStatement newTryCatch() { + return getFactory().newTryCatch(); + } + + public static SynchStatement newSynchronized() { + return getFactory().newSynchronized(); + } + + public static ThisStatement newThis() { + return getFactory().newThis(); + } + + public static SuperStatement newSuper() { + return getFactory().newSuper(); + } + + public static AssertStatement newAssert() { + return getFactory().newAssert(); + } + + public static SwitchStatement newSwitch() { + return getFactory().newSwitch(); + } +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/SuperStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/SuperStatement.java new file mode 100644 index 00000000..8d896f5a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/SuperStatement.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface SuperStatement, T extends Block>> + extends Statement> { + + public SuperStatement addArgument( Argument argument ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/SwitchStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/SwitchStatement.java new file mode 100644 index 00000000..d4690e73 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/SwitchStatement.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface SwitchStatement, T extends Block>> + extends Statement> { + + SwitchStatement addCase( Expression> option ); + + SwitchStatement addDefault(); + + SwitchStatement addStatement( Statement arg ); + + SwitchStatement setSwitchOn( Expression> expr ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/SynchStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/SynchStatement.java new file mode 100644 index 00000000..3188df34 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/SynchStatement.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface SynchStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + SynchStatement setSynchOn( Expression expr ); + + SynchStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ThisStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ThisStatement.java new file mode 100644 index 00000000..3a4ce963 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ThisStatement.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ThisStatement, T extends Block>> + extends Statement> { + + public ThisStatement addArgument( Argument argument ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/ThrowStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/ThrowStatement.java new file mode 100644 index 00000000..23d75a4b --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/ThrowStatement.java @@ -0,0 +1,19 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ThrowStatement, T extends Block>> + extends Statement> { + + public ThrowStatement setThrowable( Expression> expr ); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/TryCatchStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/TryCatchStatement.java new file mode 100644 index 00000000..b40f1406 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/TryCatchStatement.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface TryCatchStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + TryCatchStatement addCatch( DeclareExpression declaration, Statement block ); + + TryCatchStatement setFinally( Statement block ); + + TryCatchStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/model/statements/WhileStatement.java b/api/src/main/java/org/jboss/forge/roaster/model/statements/WhileStatement.java new file mode 100644 index 00000000..091827f1 --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/model/statements/WhileStatement.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface WhileStatement, T extends Block>> + extends Statement>, + BlockHolder> { + + WhileStatement setCondition( Expression expr ); + + WhileStatement setBody( Statement block ); + +} diff --git a/api/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactory.java b/api/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactory.java new file mode 100644 index 00000000..14b5c57c --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactory.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.spi; + + +import org.jboss.forge.roaster.model.expressions.AccessBuilder; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ArrayConstructorExpression; +import org.jboss.forge.roaster.model.expressions.ArrayInit; +import org.jboss.forge.roaster.model.expressions.AssignExpression; +import org.jboss.forge.roaster.model.expressions.Assignment; +import org.jboss.forge.roaster.model.expressions.CastExpression; +import org.jboss.forge.roaster.model.expressions.ConstructorBuilder; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InstanceofExpression; +import org.jboss.forge.roaster.model.expressions.LiteralBuilder; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.expressions.OperatorExpression; +import org.jboss.forge.roaster.model.expressions.ParenExpression; +import org.jboss.forge.roaster.model.expressions.PrefixOp; +import org.jboss.forge.roaster.model.expressions.Super; +import org.jboss.forge.roaster.model.expressions.TernaryExpression; +import org.jboss.forge.roaster.model.expressions.UnaryExpression; +import org.jboss.forge.roaster.model.expressions.Variable; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface ExpressionFactory, T extends ExpressionSource> + extends AccessBuilder, + LiteralBuilder, + ConstructorBuilder { + + public Variable var( String varName ); + + public OperatorExpression operator( Op op ); + + public UnaryExpression operator( PrefixOp operator, Argument> arg ); + + public TernaryExpression ternary(); + + public CastExpression cast( String klass, Expression> arg ); + + public CastExpression cast( Class klass, Expression> arg ); + + public ParenExpression paren( Expression> inner ); + + public UnaryExpression not( Argument> arg ); + + public AssignExpression assign( Assignment operator ); + + public DeclareExpression declare( String klass, String name ); + + public DeclareExpression declare( Class klass, String name ); + + public Accessor classStatic( String klass ); + + public Accessor classStatic( Class klass ); + + public InstanceofExpression instanceOf( String klass, Expression> arg ); + + public InstanceofExpression instanceOf( Class klass, Expression> arg ); + + public Super sup(); + + public ArrayInit> vec(); +} diff --git a/api/src/main/java/org/jboss/forge/roaster/spi/StatementFactory.java b/api/src/main/java/org/jboss/forge/roaster/spi/StatementFactory.java new file mode 100644 index 00000000..4b05b36a --- /dev/null +++ b/api/src/main/java/org/jboss/forge/roaster/spi/StatementFactory.java @@ -0,0 +1,109 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.spi; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.AssertStatement; +import org.jboss.forge.roaster.model.statements.AssignStatement; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.BreakStatement; +import org.jboss.forge.roaster.model.statements.ContinueStatement; +import org.jboss.forge.roaster.model.statements.DeclareStatement; +import org.jboss.forge.roaster.model.statements.DoWhileStatement; +import org.jboss.forge.roaster.model.statements.ForEachStatement; +import org.jboss.forge.roaster.model.statements.ForStatement; +import org.jboss.forge.roaster.model.statements.IfStatement; +import org.jboss.forge.roaster.model.statements.InvokeStatement; +import org.jboss.forge.roaster.model.statements.ReturnStatement; +import org.jboss.forge.roaster.model.statements.SuperStatement; +import org.jboss.forge.roaster.model.statements.SwitchStatement; +import org.jboss.forge.roaster.model.statements.SynchStatement; +import org.jboss.forge.roaster.model.statements.ThisStatement; +import org.jboss.forge.roaster.model.statements.ThrowStatement; +import org.jboss.forge.roaster.model.statements.TryCatchStatement; +import org.jboss.forge.roaster.model.statements.WhileStatement; + +public interface StatementFactory, T extends BlockHolder> { + + /** + * Creates a return statement + * @return + */ + ReturnStatement> newReturn(); + + /** + * Creates a variable assignment statement + * @return + */ + AssignStatement> newAssign(); + + /** + * Creates a variable declaration statement + * @return + */ + DeclareStatement> newDeclare(); + + /** + * Creates a method invocation statement + * @return + */ + InvokeStatement> newInvoke(); + + /** + * Creates an if statement + * @return + */ + IfStatement> newIf(); + + /** + * Creates a while statement + * @return + */ + WhileStatement> newWhile(); + + /** + * Creates a for statement + * @return + */ + ForStatement> newFor(); + + /** + * Creates an enhanced for statement + * @return + */ + ForEachStatement> newForEach(); + + /** + * Creates a block statement + * @return + */ + BlockStatement> newBlock(); + + + DoWhileStatement> newDoWhile(); + + BreakStatement> newBreak(); + + ContinueStatement> newContinue(); + + ThrowStatement> newThrow(); + + TryCatchStatement> newTryCatch(); + + SynchStatement> newSynchronized(); + + ThisStatement> newThis(); + + SuperStatement> newSuper(); + + AssertStatement> newAssert(); + + SwitchStatement> newSwitch(); +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/ASTNode.java b/impl/src/main/java/org/jboss/forge/roaster/model/ASTNode.java new file mode 100644 index 00000000..67c253d0 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/ASTNode.java @@ -0,0 +1,15 @@ +package org.jboss.forge.roaster.model; + + +import org.eclipse.jdt.core.dom.AST; + +public interface ASTNode { + + public AST getAst(); + + public J getInternal(); + + public void materialize( AST ast ); + + void setAst( AST ast ); +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/AnnotationImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/AnnotationImpl.java index c0c939a8..77814191 100644 --- a/impl/src/main/java/org/jboss/forge/roaster/model/impl/AnnotationImpl.java +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/AnnotationImpl.java @@ -62,6 +62,7 @@ protected void replace(org.eclipse.jdt.core.dom.Annotation oldNode, org.eclipse. ((MemberValuePair) oldNode.getParent()).setValue(newNode); } } + } private static final String DEFAULT_VALUE = "value"; @@ -878,4 +879,5 @@ private Class resolveTypeLiteral(TypeLiteral typeLiteral) return null; } } + } diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/BlockImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/BlockImpl.java new file mode 100644 index 00000000..719b622d --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/BlockImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.impl.statements.JdtStatementWrapper; +import org.jboss.forge.roaster.model.impl.statements.StatementImpl; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.BlockStatement; + +public class BlockImpl, T extends BlockHolder> + extends NodeImpl + implements Block, + JdtStatementWrapper { + + private org.eclipse.jdt.core.dom.Block block; + + private BlockStatement body; + + public void setBlock( BlockStatement body ) { + this.body = body; + } + + @Override + public org.eclipse.jdt.core.dom.Block getInternal() { + return block; + } + + @Override + public void materialize( AST ast ) { + + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/JDTHelper.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/JDTHelper.java index 677752bb..27283449 100644 --- a/impl/src/main/java/org/jboss/forge/roaster/model/impl/JDTHelper.java +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/JDTHelper.java @@ -6,8 +6,10 @@ */ package org.jboss.forge.roaster.model.impl; +import java.util.Arrays; import java.util.List; +import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ArrayType; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.EnumDeclaration; @@ -19,6 +21,9 @@ import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.WildcardType; +import org.jboss.forge.roaster.model.Field; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.util.Types; /** * Help with Eclipse JDT common operations. @@ -73,4 +78,44 @@ public static List getInterfaces(final BodyDeclaration dec) return (List) dec.getStructuralProperty(desc); } + public static Type getType( Class klass, AST ast ) + { + return getType( klass.getName(), ast ); + } + + public static Type getType( String klass, AST ast ) + { + if ( Types.isPrimitive( klass ) ) { + return ast.newPrimitiveType( PrimitiveType.toCode( klass ) ); + } else if ( Types.isQualified( klass ) ) { + return ast.newQualifiedType( ast.newSimpleType( ast.newName( Types.getPackage( klass ) ) ), ast.newSimpleName( Types.toSimpleName( klass ) ) ); + } else if ( Types.isSimpleName( klass ) ) { + return ast.newSimpleType( ast.newName( klass ) ); + } else if ( Types.isGeneric( klass ) ) { + String base = Types.stripGenerics( klass ); + ParameterizedType param = ast.newParameterizedType( getType( base, ast ) ); + param.typeArguments().add( Types.getGenerics( klass ) ); + } else if ( Types.isArray( klass ) ) { + String base = Types.stripArray( klass ); + return ast.newArrayType( getType( base, ast ), Types.getArrayDimension( klass ) ); + } + return null; + } + + + public static String getter( String fieldName, String type ) { + if ( boolean.class.getName().equals( type ) ) { + return "is" + capitalize( fieldName ); + } + return "get" + capitalize( fieldName ); + } + + public static String setter( String fieldName, String type ) { + return "set" + capitalize( fieldName ); + } + + public static String capitalize( String fieldName ) { + return fieldName.substring( 0, 1 ).toUpperCase() + fieldName.substring( 1 ); + } + } diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/MethodImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/MethodImpl.java index 614bd52e..ab9fa489 100644 --- a/impl/src/main/java/org/jboss/forge/roaster/model/impl/MethodImpl.java +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/MethodImpl.java @@ -25,24 +25,32 @@ import org.jboss.forge.roaster.Roaster; import org.jboss.forge.roaster.model.Annotation; import org.jboss.forge.roaster.model.JavaType; +import org.jboss.forge.roaster.model.Method; import org.jboss.forge.roaster.model.Type; import org.jboss.forge.roaster.model.TypeVariable; import org.jboss.forge.roaster.model.Visibility; import org.jboss.forge.roaster.model.ast.AnnotationAccessor; import org.jboss.forge.roaster.model.ast.ModifierAccessor; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.impl.statements.ExpressionStatementImpl; +import org.jboss.forge.roaster.model.impl.statements.JdtStatementWrapper; +import org.jboss.forge.roaster.model.impl.statements.StatementImpl; import org.jboss.forge.roaster.model.source.AnnotationSource; +import org.jboss.forge.roaster.model.source.BlockHolder; import org.jboss.forge.roaster.model.source.JavaClassSource; import org.jboss.forge.roaster.model.source.JavaSource; import org.jboss.forge.roaster.model.source.MethodSource; import org.jboss.forge.roaster.model.source.ParameterSource; import org.jboss.forge.roaster.model.source.TypeVariableSource; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.Statements; import org.jboss.forge.roaster.model.util.Strings; import org.jboss.forge.roaster.model.util.Types; /** * @author Lincoln Baxter, III */ -public class MethodImpl> implements MethodSource +public class MethodImpl> implements MethodSource, BlockHolder> { private final AnnotationAccessor> annotations = new AnnotationAccessor>(); private final ModifierAccessor modifiers = new ModifierAccessor(); @@ -670,7 +678,7 @@ public ParameterSource addParameter(String type, String name) { if (getOrigin().requiresImport(type)) { - getOrigin().addImport(type); + getOrigin().addImport(type); } String stub = "public class Stub { public void method( " + Types.toSimpleName(Types.stripGenerics(type)) + " " + name + " ) {} }"; JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); @@ -693,4 +701,27 @@ public MethodSource removeParameter(ParameterSource parameter) method.parameters().remove(parameter.getInternal()); return this; } + + @Override + public MethodSource setBody( org.jboss.forge.roaster.model.statements.Statement statement ) { + BlockImpl> block = new BlockImpl>(); + + Statement jdtStatement = ((BlockImpl) block).wireAndGetStatement( statement.wrap(), block, cu.getAST() ); + method.setBody( (Block) jdtStatement ); + + return this; + } + + @Override + public MethodSource setBody( Expression expr ) { + ExpressionStatementImpl> expressionStatement = new ExpressionStatementImpl>( expr ); + BlockImpl> block = new BlockImpl>(); + + Statement jdtStatement = ((BlockImpl) block).wireAndGetStatement( expressionStatement.wrap(), block, cu.getAST() ); + method.setBody( (Block) jdtStatement ); + + return this; + } + + } diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/NodeImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/NodeImpl.java new file mode 100644 index 00000000..327d25ae --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/NodeImpl.java @@ -0,0 +1,65 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ArrayInitializer; +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.ASTNode; +import org.jboss.forge.roaster.model.expressions.ArrayConstructorExpression; +import org.jboss.forge.roaster.model.expressions.ArrayInit; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Wireable; +import org.jboss.forge.roaster.model.impl.expressions.DotAccessorImpl; +import org.jboss.forge.roaster.model.impl.expressions.JdtExpressionWrapper; +import org.jboss.forge.roaster.model.impl.statements.JdtStatementWrapper; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.Statement; + +public abstract class NodeImpl,T,J extends org.eclipse.jdt.core.dom.ASTNode> + implements Origin, + ASTNode { + + private T origin; + private AST ast; + + @Override + public T getOrigin() { + return origin; + } + + public void setOrigin( T origin ) { + this.origin = origin; + } + + public AST getAst() { + return ast; + } + + public void setAst( AST ast ) { + this.ast = ast; + } + + public X wireAndGetExpression( ExpressionSource expression, P parent, AST ast ) { + JdtExpressionWrapper node = (JdtExpressionWrapper) expression; + node.setOrigin( parent ); + node.setAst( ast ); + node.materialize( ast ); + return node.getInternal(); + } + + public org.eclipse.jdt.core.dom.Statement wireAndGetStatement( Statement statement, P parent, AST ast ) { + JdtStatementWrapper node = (JdtStatementWrapper) statement; + node.setOrigin( parent ); + node.setAst( ast ); + node.materialize( ast ); + return node.getInternal(); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/ParameterImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/ParameterImpl.java index 2520611a..a4dc02af 100644 --- a/impl/src/main/java/org/jboss/forge/roaster/model/impl/ParameterImpl.java +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/ParameterImpl.java @@ -15,6 +15,7 @@ import org.jboss.forge.roaster.model.ast.AnnotationAccessor; import org.jboss.forge.roaster.model.source.AnnotationSource; import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.source.MethodSource; import org.jboss.forge.roaster.model.source.ParameterSource; /** diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AbstractMethodInvokeImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AbstractMethodInvokeImpl.java new file mode 100644 index 00000000..6af99e7e --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AbstractMethodInvokeImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public abstract class AbstractMethodInvokeImpl, T extends ExpressionSource,J extends org.eclipse.jdt.core.dom.Expression> + extends InvokeableImpl + implements MethodExpression { + + protected List>> arguments = Collections.EMPTY_LIST; + + public AbstractMethodInvokeImpl( String method ) { + super( method ); + } + + @Override + public MethodExpression addArgument( Argument> argument ) { + if ( arguments.isEmpty() ) { + arguments = new LinkedList>>(); + } + arguments.add( argument ); + return this; + } + + + @Override + public MethodExpression setTarget( Expression> target ) { + this.target = target; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AccessorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AccessorImpl.java new file mode 100644 index 00000000..839e54c2 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AccessorImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.model.expressions.AccessBuilder; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.ArrayIndexer; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.source.JavaSource; + +public abstract class AccessorImpl,T extends ExpressionSource, X extends Expression> + extends ArgumentImpl + implements Accessor { + + public Field field( String fieldName ) { + return new DotAccessorImpl( this ).field( fieldName ); + } + + public Getter getter( String field, String klass ) { + return new DotAccessorImpl( this ).getter( field, klass ); + } + + public Getter getter( String field, Class klass ) { + return new DotAccessorImpl( this ).getter( field, klass ); + } + + public Setter setter( String fldName, String type, org.jboss.forge.roaster.model.expressions.Expression> value ) { + return new DotAccessorImpl( this ).setter( fldName, type, value ); + } + + public MethodExpression invoke( String method ) { + return new DotAccessorImpl( this ).invoke( method ); + } + + @Override + public AccessBuilder itemAt( org.jboss.forge.roaster.model.expressions.Expression> index ) { + return new DotAccessorImpl( this ).itemAt( index ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArgumentImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArgumentImpl.java new file mode 100644 index 00000000..250e039f --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArgumentImpl.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + + +public abstract class ArgumentImpl, T extends ExpressionSource, X extends Expression> + extends ExpressionImpl + implements Argument { + + public ArgumentImpl() { } + +} + diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayAccessImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayAccessImpl.java new file mode 100644 index 00000000..6fa7bc6e --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayAccessImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ArrayAccess; +import org.jboss.forge.roaster.model.expressions.ArrayIndexer; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ArrayAccessImpl, T extends ExpressionSource> + extends SimpleAccessorImpl + implements ArrayIndexer { + + private Expression> index; + private Expression target; + private ArrayAccess axx; + + public ArrayAccessImpl( Expression> index ) { + this.index = index; + } + + @Override + public ArrayAccess getInternal() { + return axx; + } + + @Override + public void materialize( AST ast ) { + axx = ast.newArrayAccess(); + axx.setIndex( wireAndGetExpression( index, this, ast ) ); + if ( target != null ) { + axx.setArray( wireAndGetExpression( target, this, ast ) ); + } + } + + @Override + public void wireExpression( Expression child ) { + this.target = child; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayImpl.java new file mode 100644 index 00000000..215886e9 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ArrayCreation; +import org.eclipse.jdt.core.dom.ArrayInitializer; +import org.eclipse.jdt.core.dom.ArrayType; +import org.jboss.forge.roaster.model.expressions.ArrayConstructorExpression; +import org.jboss.forge.roaster.model.expressions.ArrayInit; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public class ArrayImpl, T extends ExpressionSource> + extends ArgumentImpl + implements ArrayConstructorExpression { + + private ArrayCreation array; + + private String type; + private List>> dims = Collections.EMPTY_LIST; + private ArrayInit> init; + + public ArrayImpl( String type ) { + this.type = type; + } + + @Override + public ArrayCreation getInternal() { + return array; + } + + @Override + public void materialize( AST ast ) { + array = ast.newArrayCreation(); + array.setType( (ArrayType) JDTHelper.getType( type + new String( new char[ getDimension() ] ).replace( "\0", "[]" ), ast ) ); + for ( Expression> dim : dims ) { + array.dimensions().add( wireAndGetExpression( dim, this, ast ) ); + } + if ( init != null ) { + array.setInitializer( (ArrayInitializer) wireAndGetExpression( init, this, ast ) ); + } + } + + @Override + public ArrayConstructorExpression addDimension( Expression> dim ) { + if ( dims.isEmpty() ) { + dims = new ArrayList>>(); + } + dims.add( dim ); + return this; + } + + @Override + public ArrayConstructorExpression init( ArrayInit> array ) { + this.init = array; + return this; + } + + public int getDimension() { + if ( ! dims.isEmpty() ) { + return dims.size(); + } else if ( init != null ) { + return init.size(); + } + return 0; + } + + @Override + public ArrayInit> vec() { + ArrayInit> init = new ArrayInitImpl>(); + this.init = init; + return init; + } +} + diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayInitImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayInitImpl.java new file mode 100644 index 00000000..32ab9061 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ArrayInitImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ArrayInitializer; +import org.jboss.forge.roaster.model.expressions.ArrayInit; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ArrayInitImpl, T extends ExpressionSource> + extends ExpressionImpl + implements ArrayInit { + + private List> elements = Collections.EMPTY_LIST; + + private ArrayInitializer init; + + @Override + public ArrayInit addElement( ArrayInit subRow ) { + if ( elements.isEmpty() ) { + elements = new ArrayList( ); + } + elements.add( subRow ); + return this; + } + + @Override + public ArrayInit addElement( Expression subElement ) { + if ( elements.isEmpty() ) { + elements = new ArrayList( ); + } + elements.add( subElement ); + return this; + } + + @Override + public int size() { + return elements.size(); + } + + @Override + public ArrayInitializer getInternal() { + return init; + } + + @Override + public void materialize( AST ast ) { + this.init = ast.newArrayInitializer(); + for ( ExpressionSource src : elements ) { + this.init.expressions().add( wireAndGetExpression( src, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AssignImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AssignImpl.java new file mode 100644 index 00000000..08488132 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/AssignImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.Assignment; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.AssignExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class AssignImpl, T extends ExpressionSource> + extends ArgumentImpl + implements AssignExpression { + + private Assignment axx; + + private Accessor left; + private Expression right; + private org.jboss.forge.roaster.model.expressions.Assignment op; + + public AssignImpl( org.jboss.forge.roaster.model.expressions.Assignment op ) { + this.op = op; + } + + @Override + public AssignExpression setLeft( Accessor left ) { + this.left = left; + return this; + } + + @Override + public AssignExpression setRight( Expression right ) { + this.right = right; + return this; + } + + @Override + public Assignment getInternal() { + return axx; + } + + @Override + public void materialize( AST ast ) { + axx = ast.newAssignment(); + axx.setOperator( Assignment.Operator.toOperator( op.getOp() ) ); + + if ( left != null ) { + axx.setLeftHandSide( wireAndGetExpression( left, this, ast ) ); + } + if ( right != null ) { + axx.setRightHandSide( wireAndGetExpression( right, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BaseInvokeableImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BaseInvokeableImpl.java new file mode 100644 index 00000000..9a446777 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BaseInvokeableImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public abstract class BaseInvokeableImpl, T extends ExpressionSource, J extends org.eclipse.jdt.core.dom.Expression> + extends AccessorImpl + implements InvokeExpression { + + protected String method; + + public BaseInvokeableImpl( String method ) { + this.method = method; + } + + @Override + public Accessor dot() { + return new DotAccessorImpl( this ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BooleanLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BooleanLiteralImpl.java new file mode 100644 index 00000000..482b1ab3 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/BooleanLiteralImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.BooleanLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class BooleanLiteralImpl, T extends ExpressionSource> + extends LiteralImpl { + + private boolean val; + + private BooleanLiteral literal; + + public BooleanLiteralImpl( boolean val ) { + this.val = val; + } + + @Override + public BooleanLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newBooleanLiteral( val ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CastImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CastImpl.java new file mode 100644 index 00000000..b39377ce --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CastImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; +import org.jboss.forge.roaster.model.expressions.CastExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class CastImpl, T extends ExpressionSource> + extends ArgumentImpl + implements CastExpression { + + private org.eclipse.jdt.core.dom.CastExpression cast; + + private String type; + private Expression> expression; + + public CastImpl( String klass, Expression> expression ) { + this.type = klass; + this.expression = expression; + } + + + @Override + public org.eclipse.jdt.core.dom.CastExpression getInternal() { + return cast; + } + + @Override + public void materialize( AST ast ) { + cast = ast.newCastExpression(); + cast.setType( JDTHelper.getType( type, ast ) ); + if ( expression != null ) { + org.eclipse.jdt.core.dom.Expression expr = wireAndGetExpression( expression, this, ast ); + ParenthesizedExpression paren = ast.newParenthesizedExpression(); + paren.setExpression( expr ); + cast.setExpression( paren ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CharacterLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CharacterLiteralImpl.java new file mode 100644 index 00000000..96b5d016 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/CharacterLiteralImpl.java @@ -0,0 +1,36 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.CharacterLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class CharacterLiteralImpl, T extends ExpressionSource> + extends LiteralImpl { + + private Character val; + + private CharacterLiteral literal; + + public CharacterLiteralImpl( Character val ) { + this.val = val; + } + + @Override + public CharacterLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newCharacterLiteral(); + literal.setCharValue( val ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ClassLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ClassLiteralImpl.java new file mode 100644 index 00000000..208bb0e0 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ClassLiteralImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.TypeLiteral; +import org.jboss.forge.roaster.model.expressions.ClassLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ClassLiteralImpl, T extends ExpressionSource> + extends AccessorImpl + implements ClassLiteral { + + private String val; + + private TypeLiteral literal; + + public ClassLiteralImpl( String val ) { + this.val = val; + } + + @Override + public TypeLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newTypeLiteral(); + literal.setType( JDTHelper.getType( val, ast ) ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ConstructorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ConstructorImpl.java new file mode 100644 index 00000000..17902dc9 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ConstructorImpl.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ConstructorExpression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + + +public class ConstructorImpl, T extends ExpressionSource> + extends ArgumentImpl + implements ConstructorExpression { + + private ClassInstanceCreation constr; + + private String type; + private List>> arguments = Collections.EMPTY_LIST; + + public ConstructorImpl( String type ) { + this.type = type; + } + + @Override + public ConstructorExpression addArgument( Argument> arg ) { + if ( arguments.isEmpty() ) { + arguments = new LinkedList>>(); + } + arguments.add( arg ); + return this; + } + + @Override + public ClassInstanceCreation getInternal() { + return constr; + } + + @Override + public void materialize( AST ast ) { + constr = ast.newClassInstanceCreation(); + constr.setType( JDTHelper.getType( type, ast ) ); + + for ( Argument> arg : arguments ) { + constr.arguments().add( wireAndGetExpression( arg, this, ast ) ); + } + } +} + diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DeclareExpressionImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DeclareExpressionImpl.java new file mode 100644 index 00000000..5ae8f3e1 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DeclareExpressionImpl.java @@ -0,0 +1,56 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class DeclareExpressionImpl, T extends ExpressionSource> + extends ArgumentImpl + implements DeclareExpression { + + private VariableDeclarationExpression var; + + private String type; + private String name; + private Expression init; + + public DeclareExpressionImpl( String type, String name ) { + this.type = type; + this.name = name; + } + + @Override + public DeclareExpression init( Expression expr ) { + this.init = expr; + return this; + } + + @Override + public VariableDeclarationExpression getInternal() { + return var; + } + + @Override + public void materialize( AST ast ) { + VariableDeclarationFragment frag = ast.newVariableDeclarationFragment(); + frag.setName( ast.newSimpleName( name ) ); + var = ast.newVariableDeclarationExpression( frag ); + var.setType( JDTHelper.getType( type, ast ) ); + + if ( init != null ) { + frag.setInitializer( wireAndGetExpression( init, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DotAccessorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DotAccessorImpl.java new file mode 100644 index 00000000..c5559f03 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/DotAccessorImpl.java @@ -0,0 +1,96 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.expressions.AccessBuilder; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.ArrayIndexer; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.expressions.Variable; +import org.jboss.forge.roaster.model.expressions.Wireable; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.spi.ExpressionFactoryImpl; + +public class DotAccessorImpl,T extends ExpressionSource> + extends ExpressionFactoryImpl + implements Accessor { + + private Expression parent; + + public DotAccessorImpl( Expression parent ) { + this.parent = parent; + } + + @Override + public T getOrigin() { + return null; + } + + @Override + public Field field( String fieldName ) { + Field field = super.field( fieldName ); + swap( field, this.parent ); + return field; + } + + @Override + public Getter getter( String fieldName, String type ) { + Getter getter = super.getter( fieldName, type ); + swap( getter, this.parent ); + return getter; + } + + @Override + public Setter setter( String fldName, String type, org.jboss.forge.roaster.model.expressions.Expression> value ) { + Setter setter = super.setter( fldName, type, value ); + swap( setter, this.parent ); + return setter; + } + + @Override + public Variable var( String varName ) { + Variable var = super.var( varName ); + swap( var, this.parent ); + return var; + } + + @Override + public MethodExpression invoke( String method ) { + MethodExpression invoke = super.invoke( method ); + swap( invoke, this.parent ); + return invoke; + } + + @Override + public AccessBuilder itemAt( Expression> index ) { + AccessBuilder accessor = super.itemAt( index ); + swap( accessor,this.parent ); + return accessor; + } + + + private void swap( Expression child, Expression parent ) { + Wireable sub = (Wireable) child; + Wireable sup = (Wireable) parent; + + sub.wireParent( sup.getParent() ); + sup.wireParent( child ); + sub.wireExpression( parent ); + } + + @Override + public void materialize( AST ast ) { + super.materialize( ast ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ExpressionImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ExpressionImpl.java new file mode 100644 index 00000000..63acf0a7 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ExpressionImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.spi.ExpressionFactoryImpl; + +public abstract class ExpressionImpl, T extends ExpressionSource, X extends org.eclipse.jdt.core.dom.Expression> + extends ExpressionFactoryImpl + implements Expression, + JdtExpressionWrapper { + + private ExpressionSource parent; + + public ExpressionImpl() { } + + public ExpressionSource getParent() { + return parent; + } + + public void wireParent( ExpressionSource parent ) { + this.parent = parent; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/FieldImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/FieldImpl.java new file mode 100644 index 00000000..4cce94e9 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/FieldImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class FieldImpl, T extends ExpressionSource> + extends SimpleAccessorImpl + implements Field { + + private FieldAccess fld; + + private String fieldName; + private Expression expression; + + public FieldImpl( String fieldName ) { + this.fieldName = fieldName; + } + + @Override + public FieldAccess getInternal() { + return fld; + } + + @Override + public void materialize( AST ast ) { + fld = ast.newFieldAccess(); + fld.setName( ast.newSimpleName( fieldName ) ); + if ( expression == null ) { + fld.setExpression( ast.newThisExpression() ); + } else { + fld.setExpression( wireAndGetExpression( expression, this, ast ) ); + } + } + + @Override + public void wireExpression( Expression child ) { + this.expression = child; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/GetterImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/GetterImpl.java new file mode 100644 index 00000000..786f9a04 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/GetterImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class GetterImpl, T extends ExpressionSource> + extends InvokeableImpl + implements Getter { + + + protected MethodInvocation invoke; + + public GetterImpl( String fieldName, String type ) { + super( JDTHelper.getter( fieldName, type ) ); + } + + @Override + public void wireExpression( Expression child ) { + setTarget( (Expression>) child ); + } + + @Override + public InvokeExpression setTarget( Expression> target ) { + this.target = target; + return this; + } + + @Override + public MethodInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newMethodInvocation(); + + getInternal().setName( ast.newSimpleName( method ) ); + if ( target != null ) { + getInternal().setExpression( wireAndGetExpression( target, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InstanceofImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InstanceofImpl.java new file mode 100644 index 00000000..e997c8c7 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InstanceofImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InstanceofExpression; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class InstanceofImpl, T extends ExpressionSource> + extends ArgumentImpl + implements InstanceofExpression { + + private org.eclipse.jdt.core.dom.InstanceofExpression isA; + + private String type; + private Expression> expression; + + public InstanceofImpl( String klass, Expression> expression ) { + this.type = klass; + this.expression = expression; + } + + @Override + public org.eclipse.jdt.core.dom.InstanceofExpression getInternal() { + return isA; + } + + @Override + public void materialize( AST ast ) { + isA = ast.newInstanceofExpression(); + isA.setRightOperand( JDTHelper.getType( type, ast ) ); + if ( expression != null ) { + org.eclipse.jdt.core.dom.Expression expr = wireAndGetExpression( expression, this, ast ); + isA.setLeftOperand( expr ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InvokeableImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InvokeableImpl.java new file mode 100644 index 00000000..42cf2926 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/InvokeableImpl.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public abstract class InvokeableImpl, T extends ExpressionSource, J extends org.eclipse.jdt.core.dom.Expression> + extends BaseInvokeableImpl + implements InvokeExpression { + + protected Expression> target; + + + public InvokeableImpl( String method ) { + super( method ); + } + + @Override + public Accessor dot() { + return new DotAccessorImpl( this ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/JdtExpressionWrapper.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/JdtExpressionWrapper.java new file mode 100644 index 00000000..ffe53ba0 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/JdtExpressionWrapper.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + + +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.Origin; +import org.jboss.forge.roaster.model.ASTNode; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface JdtExpressionWrapper,T,J extends Expression> + extends ASTNode, + Origin { + + + public void setOrigin( T parent ); + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/LiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/LiteralImpl.java new file mode 100644 index 00000000..7f3b98e8 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/LiteralImpl.java @@ -0,0 +1,21 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Literal; +import org.jboss.forge.roaster.model.source.JavaSource; + +public abstract class LiteralImpl, T extends ExpressionSource, L extends Expression> + extends ArgumentImpl + implements Literal { + + public LiteralImpl() {} + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/MethodInvokeImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/MethodInvokeImpl.java new file mode 100644 index 00000000..403b2e37 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/MethodInvokeImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.expressions.Wireable; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class MethodInvokeImpl, T extends ExpressionSource> + extends AbstractMethodInvokeImpl + implements Wireable { + + protected MethodInvocation invoke; + + public MethodInvokeImpl( String method ) { + super( method ); + } + + @Override + public MethodInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newMethodInvocation(); + + getInternal().setName( ast.newSimpleName( method ) ); + if ( target != null ) { + getInternal().setExpression( wireAndGetExpression( target, this, ast ) ); + } + for ( Argument> arg : arguments ) { + getInternal().arguments().add( wireAndGetExpression( arg, this, ast ) ); + } + } + + @Override + public void wireExpression( Expression child ) { + setTarget( (Expression>) child ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NotImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NotImpl.java new file mode 100644 index 00000000..87080ed2 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NotImpl.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.PrefixOp; +import org.jboss.forge.roaster.model.expressions.UnaryExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class NotImpl, T extends ExpressionSource> + extends UnaryImpl { + + public NotImpl( Argument> expr ) { + super( PrefixOp.NOT, expr ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NullLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NullLiteralImpl.java new file mode 100644 index 00000000..69105e6f --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NullLiteralImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.NullLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class NullLiteralImpl, T extends ExpressionSource> + extends LiteralImpl { + + private NullLiteral literal; + + public NullLiteralImpl() {} + + @Override + public NullLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newNullLiteral(); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NumberLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NumberLiteralImpl.java new file mode 100644 index 00000000..e19931ef --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/NumberLiteralImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.NumberLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class NumberLiteralImpl, T extends ExpressionSource> + extends LiteralImpl { + + private Number val; + + private NumberLiteral literal; + + public NumberLiteralImpl( Number val ) { + this.val = val; + } + + @Override + public NumberLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newNumberLiteral( val.toString() ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/OperatorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/OperatorImpl.java new file mode 100644 index 00000000..dac5e17f --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/OperatorImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.InfixExpression; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.expressions.OperatorExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class OperatorImpl, T extends ExpressionSource> + extends ArgumentImpl + implements OperatorExpression { + + private InfixExpression expr; + + private Op operator; + private List>> argumentList = Collections.EMPTY_LIST; + + public OperatorImpl( Op op ) { + this.operator = op; + } + + @Override + public OperatorExpression addArgument( Argument> arg ) { + if ( argumentList.isEmpty() ) { + argumentList = new LinkedList>>(); + } + argumentList.add( arg ); + return this; + } + + @Override + public InfixExpression getInternal() { + return expr; + } + + @Override + public void materialize( AST ast ) { + expr = ast.newInfixExpression(); + + expr.setOperator( InfixExpression.Operator.toOperator( this.operator.getOp() ) ); + + for ( Argument> arg : argumentList ) { + wireArg( arg, ast ); + } + } + + protected void wireArg( Argument> arg, AST ast ) { + Expression child = wireAndGetExpression( arg, this, ast ); + + if ( child.getNodeType() == ASTNode.INFIX_EXPRESSION ) { + if ( ! expr.getOperator().equals( ((InfixExpression) child).getOperator() ) ) { + ParenthesizedExpression par = ast.newParenthesizedExpression(); + par.setExpression( child ); + child = par; + } + } + + InfixExpression infix = ((InfixExpression) expr); + if ( "MISSING".equals( infix.getLeftOperand().toString() ) ) { + infix.setLeftOperand( child ); + } else if ( "MISSING".equals( infix.getRightOperand().toString() ) ) { + infix.setRightOperand( child ); + } else { + org.eclipse.jdt.core.dom.Expression prev = infix.getRightOperand(); + InfixExpression more = ast.newInfixExpression(); + more.setOperator( infix.getOperator() ); + infix.setRightOperand( more ); + prev.delete(); + more.setLeftOperand( prev ); + more.setRightOperand( child ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ParenImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ParenImpl.java new file mode 100644 index 00000000..809d5e1b --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/ParenImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.ParenExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ParenImpl, T extends ExpressionSource> + extends ArgumentImpl + implements ParenExpression { + + ParenthesizedExpression paren; + + private Expression inner; + + public ParenImpl( Expression child ) { + inner = child; + } + + @Override + public ParenthesizedExpression getInternal() { + return paren; + } + + @Override + public void materialize( AST ast ) { + paren = ast.newParenthesizedExpression(); + + if ( inner != null ) { + paren.setExpression( wireAndGetExpression( inner, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/PostFixImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/PostFixImpl.java new file mode 100644 index 00000000..2cdabe04 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/PostFixImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.PostfixExpression; +import org.jboss.forge.roaster.model.expressions.BareArgument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class PostFixImpl, T extends ExpressionSource> + extends ArgumentImpl { + + private PostfixExpression post; + + private String op; + private BareArgument arg; + + public PostFixImpl( String op, BareArgument arg ) { + this.op = op; + this.arg = arg; + } + + @Override + public PostfixExpression getInternal() { + return post; + } + + @Override + public void materialize( AST ast ) { + post = ast.newPostfixExpression(); + post.setOperator( PostfixExpression.Operator.toOperator( op ) ); + + if ( arg != null ) { + post.setOperand( wireAndGetExpression( arg, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SelfArgumentImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SelfArgumentImpl.java new file mode 100644 index 00000000..a9ba6ddd --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SelfArgumentImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ThisExpression; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Wireable; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SelfArgumentImpl, T extends ExpressionSource> + extends AccessorImpl + implements Accessor, + Wireable { + + public SelfArgumentImpl() {} + + ThisExpression self; + + @Override + public ThisExpression getInternal() { + return self; + } + + @Override + public void materialize( AST ast ) { + self = ast.newThisExpression(); + } + + @Override + public void wireExpression( org.jboss.forge.roaster.model.expressions.Expression child ) { + throw new UnsupportedOperationException( "This method should not be invoked, since 'this' can only be the start of a dot-chain" ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SetterImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SetterImpl.java new file mode 100644 index 00000000..fc579df8 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SetterImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SetterImpl, T extends ExpressionSource> + extends MethodInvokeImpl + implements Setter { + + private MethodInvocation setter; + + private Expression> value; + + public SetterImpl( String fieldName, String type, Expression> value ) { + super( JDTHelper.setter( fieldName, type ) ); + this.value = value; + } + + @Override + public MethodInvocation getInternal() { + return setter; + } + + @Override + public void materialize( AST ast ) { + super.materialize( ast ); + if ( value != null ) { + setter.arguments().add( wireAndGetExpression( value, this, ast ) ); + } + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SimpleAccessorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SimpleAccessorImpl.java new file mode 100644 index 00000000..8d6cf5cd --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SimpleAccessorImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.PostfixExpression; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.BareArgument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +public abstract class SimpleAccessorImpl, T extends ExpressionSource, J extends Expression> + extends AccessorImpl + implements BareArgument { + + @Override + public Argument inc() { + return new PostFixImpl( PostfixExpression.Operator.INCREMENT.toString(), this ); + } + + @Override + public Argument dec() { + return new PostFixImpl( PostfixExpression.Operator.DECREMENT.toString(), this ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StaticClassAccessorImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StaticClassAccessorImpl.java new file mode 100644 index 00000000..c6fa8878 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StaticClassAccessorImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.Name; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Wireable; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class StaticClassAccessorImpl, T extends ExpressionSource> + extends AccessorImpl + implements Wireable { + + private Name klass; + + private String name; + + private Expression expression; + + public StaticClassAccessorImpl( String name ) { + this.name = name; + } + + @Override + public Name getInternal() { + return klass; + } + + @Override + public void materialize( AST ast ) { + klass = ast.newName( name ); + } + + @Override + public void wireExpression( Expression child ) { + this.expression = child; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StringLiteralImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StringLiteralImpl.java new file mode 100644 index 00000000..67ccf153 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/StringLiteralImpl.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.StringLiteral; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Literal; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class StringLiteralImpl, T extends ExpressionSource> + extends AccessorImpl + implements Literal { + + private String val; + + private StringLiteral literal; + + public StringLiteralImpl( String val ) { + this.val = val; + } + + @Override + public StringLiteral getInternal() { + return literal; + } + + @Override + public void materialize( AST ast ) { + literal = ast.newStringLiteral(); + literal.setLiteralValue( val ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperFieldImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperFieldImpl.java new file mode 100644 index 00000000..a57e00ed --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperFieldImpl.java @@ -0,0 +1,56 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.PostfixExpression; +import org.eclipse.jdt.core.dom.SuperFieldAccess; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SuperFieldImpl, T extends ExpressionSource> + extends AccessorImpl + implements Field { + + private SuperFieldAccess fld; + + private String fieldName; + + public SuperFieldImpl( String fieldName ) { + this.fieldName = fieldName; + } + + @Override + public SuperFieldAccess getInternal() { + return fld; + } + + @Override + public void materialize( AST ast ) { + fld = ast.newSuperFieldAccess(); + fld.setName( ast.newSimpleName( fieldName ) ); + } + + @Override + public Argument inc() { + return new PostFixImpl( PostfixExpression.Operator.INCREMENT.toString(), this ); + } + + @Override + public Argument dec() { + return new PostFixImpl( PostfixExpression.Operator.DECREMENT.toString(), this ); + } + + @Override + public void wireExpression( Expression child ) { + throw new UnsupportedOperationException( "Unable to set an access path other than 'super' on a SuperField " ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperGetterImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperGetterImpl.java new file mode 100644 index 00000000..980ebd9c --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperGetterImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.InvokeExpression; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SuperGetterImpl, T extends ExpressionSource> + extends InvokeableImpl + implements Getter { + + + protected SuperMethodInvocation invoke; + + public SuperGetterImpl( String fieldName, String type ) { + super( JDTHelper.getter( fieldName, type ) ); + } + + @Override + public void wireExpression( Expression child ) { + setTarget( (Expression>) child ); + } + + @Override + public InvokeExpression setTarget( Expression> target ) { + this.target = target; + return this; + } + + @Override + public SuperMethodInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newSuperMethodInvocation(); + + getInternal().setName( ast.newSimpleName( method ) ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperImpl.java new file mode 100644 index 00000000..d3ce7b4a --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.expressions.Super; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.spi.ExpressionFactoryImpl; + +public class SuperImpl,T extends ExpressionSource> + extends ExpressionFactoryImpl + implements Super { + + @Override + public Field field( String fieldName ) { + return new SuperFieldImpl( fieldName ); + + } + + @Override + public Getter getter( String field, String klass ) { + return new SuperGetterImpl( field, klass ); + } + + @Override + public Getter getter( String field, Class klass ) { + return getter( field, klass.getName() ); + } + + @Override + public MethodExpression invoke( String method ) { + return new SuperMethodInvokeImpl( method ); + } + + @Override + public Setter setter( String fldName, Class type, Expression value ) { + return setter( fldName, type.getName(), value ); + } + + @Override + public Setter setter( String fldName, String type, Expression value ) { + return new SuperSetterImpl( fldName, type, value ); + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperMethodInvokeImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperMethodInvokeImpl.java new file mode 100644 index 00000000..fab3cbe0 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperMethodInvokeImpl.java @@ -0,0 +1,41 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SuperMethodInvokeImpl, T extends ExpressionSource> + extends AbstractMethodInvokeImpl { + + protected SuperMethodInvocation invoke; + + public SuperMethodInvokeImpl( String method ) { + super( method ); + } + + @Override + public SuperMethodInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newSuperMethodInvocation(); + + invoke.setName( ast.newSimpleName( method ) ); + for ( Argument> arg : arguments ) { + invoke.arguments().add( wireAndGetExpression( arg, this, ast ) ); + } + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperSetterImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperSetterImpl.java new file mode 100644 index 00000000..65b76f1b --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/SuperSetterImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class SuperSetterImpl, T extends ExpressionSource> + extends AbstractMethodInvokeImpl + implements Setter { + + private SuperMethodInvocation setter; + + private Expression> value; + + public SuperSetterImpl( String fieldName, String type, Expression> value ) { + super( JDTHelper.setter( fieldName, type ) ); + this.value = value; + } + + @Override + public SuperMethodInvocation getInternal() { + return setter; + } + + @Override + public void materialize( AST ast ) { + setter = ast.newSuperMethodInvocation(); + setter.setName( ast.newSimpleName( method ) ); + if ( value != null ) { + setter.arguments().add( wireAndGetExpression( value, this, ast ) ); + } + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/TernaryImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/TernaryImpl.java new file mode 100644 index 00000000..cbdd054b --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/TernaryImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ConditionalExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.TernaryExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class TernaryImpl, T extends ExpressionSource> + extends ArgumentImpl + implements TernaryExpression { + + private ConditionalExpression ternary; + + private Expression condition; + private Expression onTrue; + private Expression onFalse; + + public TernaryImpl() {} + + @Override + public TernaryExpression setCondition( Expression expression ) { + this.condition = expression; + return this; + } + + @Override + public TernaryExpression setIfExpression( Expression onTrue ) { + this.onTrue = onTrue; + return this; + } + + @Override + public TernaryExpression setElseExpression( Expression onFalse ) { + this.onFalse = onFalse; + return this; + } + + @Override + public ConditionalExpression getInternal() { + return ternary; + } + + @Override + public void materialize( AST ast ) { + ternary = ast.newConditionalExpression(); + + if ( condition != null ) { + ternary.setExpression( wireAndGetExpression( condition, this, ast ) ); + } + if ( onTrue != null ) { + ternary.setThenExpression( wireAndGetExpression( onTrue, this, ast ) ); + } + if ( onFalse != null ) { + ternary.setElseExpression( wireAndGetExpression( onFalse, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/UnaryImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/UnaryImpl.java new file mode 100644 index 00000000..f9977882 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/UnaryImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.PrefixExpression; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.PrefixOp; +import org.jboss.forge.roaster.model.expressions.UnaryExpression; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class UnaryImpl, T extends ExpressionSource> + extends ArgumentImpl + implements UnaryExpression { + + PrefixExpression expr; + + private Argument> arg; + private PrefixOp op; + + public UnaryImpl( PrefixOp op, Argument> expr ) { + this.arg = expr; + this.op = op; + } + + @Override + public PrefixExpression getInternal() { + return expr; + } + + @Override + public void materialize( AST ast ) { + expr = ast.newPrefixExpression(); + expr.setOperator( PrefixExpression.Operator.toOperator( op.getOp() ) ); + + if ( arg != null ) { + expr.setOperand( wireAndGetExpression( arg, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/VarArgumentImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/VarArgumentImpl.java new file mode 100644 index 00000000..b157b8e5 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/expressions/VarArgumentImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.expressions; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.Name; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Variable; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class VarArgumentImpl, T extends ExpressionSource> + extends SimpleAccessorImpl + implements Variable { + + private Name var; + + private String name; + + private Expression expression; + + public VarArgumentImpl( String name ) { + this.name = name; + } + + @Override + public Name getInternal() { + return var; + } + + @Override + public void materialize( AST ast ) { + var = ast.newName( name ); + } + + @Override + public void wireExpression( Expression child ) { + this.expression = child; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssertStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssertStatementImpl.java new file mode 100644 index 00000000..1b314b89 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssertStatementImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.AssertStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class AssertStatementImpl, T extends Block>> + extends StatementImpl> + implements org.jboss.forge.roaster.model.statements.AssertStatement { + + private AssertStatement assrt; + private Expression> assertion; + private Expression> message; + + + @Override + public AssertStatement getInternal() { + return assrt; + } + + @Override + public void materialize( AST ast ) { + assrt = ast.newAssertStatement(); + if ( assertion != null ) { + assrt.setExpression( wireAndGetExpression( assertion, this, ast ) ); + } + if ( message != null ) { + assrt.setMessage( wireAndGetExpression( message, this, ast ) ); + } + } + + @Override + public org.jboss.forge.roaster.model.statements.AssertStatement setAssertion( Expression> expression ) { + this.assertion = expression; + return this; + } + + @Override + public org.jboss.forge.roaster.model.statements.AssertStatement setMessage( Expression> msg ) { + this.message = msg; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssignStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssignStatementImpl.java new file mode 100644 index 00000000..69f842bd --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/AssignStatementImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.Assignment; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.AssignStatement; + +public class AssignStatementImpl, T extends Block>> + extends StatementImpl> + implements AssignStatement { + + private Assignment axx; + private ExpressionStatement statement; + + private Expression left; + private Expression right; + + public AssignStatementImpl() {} + + @Override + public AssignStatement setRight( Expression right ) { + this.right = right; + return this; + } + + @Override + public AssignStatement setLeft( Accessor left ) { + this.left = left; + return this; + } + + @Override + public ExpressionStatement getInternal() { + return statement; + } + + public void materialize( AST ast ) { + axx = ast.newAssignment(); + axx.setOperator( Assignment.Operator.ASSIGN ); + statement = ast.newExpressionStatement( axx ); + + if ( left != null ) { + axx.setLeftHandSide( wireAndGetExpression( left, this, getAst() ) ); + } + if ( right != null ) { + axx.setRightHandSide( wireAndGetExpression( right, this, getAst() ) ); + } + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BlockStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BlockStatementImpl.java new file mode 100644 index 00000000..86b5f5ca --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BlockStatementImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.Statement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class BlockStatementImpl, T extends Block>> + extends StatementImpl> + implements BlockStatement { + + private org.eclipse.jdt.core.dom.Block block; + private List> statements = Collections.EMPTY_LIST; + + public BlockStatementImpl() { } + + @Override + public BlockStatement addStatement( Statement statement ) { + if ( statements.isEmpty() ) { + statements = new LinkedList>(); + } + statements.add( statement ); + return this; + } + + @Override + public BlockStatement addStatement( Expression expression ) { + return addStatement( new ExpressionStatementImpl>( expression ) ); + } + + @Override + public org.eclipse.jdt.core.dom.Block getInternal() { + return block; + } + + @Override + public void materialize( AST ast ) { + block = ast.newBlock(); + + for ( Statement statement : statements ) { + block.statements().add( wireAndGetStatement( statement, this, ast ) ); + } + } + + public BlockStatement wrap() { + return this; + } + +} \ No newline at end of file diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BreakStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BreakStatementImpl.java new file mode 100644 index 00000000..90696d14 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/BreakStatementImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.BreakStatement; + +public class BreakStatementImpl, T extends Block>> + extends StatementImpl> + implements BreakStatement { + + private org.eclipse.jdt.core.dom.BreakStatement ret; + + private String target; + + public BreakStatementImpl() { } + + @Override + public org.eclipse.jdt.core.dom.BreakStatement getInternal() { + return ret; + } + + @Override + public void materialize( AST ast ) { + ret = ast.newBreakStatement(); + if ( target != null ) { + ret.setLabel( ast.newSimpleName( target ) ); + } + } + + @Override + public BreakStatement setTarget( String label ) { + this.target = label; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ContinueStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ContinueStatementImpl.java new file mode 100644 index 00000000..3bc4da89 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ContinueStatementImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.ContinueStatement; + +public class ContinueStatementImpl, T extends Block>> + extends StatementImpl> + implements ContinueStatement { + + private org.eclipse.jdt.core.dom.ContinueStatement ret; + + private String target; + + public ContinueStatementImpl() { } + + @Override + public org.eclipse.jdt.core.dom.ContinueStatement getInternal() { + return ret; + } + + @Override + public void materialize( AST ast ) { + ret = ast.newContinueStatement(); + if ( target != null ) { + ret.setLabel( ast.newSimpleName( target ) ); + } + } + + @Override + public ContinueStatement setTarget( String label ) { + this.target = label; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DeclareStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DeclareStatementImpl.java new file mode 100644 index 00000000..fee1bbc5 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DeclareStatementImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.expressions.Expressions; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.DeclareStatement; + +public class DeclareStatementImpl, T extends Block>> + extends StatementImpl> + implements DeclareStatement { + + private VariableDeclarationStatement var; + + private Expression initializer; + private String name; + private String type; + + public DeclareStatementImpl() { } + + @Override + public DeclareStatement setVariable( Class klass, String name ) { + return setVariable( klass.getName(), name ); + } + + public DeclareStatement setVariable( String type, String name ) { + this.name = name; + this.type = type; + return this; + } + + @Override + public DeclareStatement setInitExpression( Expression init ) { + this.initializer = init; + return this; + } + + @Override + public DeclareStatement setDefaultInitExpression() { + setInitExpression( Expressions.zeroLiteral( type ) ); + return this; + } + + public VariableDeclarationFragment getMainVar() { + return (VariableDeclarationFragment) var.fragments().iterator().next(); + } + + @Override + public VariableDeclarationStatement getInternal() { + return var; + } + + @Override + public void materialize( AST ast ) { + var = ast.newVariableDeclarationStatement( ast.newVariableDeclarationFragment() ); + + var.setType( JDTHelper.getType( type, ast ) ); + getMainVar().setName( ast.newSimpleName( name ) ); + + if ( initializer != null ) { + getMainVar().setInitializer( wireAndGetExpression( initializer, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DoWhileStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DoWhileStatementImpl.java new file mode 100644 index 00000000..80531185 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/DoWhileStatementImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.DoStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.DoWhileStatement; +import org.jboss.forge.roaster.model.statements.Statement; + +public class DoWhileStatementImpl, T extends Block>> + extends StatementImpl> + implements DoWhileStatement { + + private DoStatement rep; + + private Statement body; + private Expression condition; + + public DoWhileStatementImpl() { } + + @Override + public DoWhileStatement setBody( Statement statement ) { + this.body = statement; + return this; + } + + @Override + public DoWhileStatement setCondition( Expression expr ) { + this.condition = expr; + return this; + } + + @Override + public DoStatement getInternal() { + return rep; + } + + @Override + public void materialize( AST ast ) { + rep = ast.newDoStatement(); + + if ( body != null ) { + rep.setBody( wireAndGetStatement( body.wrap(), this, ast ) ); + } + if ( condition != null ) { + rep.setExpression( wireAndGetExpression( condition, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ExpressionStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ExpressionStatementImpl.java new file mode 100644 index 00000000..90298d29 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ExpressionStatementImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ExpressionStatementImpl, T extends Block>> + extends StatementImpl> { + + private Expression> expression; + private ExpressionStatement exprStatement; + + public ExpressionStatementImpl( Expression expr ) { + this.expression = expr; + } + + public ExpressionStatementImpl() { + } + + @Override + public ExpressionStatement getInternal() { + return exprStatement; + } + + public void materialize( AST ast ) { + exprStatement = ast.newExpressionStatement( wireAndGetExpression( expression, this, getAst() ) ); + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForEachStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForEachStatementImpl.java new file mode 100644 index 00000000..3f45f87b --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForEachStatementImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.EnhancedForStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.ForEachStatement; +import org.jboss.forge.roaster.model.statements.Statement; + +public class ForEachStatementImpl, T extends Block>> + extends StatementImpl> + implements ForEachStatement { + + private EnhancedForStatement iter; + + private String name; + private String type; + private Expression source; + private Statement body; + + public ForEachStatementImpl() { } + + @Override + public ForEachStatement setIterator( String klass, String name ) { + this.name = name; + this.type = klass; + return this; + } + + @Override + public ForEachStatement setIterator( Class klass, String name ) { + return setIterator( klass.getName(), name ); + } + + @Override + public ForEachStatement setSource( Expression expr ) { + this.source = expr; + return this; + } + + @Override + public ForEachStatement setBody( Statement statement ) { + this.body = statement; + return this; + } + + @Override + public EnhancedForStatement getInternal() { + return iter; + } + + @Override + public void materialize( AST ast ) { + iter = ast.newEnhancedForStatement(); + + iter.getParameter().setName( iter.getAST().newSimpleName( name ) ); + iter.getParameter().setType( JDTHelper.getType( type, iter.getAST() ) ); + + if ( source != null ) { + iter.setExpression( wireAndGetExpression( source, this, ast ) ); + } + if ( body != null ) { + iter.setBody( wireAndGetStatement( body.wrap(), this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForStatementImpl.java new file mode 100644 index 00000000..a9feaad0 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ForStatementImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.ForStatement; +import org.jboss.forge.roaster.model.statements.Statement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class ForStatementImpl, T extends Block>> + extends StatementImpl> + implements ForStatement { + + private org.eclipse.jdt.core.dom.ForStatement iter; + + private List declarations = Collections.EMPTY_LIST; + private List updaters = Collections.EMPTY_LIST; + private Expression condition; + private Statement body; + + public ForStatementImpl() { } + + @Override + public ForStatement addDeclaration( DeclareExpression declaration ) { + if ( declarations.isEmpty() ) { + declarations = new LinkedList(); + } + declarations.add( declaration ); + return this; + } + + @Override + public ForStatement addUpdate( Expression expression ) { + if ( updaters.isEmpty() ) { + updaters = new LinkedList(); + } + updaters.add( expression ); + return this; + } + + @Override + public ForStatement setCondition( Expression booleanExpression ) { + this.condition = booleanExpression; + return this; + } + + @Override + public ForStatement setBody( Statement statement ) { + this.body = statement; + return this; + } + + @Override + public org.eclipse.jdt.core.dom.ForStatement getInternal() { + return iter; + } + + @Override + public void materialize( AST ast ) { + iter = ast.newForStatement(); + + for ( DeclareExpression declaration : declarations ) { + VariableDeclarationExpression declare = (VariableDeclarationExpression) wireAndGetExpression( declaration, this, ast ); + if ( iter.initializers().isEmpty() ) { + iter.initializers().add( declare ); + } else { + VariableDeclarationExpression existing = (VariableDeclarationExpression) iter.initializers().get( 0 ); + VariableDeclarationFragment frag = (VariableDeclarationFragment) declare.fragments().get( 0 ); + frag.delete(); + existing.fragments().add( frag ); + } + } + + if ( condition != null ) { + iter.setExpression( wireAndGetExpression( condition, this, ast ) ); + } + + for ( Expression updater : updaters ) { + iter.updaters().add( wireAndGetExpression( updater, this, ast ) ); + } + + if ( body != null ) { + iter.setBody( wireAndGetStatement( body.wrap(), this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/IfStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/IfStatementImpl.java new file mode 100644 index 00000000..cc2b9a4e --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/IfStatementImpl.java @@ -0,0 +1,68 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.IfStatement; +import org.jboss.forge.roaster.model.statements.Statement; + +public class IfStatementImpl, T extends Block>> + extends StatementImpl> + implements IfStatement { + + private org.eclipse.jdt.core.dom.IfStatement iff; + + private Expression condition; + private Statement thenBody; + private Statement elseBody; + + public IfStatementImpl() { } + + + @Override + public IfStatement setElse( Statement statement ) { + this.elseBody = statement; + return this; + } + + @Override + public IfStatement setCondition( Expression condition ) { + this.condition = condition; + return this; + } + + @Override + public IfStatement setThen( Statement statement ) { + this.thenBody = statement; + return this; + } + + @Override + public org.eclipse.jdt.core.dom.IfStatement getInternal() { + return iff; + } + + @Override + public void materialize( AST ast ) { + iff = ast.newIfStatement(); + + if ( condition != null ) { + iff.setExpression( wireAndGetExpression( condition, this, ast ) ); + } + if ( thenBody != null ) { + iff.setThenStatement( wireAndGetStatement( thenBody.wrap(), this, ast ) ); + } + if ( elseBody != null ) { + iff.setElseStatement( wireAndGetStatement( elseBody.wrap(), this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/InvokeStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/InvokeStatementImpl.java new file mode 100644 index 00000000..2a0ce7e6 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/InvokeStatementImpl.java @@ -0,0 +1,78 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.InvokeStatement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class InvokeStatementImpl, T extends Block>> + extends StatementImpl> + implements InvokeStatement { + + private ExpressionStatement statement; + private MethodInvocation invoke; + + private String method; + private Accessor target; + private List argumentList = Collections.EMPTY_LIST; + + public InvokeStatementImpl() { } + + @Override + public InvokeStatement setMethod( String method ) { + this.method = method; + return this; + } + + @Override + public InvokeStatement setTarget( Accessor target ) { + this.target = target; + return this; + } + + @Override + public InvokeStatement addArgument( Argument argument ) { + if ( argumentList.isEmpty() ) { + argumentList = new LinkedList(); + } + argumentList.add( argument ); + return this; + } + + @Override + public ExpressionStatement getInternal() { + return statement; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newMethodInvocation(); + statement = ast.newExpressionStatement( invoke ); + + invoke.setName( statement.getAST().newSimpleName( method ) ); + + if ( target != null ) { + invoke.setExpression( wireAndGetExpression( target, this, ast ) ); + } + + for ( Argument argument : argumentList ) { + invoke.arguments().add( wireAndGetExpression( argument, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/JdtStatementWrapper.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/JdtStatementWrapper.java new file mode 100644 index 00000000..9412189b --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/JdtStatementWrapper.java @@ -0,0 +1,17 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.Statement; +import org.jboss.forge.roaster.model.ASTNode; +import org.jboss.forge.roaster.model.source.JavaSource; + +public interface JdtStatementWrapper extends ASTNode { + + public void setOrigin( T origin ); +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ReturnStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ReturnStatementImpl.java new file mode 100644 index 00000000..2f3bf4d4 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ReturnStatementImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.ReturnStatement; + +public class ReturnStatementImpl, T extends Block>> + extends StatementImpl> + implements ReturnStatement { + + private org.eclipse.jdt.core.dom.ReturnStatement ret; + + private Expression result; + + public ReturnStatementImpl() { } + + public ReturnStatement setReturn( Expression expression ) { + result = expression; + return this; + } + + @Override + public org.eclipse.jdt.core.dom.ReturnStatement getInternal() { + return ret; + } + + @Override + public void materialize( AST ast ) { + ret = ast.newReturnStatement(); + + if ( result != null ) { + ret.setExpression( wireAndGetExpression( result, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementFactoryImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementFactoryImpl.java new file mode 100644 index 00000000..2d5a4894 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementFactoryImpl.java @@ -0,0 +1,145 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.AssertStatement; +import org.jboss.forge.roaster.model.statements.AssignStatement; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.BreakStatement; +import org.jboss.forge.roaster.model.statements.ContinueStatement; +import org.jboss.forge.roaster.model.statements.DeclareStatement; +import org.jboss.forge.roaster.model.statements.DoWhileStatement; +import org.jboss.forge.roaster.model.statements.ForEachStatement; +import org.jboss.forge.roaster.model.statements.ForStatement; +import org.jboss.forge.roaster.model.statements.IfStatement; +import org.jboss.forge.roaster.model.statements.InvokeStatement; +import org.jboss.forge.roaster.model.statements.ReturnStatement; +import org.jboss.forge.roaster.model.statements.SuperStatement; +import org.jboss.forge.roaster.model.statements.SwitchStatement; +import org.jboss.forge.roaster.model.statements.SynchStatement; +import org.jboss.forge.roaster.model.statements.ThisStatement; +import org.jboss.forge.roaster.model.statements.ThrowStatement; +import org.jboss.forge.roaster.model.statements.TryCatchStatement; +import org.jboss.forge.roaster.model.statements.WhileStatement; +import org.jboss.forge.roaster.spi.StatementFactory; + +public class StatementFactoryImpl, T extends BlockHolder> implements StatementFactory { + + + public StatementFactoryImpl() { } + + + public ReturnStatement> newReturn() { + ReturnStatementImpl> returnSt = new ReturnStatementImpl>(); + return returnSt; + } + + public AssignStatement> newAssign() { + AssignStatementImpl> assign = new AssignStatementImpl>(); + return assign; + } + + public DeclareStatement> newDeclare() { + DeclareStatementImpl> declare = new DeclareStatementImpl>(); + return declare; + } + + public InvokeStatement> newInvoke() { + InvokeStatementImpl> invoke = new InvokeStatementImpl>(); + return invoke; + } + + public IfStatement> newIf() { + IfStatementImpl> iff = new IfStatementImpl>(); + return iff; + } + + public WhileStatement> newWhile() { + WhileStatementImpl> loop = new WhileStatementImpl>(); + return loop; + } + + public DoWhileStatement> newDoWhile() { + DoWhileStatementImpl> loop = new DoWhileStatementImpl>(); + return loop; + } + + public ForStatement> newFor() { + ForStatementImpl> loop = new ForStatementImpl>(); + return loop; + } + + public ForEachStatement> newForEach() { + ForEachStatementImpl> loop = new ForEachStatementImpl>(); + return loop; + } + + @Override + public BlockStatement> newBlock() { + BlockStatementImpl> child = new BlockStatementImpl>(); + return child; + } + + @Override + public BreakStatement> newBreak() { + BreakStatement> stop = new BreakStatementImpl>(); + return stop; + } + + @Override + public ContinueStatement> newContinue() { + ContinueStatement> goon = new ContinueStatementImpl>(); + return goon; + } + + @Override + public ThrowStatement> newThrow() { + ThrowStatement> throwX = new ThrowStatementImpl>(); + return throwX; + } + + @Override + public TryCatchStatement> newTryCatch() { + TryCatchStatement> tryCatch = new TryCatchStatementImpl>(); + return tryCatch; + } + + @Override + public SynchStatement> newSynchronized() { + SynchStatement> synch = new SynchStatementImpl>(); + return synch; + } + + @Override + public ThisStatement> newThis() { + ThisStatement> self = new ThisStatementImpl>(); + return self; + } + + @Override + public SuperStatement> newSuper() { + SuperStatement> sup = new SuperStatementImpl>(); + return sup; + } + + @Override + public AssertStatement> newAssert() { + AssertStatement> sup = new AssertStatementImpl>(); + return sup; + } + + @Override + public SwitchStatement> newSwitch() { + SwitchStatement> sup = new SwitchStatementImpl>(); + return sup; + } + +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementImpl.java new file mode 100644 index 00000000..a75016e4 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/StatementImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.LabeledStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.impl.NodeImpl; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.BlockStatement; +import org.jboss.forge.roaster.model.statements.Statement; +import org.jboss.forge.roaster.model.statements.Statements; + +public abstract class StatementImpl, T extends Block>, J extends org.eclipse.jdt.core.dom.Statement,S extends Statement> + extends NodeImpl + implements Statement, + JdtStatementWrapper { + + private String label; + + protected StatementImpl() { + } + + public BlockStatement wrap() { + BlockStatement wrapper = Statements.newBlock(); + wrapper.addStatement( this ); + return wrapper; + } + + @Override + public S setLabel( String label ) { + this.label = label; + return (S) this; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public boolean hasLabel() { + return label != null && label.length() > 0; + } + + @Override + public org.eclipse.jdt.core.dom.Statement wireAndGetStatement( Statement statement, P parent, AST ast ) { + org.eclipse.jdt.core.dom.Statement stat = super.wireAndGetStatement( statement, parent, ast ); + if ( statement.hasLabel() ) { + LabeledStatement labeledStatement = ast.newLabeledStatement(); + labeledStatement.setBody( stat ); + labeledStatement.setLabel( ast.newSimpleName( statement.getLabel() ) ); + return labeledStatement; + } else { + return stat; + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SuperStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SuperStatementImpl.java new file mode 100644 index 00000000..7c61e466 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SuperStatementImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SuperConstructorInvocation; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.SuperStatement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class SuperStatementImpl, T extends Block>> + extends StatementImpl> + implements SuperStatement { + + private SuperConstructorInvocation invoke; + + private List argumentList = Collections.EMPTY_LIST; + + public SuperStatementImpl() { } + + @Override + public SuperStatement addArgument( Argument argument ) { + if ( argumentList.isEmpty() ) { + argumentList = new LinkedList(); + } + argumentList.add( argument ); + return this; + } + + @Override + public SuperConstructorInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newSuperConstructorInvocation(); + + for ( Argument argument : argumentList ) { + invoke.arguments().add( wireAndGetExpression( argument, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SwitchStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SwitchStatementImpl.java new file mode 100644 index 00000000..466e5023 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SwitchStatementImpl.java @@ -0,0 +1,104 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SwitchCase; +import org.eclipse.jdt.core.dom.SwitchStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.Statement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class SwitchStatementImpl, T extends Block>> + extends StatementImpl> + implements org.jboss.forge.roaster.model.statements.SwitchStatement { + + private SwitchStatement opts; + + private Expression> expression; + private List> statements = Collections.EMPTY_LIST; + + public SwitchStatementImpl() { } + + + @Override + public SwitchStatement getInternal() { + return opts; + } + + @Override + public void materialize( AST ast ) { + opts = ast.newSwitchStatement(); + opts.setExpression( wireAndGetExpression( expression, this, ast ) ); + + for ( Statement stat : statements ) { + if ( SwitchMockStatement.class.isInstance( stat ) ) { + SwitchMockStatement mock = (SwitchMockStatement) stat; + SwitchCase opt = ast.newSwitchCase(); + if ( mock.getOption() == null ) { + opt.setExpression( null ); + } else { + opt.setExpression( wireAndGetExpression( mock.getOption(), this, ast ) ); + } + opts.statements().add( opt ); + } else { + opts.statements().add( wireAndGetStatement( stat, this, ast ) ); + } + } + } + + @Override + public org.jboss.forge.roaster.model.statements.SwitchStatement addCase( Expression> option ) { + if ( statements.isEmpty() ) { + statements = new LinkedList>( ); + } + statements.add( new SwitchMockStatement( option ) ); + return this; + } + + @Override + public org.jboss.forge.roaster.model.statements.SwitchStatement addDefault() { + statements.add( new SwitchMockStatement( null ) ); + return this; + } + + @Override + public org.jboss.forge.roaster.model.statements.SwitchStatement addStatement( Statement arg ) { + if ( statements.isEmpty() ) { + statements = new LinkedList>( ); + } + statements.add( arg ); + return this; + } + + @Override + public org.jboss.forge.roaster.model.statements.SwitchStatement setSwitchOn( Expression> expr ) { + this.expression = expr; + return this; + } + + private class SwitchMockStatement extends ExpressionStatementImpl { + private Expression> option; + + public SwitchMockStatement( Expression> option ) { + this.option = option; + } + + public Expression> getOption() { + return option; + } + } +} + + diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SynchStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SynchStatementImpl.java new file mode 100644 index 00000000..e0d0a363 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/SynchStatementImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.SynchronizedStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.Statement; +import org.jboss.forge.roaster.model.statements.SynchStatement; + +public class SynchStatementImpl, T extends Block>> + extends StatementImpl> + implements SynchStatement { + + private SynchronizedStatement synch; + + private Expression expr; + private Statement body; + + public SynchStatementImpl() { } + + @Override + public SynchronizedStatement getInternal() { + return synch; + } + + @Override + public void materialize( AST ast ) { + synch = ast.newSynchronizedStatement(); + + if ( expr != null ) { + synch.setExpression( wireAndGetExpression( expr, this, ast ) ); + } + if ( body != null ) { + synch.setBody( (org.eclipse.jdt.core.dom.Block) wireAndGetStatement( body.wrap(), this, ast ) ); + } + } + + @Override + public SynchStatement setSynchOn( Expression expr ) { + this.expr = expr; + return this; + } + + @Override + public SynchStatement setBody( Statement block ) { + this.body = block; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThisStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThisStatementImpl.java new file mode 100644 index 00000000..ae6b47eb --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThisStatementImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ConstructorInvocation; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.ThisStatement; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class ThisStatementImpl, T extends Block>> + extends StatementImpl> + implements ThisStatement { + + private ConstructorInvocation invoke; + + private List argumentList = Collections.EMPTY_LIST; + + public ThisStatementImpl() { } + + @Override + public ThisStatement addArgument( Argument argument ) { + if ( argumentList.isEmpty() ) { + argumentList = new LinkedList(); + } + argumentList.add( argument ); + return this; + } + + @Override + public ConstructorInvocation getInternal() { + return invoke; + } + + @Override + public void materialize( AST ast ) { + invoke = ast.newConstructorInvocation(); + + for ( Argument argument : argumentList ) { + invoke.arguments().add( wireAndGetExpression( argument, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThrowStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThrowStatementImpl.java new file mode 100644 index 00000000..5393d2f7 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/ThrowStatementImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ThrowStatement; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ThrowStatementImpl, T extends Block>> + extends StatementImpl> + implements org.jboss.forge.roaster.model.statements.ThrowStatement { + + private Expression> expression; + private ThrowStatement throwStatement; + + public ThrowStatementImpl() {} + + @Override + public ThrowStatement getInternal() { + return throwStatement; + } + + public void materialize( AST ast ) { + throwStatement = ast.newThrowStatement(); + if ( expression != null ) { + throwStatement.setExpression( wireAndGetExpression( expression, this, getAst() ) ); + } + } + + @Override + public org.jboss.forge.roaster.model.statements.ThrowStatement setThrowable( Expression> expr ) { + this.expression = expr; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/TryCatchStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/TryCatchStatementImpl.java new file mode 100644 index 00000000..3fc7f941 --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/TryCatchStatementImpl.java @@ -0,0 +1,93 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.CatchClause; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.TryStatement; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.impl.JDTHelper; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.Statement; +import org.jboss.forge.roaster.model.statements.TryCatchStatement; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +public class TryCatchStatementImpl, T extends Block>> + extends StatementImpl> + implements TryCatchStatement { + + private TryStatement tryCatch; + + private Map catches = Collections.EMPTY_MAP; + private Statement body; + private Statement fine; + + public TryCatchStatementImpl() { } + + + @Override + public TryStatement getInternal() { + return tryCatch; + } + + @Override + public void materialize( AST ast ) { + tryCatch = ast.newTryStatement(); + + for ( DeclareExpression declare : catches.keySet() ) { + CatchClause clause = ast.newCatchClause(); + clause.setException( varToSvd( (VariableDeclarationExpression) wireAndGetExpression( declare, this, ast ), ast ) ); + clause.setBody( (org.eclipse.jdt.core.dom.Block) wireAndGetStatement( catches.get( declare ).wrap(), this, ast ) ); + tryCatch.catchClauses().add( clause ); + } + + if ( fine != null ) { + tryCatch.setFinally( (org.eclipse.jdt.core.dom.Block) wireAndGetStatement( fine.wrap(), this, ast ) ); + } + if ( body != null ) { + tryCatch.setBody( (org.eclipse.jdt.core.dom.Block) wireAndGetStatement( body.wrap(), this, ast ) ); + } + } + + private SingleVariableDeclaration varToSvd( VariableDeclarationExpression var, AST ast ) { + SingleVariableDeclaration svd = ast.newSingleVariableDeclaration(); + VariableDeclarationFragment frag = (VariableDeclarationFragment) var.fragments().get( 0 ); + svd.setName( ast.newSimpleName( frag.getName().getIdentifier() ) ); + svd.setType( JDTHelper.getType( var.getType().toString(), ast ) ); + return svd; + } + + @Override + public TryCatchStatement addCatch( DeclareExpression declaration, Statement block ) { + if ( catches.isEmpty() ) { + catches = new LinkedHashMap(); + } + catches.put( declaration, block ); + return this; + } + + @Override + public TryCatchStatement setFinally( Statement block ) { + this.fine = block; + return this; + } + + @Override + public TryCatchStatement setBody( Statement block ) { + this.body = block; + return this; + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/WhileStatementImpl.java b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/WhileStatementImpl.java new file mode 100644 index 00000000..36ac946f --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/model/impl/statements/WhileStatementImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.model.impl.statements; + +import org.eclipse.jdt.core.dom.AST; +import org.jboss.forge.roaster.model.Block; +import org.jboss.forge.roaster.model.expressions.Expression; +import org.jboss.forge.roaster.model.source.BlockHolder; +import org.jboss.forge.roaster.model.source.JavaSource; +import org.jboss.forge.roaster.model.statements.Statement; +import org.jboss.forge.roaster.model.statements.WhileStatement; + +public class WhileStatementImpl, T extends Block>> + extends StatementImpl> + implements WhileStatement { + + private org.eclipse.jdt.core.dom.WhileStatement rep; + + private Statement body; + private Expression condition; + + public WhileStatementImpl() { } + + @Override + public WhileStatement setBody( Statement statement ) { + this.body = statement; + return this; + } + + @Override + public WhileStatement setCondition( Expression expr ) { + this.condition = expr; + return this; + } + + @Override + public org.eclipse.jdt.core.dom.WhileStatement getInternal() { + return rep; + } + + @Override + public void materialize( AST ast ) { + rep = ast.newWhileStatement(); + + if ( body != null ) { + rep.setBody( wireAndGetStatement( body.wrap(), this, ast ) ); + } + if ( condition != null ) { + rep.setExpression( wireAndGetExpression( condition, this, ast ) ); + } + } +} diff --git a/impl/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactoryImpl.java b/impl/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactoryImpl.java new file mode 100644 index 00000000..8d900e6c --- /dev/null +++ b/impl/src/main/java/org/jboss/forge/roaster/spi/ExpressionFactoryImpl.java @@ -0,0 +1,290 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.jboss.forge.roaster.spi; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.Expression; +import org.jboss.forge.roaster.model.expressions.AccessBuilder; +import org.jboss.forge.roaster.model.expressions.Accessor; +import org.jboss.forge.roaster.model.expressions.Argument; +import org.jboss.forge.roaster.model.expressions.ArrayConstructorExpression; +import org.jboss.forge.roaster.model.expressions.ArrayIndexer; +import org.jboss.forge.roaster.model.expressions.ArrayInit; +import org.jboss.forge.roaster.model.expressions.AssignExpression; +import org.jboss.forge.roaster.model.expressions.Assignment; +import org.jboss.forge.roaster.model.expressions.CastExpression; +import org.jboss.forge.roaster.model.expressions.ClassLiteral; +import org.jboss.forge.roaster.model.expressions.ConstructorExpression; +import org.jboss.forge.roaster.model.expressions.DeclareExpression; +import org.jboss.forge.roaster.model.expressions.ExpressionSource; +import org.jboss.forge.roaster.model.expressions.Field; +import org.jboss.forge.roaster.model.expressions.Getter; +import org.jboss.forge.roaster.model.expressions.InstanceofExpression; +import org.jboss.forge.roaster.model.expressions.Literal; +import org.jboss.forge.roaster.model.expressions.MethodExpression; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.expressions.OperatorExpression; +import org.jboss.forge.roaster.model.expressions.ParenExpression; +import org.jboss.forge.roaster.model.expressions.PrefixOp; +import org.jboss.forge.roaster.model.expressions.Setter; +import org.jboss.forge.roaster.model.expressions.Super; +import org.jboss.forge.roaster.model.expressions.TernaryExpression; +import org.jboss.forge.roaster.model.expressions.UnaryExpression; +import org.jboss.forge.roaster.model.expressions.Variable; +import org.jboss.forge.roaster.model.impl.NodeImpl; +import org.jboss.forge.roaster.model.impl.expressions.ArrayAccessImpl; +import org.jboss.forge.roaster.model.impl.expressions.ArrayImpl; +import org.jboss.forge.roaster.model.impl.expressions.ArrayInitImpl; +import org.jboss.forge.roaster.model.impl.expressions.AssignImpl; +import org.jboss.forge.roaster.model.impl.expressions.BooleanLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.CastImpl; +import org.jboss.forge.roaster.model.impl.expressions.CharacterLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.ClassLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.ConstructorImpl; +import org.jboss.forge.roaster.model.impl.expressions.DeclareExpressionImpl; +import org.jboss.forge.roaster.model.impl.expressions.FieldImpl; +import org.jboss.forge.roaster.model.impl.expressions.GetterImpl; +import org.jboss.forge.roaster.model.impl.expressions.InstanceofImpl; +import org.jboss.forge.roaster.model.impl.expressions.MethodInvokeImpl; +import org.jboss.forge.roaster.model.impl.expressions.NotImpl; +import org.jboss.forge.roaster.model.impl.expressions.NullLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.NumberLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.OperatorImpl; +import org.jboss.forge.roaster.model.impl.expressions.ParenImpl; +import org.jboss.forge.roaster.model.impl.expressions.SelfArgumentImpl; +import org.jboss.forge.roaster.model.impl.expressions.SetterImpl; +import org.jboss.forge.roaster.model.impl.expressions.StaticClassAccessorImpl; +import org.jboss.forge.roaster.model.impl.expressions.StringLiteralImpl; +import org.jboss.forge.roaster.model.impl.expressions.SuperImpl; +import org.jboss.forge.roaster.model.impl.expressions.TernaryImpl; +import org.jboss.forge.roaster.model.impl.expressions.UnaryImpl; +import org.jboss.forge.roaster.model.impl.expressions.VarArgumentImpl; +import org.jboss.forge.roaster.model.source.JavaSource; + +public class ExpressionFactoryImpl, T extends ExpressionSource, J extends Expression> + extends NodeImpl + implements ExpressionFactory { + + + public ExpressionFactoryImpl() { } + + @Override + public J getInternal() { + throw new UnsupportedOperationException( "Method should not be called directly on this class" ); + } + + @Override + public void materialize( AST ast ) { + throw new UnsupportedOperationException( "Method should not be called directly on this class" ); + } + + @Override + public Literal literal( String val ) { + return new StringLiteralImpl( val ); + } + + @Override + public Literal literal( Number val ) { + return new NumberLiteralImpl( val ); + } + + @Override + public Literal literal( Character val ) { + return new CharacterLiteralImpl( val ); + } + + @Override + public ClassLiteral classLiteral( Class klass ) { + return classLiteral( klass.getName() ); + } + + @Override + public ClassLiteral classLiteral( String klass ) { + return new ClassLiteralImpl( klass ); + } + + @Override + public Literal literal( Boolean val ) { + return new BooleanLiteralImpl( val ); + } + + public Literal zeroLiteral( Class klass ) { + return zeroLiteral( klass.getName() ); + } + + public Literal zeroLiteral( String klass ) { + if ( boolean.class.getName().equals( klass ) ) { + return literal( false ); + } else if ( byte.class.getName().equals( klass ) ) { + return literal( 0 ); + } else if ( char.class.getName().equals( klass ) ) { + return literal( 0 ); + } else if ( double.class.getName().equals( klass ) ) { + return literal( 0.0 ); + } else if ( float.class.getName().equals( klass ) ) { + return literal( 0.0f ); + } else if ( int.class.getName().equals( klass ) ) { + return literal( 0 ); + } else if ( long.class.getName().equals( klass ) ) { + return literal( 0L ); + } else if ( short.class.getName().equals( klass ) ) { + return literal( 0 ); + } else { + return nullLiteral(); + } + } + + @Override + public OperatorExpression operator( Op op ) { + return new OperatorImpl( op ); + } + + @Override + public UnaryExpression operator( PrefixOp op, org.jboss.forge.roaster.model.expressions.Argument> arg ) { + return new UnaryImpl( op, arg ); + } + + @Override + public Literal nullLiteral() { + return new NullLiteralImpl(); + } + + @Override + public UnaryExpression not( Argument> arg ) { + return new NotImpl( arg ); + } + + @Override + public Field field( String fieldName ) { + return new FieldImpl( fieldName ); + } + + @Override + public Getter getter( String fieldName, String type ) { + return new GetterImpl( fieldName, type ); + } + + @Override + public Getter getter( String fieldName, Class type ) { + return getter( fieldName, type.getName() ); + } + + @Override + public Setter setter( String fldName, String type, org.jboss.forge.roaster.model.expressions.Expression> value ) { + return new SetterImpl( fldName, type, value ); + } + + @Override + public Setter setter( String fldName, Class type, org.jboss.forge.roaster.model.expressions.Expression> value ) { + return setter( fldName, type.getName(), value ); + } + + @Override + public DeclareExpression declare( String klass, String name ) { + return new DeclareExpressionImpl( klass, name ); + } + + @Override + public DeclareExpression declare( Class klass, String name ) { + return declare( klass.getName(), name ); + } + + @Override + public MethodExpression invoke( String method ) { + return new MethodInvokeImpl( method ); + } + + @Override + public CastExpression cast( String klass, org.jboss.forge.roaster.model.expressions.Expression> arg ) { + CastExpression expr = new CastImpl( klass, arg ); + return expr; + } + + @Override + public CastExpression cast( Class klass, org.jboss.forge.roaster.model.expressions.Expression> arg ) { + return cast( klass.getName(), arg ); + } + + @Override + public ConstructorExpression newInstance( String klass ) { + return new ConstructorImpl( klass ); + } + + @Override + public ConstructorExpression newInstance( Class klass ) { + return newInstance( klass.getName() ); + } + + @Override + public ArrayConstructorExpression newArray( String klass ) { + return new ArrayImpl( klass ); + } + + @Override + public ArrayConstructorExpression newArray( Class klass ) { + return newArray( klass.getName() ); + } + + @Override + public Variable var( String varName ) { + return new VarArgumentImpl( varName ); + } + + @Override + public AssignExpression assign( Assignment operator ) { + return new AssignImpl( operator ); + } + + @Override + public Accessor thisLiteral() { + return new SelfArgumentImpl(); + } + + public ParenExpression paren( org.jboss.forge.roaster.model.expressions.Expression> child) { + return new ParenImpl( child ); + } + + @Override + public TernaryExpression ternary() { + return new TernaryImpl(); + } + + public Accessor classStatic( String klass ) { + return new StaticClassAccessorImpl( klass ); + } + + public Accessor classStatic( Class klass ) { + return classStatic( klass.getName() ); + } + + @Override + public InstanceofExpression instanceOf( String klass, org.jboss.forge.roaster.model.expressions.Expression> arg ) { + InstanceofExpression expr = new InstanceofImpl( klass, arg ); + return expr; + } + + @Override + public InstanceofExpression instanceOf( Class klass, org.jboss.forge.roaster.model.expressions.Expression> arg ) { + return instanceOf( klass.getName(), arg ); + } + + @Override + public Super sup() { + return new SuperImpl(); + } + + @Override + public ArrayInit> vec() { + return new ArrayInitImpl>(); + } + + @Override + public AccessBuilder itemAt( org.jboss.forge.roaster.model.expressions.Expression> index ) { + return new ArrayAccessImpl( index ); + } +} diff --git a/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.ExpressionFactory b/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.ExpressionFactory new file mode 100644 index 00000000..b21e171f --- /dev/null +++ b/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.ExpressionFactory @@ -0,0 +1 @@ +org.jboss.forge.roaster.spi.ExpressionFactoryImpl \ No newline at end of file diff --git a/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.StatementFactory b/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.StatementFactory new file mode 100644 index 00000000..bd4c0503 --- /dev/null +++ b/impl/src/main/resources/META-INF/services/org.jboss.forge.roaster.spi.StatementFactory @@ -0,0 +1 @@ +org.jboss.forge.roaster.model.impl.statements.StatementFactoryImpl \ No newline at end of file diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ConstructorStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ConstructorStatementsTest.java new file mode 100644 index 00000000..6d72089c --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ConstructorStatementsTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.jboss.forge.roaster.model.expressions.Expressions.field; +import static org.jboss.forge.roaster.model.expressions.Expressions.literal; +import static org.jboss.forge.roaster.model.expressions.Expressions.newInstance; +import static org.jboss.forge.roaster.model.expressions.Expressions.operator; +import static org.jboss.forge.roaster.model.expressions.Expressions.var; +import static org.jboss.forge.roaster.model.statements.Statements.newAssign; +import static org.jboss.forge.roaster.model.statements.Statements.newDeclare; +import static org.jboss.forge.roaster.model.statements.Statements.newSuper; +import static org.jboss.forge.roaster.model.statements.Statements.newThis; +import static org.junit.Assert.assertEquals; + + +public class ConstructorStatementsTest +{ + + @Test + public void testEmptyConstructor() throws Exception + { + String target = "this(x);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public Foo()" ); + + method.setBody( newThis().addArgument( var( "x" ) ) ); + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSuperConstructor() throws Exception + { + String target = "super(x);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public Foo()" ); + + method.setBody( newSuper().addArgument( var( "x" ) ) ); + assertEquals( target, method.getBody().trim() ); + } + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ControlFlowStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ControlFlowStatementsTest.java new file mode 100644 index 00000000..b8863765 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ControlFlowStatementsTest.java @@ -0,0 +1,194 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.jboss.forge.roaster.model.expressions.Expressions.declare; +import static org.jboss.forge.roaster.model.expressions.Expressions.literal; +import static org.jboss.forge.roaster.model.expressions.Expressions.newInstance; +import static org.jboss.forge.roaster.model.expressions.Expressions.operator; +import static org.jboss.forge.roaster.model.expressions.Expressions.thisLiteral; +import static org.jboss.forge.roaster.model.expressions.Expressions.var; +import static org.jboss.forge.roaster.model.statements.Statements.newAssert; +import static org.jboss.forge.roaster.model.statements.Statements.newAssign; +import static org.jboss.forge.roaster.model.statements.Statements.newBlock; +import static org.jboss.forge.roaster.model.statements.Statements.newBreak; +import static org.jboss.forge.roaster.model.statements.Statements.newContinue; +import static org.jboss.forge.roaster.model.statements.Statements.newDeclare; +import static org.jboss.forge.roaster.model.statements.Statements.newDoWhile; +import static org.jboss.forge.roaster.model.statements.Statements.newIf; +import static org.jboss.forge.roaster.model.statements.Statements.newInvoke; +import static org.jboss.forge.roaster.model.statements.Statements.newReturn; +import static org.jboss.forge.roaster.model.statements.Statements.newSwitch; +import static org.jboss.forge.roaster.model.statements.Statements.newSynchronized; +import static org.jboss.forge.roaster.model.statements.Statements.newThrow; +import static org.jboss.forge.roaster.model.statements.Statements.newTryCatch; +import static org.jboss.forge.roaster.model.statements.Statements.newWhile; +import static org.junit.Assert.assertEquals; + + +public class ControlFlowStatementsTest +{ + @Test + public void testSimpleLabeledStatement() throws Exception + { + String target = "Out: return x;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn().setLabel( "Out" ).setReturn( var( "x" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testBreak() throws Exception + { + String target = "if (true) {\n break;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newBlock() + .addStatement( newIf().setCondition( literal( true ) ).setThen( newBreak() ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testContinue() throws Exception + { + String target = "while (true) {\n continue;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newBlock() + .addStatement( newWhile().setCondition( literal( true ) ).setBody( newContinue() ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testBreakWithLabel() throws Exception + { + String target = "while (true) {\n break exit;\n}\n exit: return x;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newBlock() + .addStatement( newWhile().setCondition( literal( true ) ).setBody( + newBreak().setTarget( "exit" ) ) ) + .addStatement( newReturn().setReturn( var( "x" ) ).setLabel( "exit" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testContinueWithLabel() throws Exception + { + String target = "while (true) {\n test: x=x + 1;\n continue test;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newBlock() + .addStatement( newWhile().setCondition( literal( true ) ).setBody( + newBlock() + .addStatement( + newAssign().setLeft( var( "x" ) ).setRight( operator( Op.PLUS ).addArgument( var( "x" ) ).addArgument( literal( 1 ) ) ) + .setLabel( "test" ) ) + .addStatement( newContinue().setTarget( "test" ) ) + ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + + @Test + public void testThrowable() throws Exception + { + String target = "throw new java.lang.UnsupportedOperationException(\"sorry\");"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newThrow().setThrowable( newInstance( UnsupportedOperationException.class ).addArgument( literal( "sorry" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testTryCatch() throws Exception + { + String target = "try {\n" + + " x.foo();\n" + + "}\n catch (java.lang.NullPointerException npe) {\n" + + " npe.printStackTrace();\n" + + "}\ncatch (java.lang.IllegalStateException ise) {\n" + + " ise.printStackTrace();\n" + + "}\n finally {\n" + + " return;\n" + + "}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newTryCatch() + .setBody( newInvoke().setMethod( "foo" ).setTarget( var( "x" ) ) ) + .addCatch( declare( NullPointerException.class, "npe" ), newInvoke().setMethod( "printStackTrace" ).setTarget( var( "npe" ) ) ) + .addCatch( declare( IllegalStateException.class, "ise" ), newInvoke().setMethod( "printStackTrace" ).setTarget( var( "ise" ) ) ) + .setFinally( newReturn() ) + ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSynchronized() throws Exception + { + String target = "synchronized (this) {\n x++;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newSynchronized().setSynchOn( thisLiteral() ).setBody( newBlock().addStatement( var( "x" ).inc() ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSwitchCase() throws Exception + { + String target = "switch (x) {\n" + + "case 0:\n" + + " return true;\n" + + "case 1:\n" + + "break;\n" + + "case 2:\n" + + "default :\n" + + "return false;\n" + + "}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newSwitch().setSwitchOn( var( "x" ) ) + .addCase( literal( 0 ) ).addStatement( newReturn().setReturn( literal( true ) ) ) + .addCase( literal( 1 ) ).addStatement( newBreak() ) + .addCase( literal( 2 ) ) + .addDefault() + .addStatement( newReturn().setReturn( literal( false ) ) ) + ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testAssertion() throws Exception + { + String target = "assert x > 0 : \"x GT 0\";"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newAssert() + .setAssertion( operator( Op.GREATER ).addArgument( var( "x" ) ).addArgument( literal( 0 ) ) ) + .setMessage( literal( "x GT 0" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/DeclareStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/DeclareStatementsTest.java new file mode 100644 index 00000000..a2032d61 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/DeclareStatementsTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + + +public class DeclareStatementsTest +{ + + @Test + public void testDeclare() throws Exception + { + String target = "java.lang.Integer y=new java.lang.Integer();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo( String x )" ); + + method.setBody( newDeclare().setVariable( Integer.class, "y" ).setInitExpression( newInstance( Integer.class ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testDeclarePrimitive() throws Exception + { + String target = "int y=0;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo( String x )" ); + + method.setBody( newDeclare().setVariable( int.class, "y" ).setDefaultInitExpression() ); + + assertEquals( target, method.getBody().trim() ); + } + + + @Test + public void testDeclareAndInit() throws Exception + { + String target = "java.lang.Integer y=0;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo( String x )" ); + + method.setBody( newDeclare().setVariable( Integer.class, "y" ).setInitExpression( literal( 0 ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSimpleAssignment() throws Exception + { + String target = "this.name=x;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo( String x )" ); + + method.setBody( newAssign().setLeft( field( "name" ) ).setRight( var( "x" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testAssignmentExpr() throws Exception + { + String target = "this.name=this.name + \" Doe\";"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo( String x )" ); + + method.setBody( newAssign() + .setLeft( field( "name" ) ) + .setRight( operator( Op.PLUS ).addArgument( field( "name" ) ).addArgument( literal( " Doe" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ForStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ForStatementsTest.java new file mode 100644 index 00000000..aea72181 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ForStatementsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Assignment; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + +public class ForStatementsTest +{ + + @Test + public void testSimpleForWithPrint() throws Exception + { + + String target = "for (int j=0, k=0; j < 100; j++, k=k + 2) {\n java.lang.System.out.println(j);\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newFor() + .addDeclaration( declare( int.class, "j" ).init( literal( 0 ) ) ) + .addDeclaration( declare( int.class, "k" ).init( literal( 0 ) ) ) + .setCondition( operator( Op.LESS ) + .addArgument( var( "j" ) ) + .addArgument( literal( 100 ) ) ) + .addUpdate( var( "j" ).inc() ) + .addUpdate( assign( Assignment.ASSIGN ) + .setLeft( var( "k" ) ) + .setRight( operator( Op.PLUS ) + .addArgument( var( "k" ) ) + .addArgument( literal( 2 ) ) ) ) + .setBody( newInvoke() + .setMethod( "println" ) + .setTarget( classStatic( System.class ).field( "out" ) ) + .addArgument( var( "j" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSimpleForEachWithPrint() throws Exception + { + + String target = "for (java.lang.String name : p.getNames()) {\n java.lang.System.out.println(name);\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newForEach() + .setIterator( String.class, "name" ) + .setSource( var( "p" ).getter( "names", String.class ) ) + .setBody( newInvoke() + .setTarget( classStatic( System.class ).field( "out" ) ) + .setMethod( "println" ) + .addArgument( var( "name" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/IfStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/IfStatementsTest.java new file mode 100644 index 00000000..a6cd9a97 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/IfStatementsTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + +public class IfStatementsTest +{ + @Test + public void testSimpleIfWithCondition() throws Exception + { + String target = "if (x != null) {\n x=null;\n}\n else {\n x=y;\n x=x + 1;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newIf() + .setCondition( operator( Op.NOT_EQUALS ).addArgument( var( "x" ) ).addArgument( nullLiteral() ) ) + .setThen( newAssign().setLeft( var( "x" ) ).setRight( nullLiteral() ) ) + .setElse( newBlock() + .addStatement( newAssign().setLeft( var( "x" ) ).setRight( var( "y" ) ) ) + .addStatement( newAssign().setLeft( var( "x" ) ).setRight( + operator( Op.PLUS ) + .addArgument( var( "x" ) ) + .addArgument( literal( 1 ) ) ) ) ) ); + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testIfWithDotAccessor() throws Exception + { + String target = "if (this.x != y.z) {\n return false;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newIf() + .setCondition( operator( Op.NOT_EQUALS ) + .addArgument( thisLiteral().field( "x" ) ) + .addArgument( var( "y" ).field( "z" ) ) ) + .setThen( newReturn().setReturn( literal( false ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testIfWithNegation() throws Exception + { + String target = "if (!x) {\n return false;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newIf() + .setCondition( not( var( "x" ) ) ) + .setThen( newReturn().setReturn( literal( false ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testIfWithDoubleNegation() throws Exception + { + String target = "if (!!x) {\n return false;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newIf() + .setCondition( not( not( var( "x" ) ) ) ) + .setThen( newReturn().setReturn( literal( false ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testIfWithInstanceof() throws Exception + { + String target = "if (x instanceof Foo) {\n return false;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newIf() + .setCondition( instanceOf( "Foo", var( "x" ) ) ) + .setThen( newReturn().setReturn( literal( false ) ) ) ); + assertEquals( target, method.getBody().trim() ); + } + + + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/InvokeStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/InvokeStatementsTest.java new file mode 100644 index 00000000..f0bfa371 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/InvokeStatementsTest.java @@ -0,0 +1,122 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + + +public class InvokeStatementsTest +{ + + @Test + public void testInvoke() throws Exception + { + String target = "java.lang.Math.random();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setMethod( "random" ).setTarget( classStatic( Math.class ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeWithArg() throws Exception + { + String target = "java.lang.Math.round(2.4);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setTarget( classStatic( Math.class ) ).setMethod( "round" ).addArgument( literal( 2.4f ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeWithArgs() throws Exception + { + String target = "java.lang.Math.min(3,4);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().addArgument( literal( 3 ) ).addArgument( literal( 4 ) ).setTarget( classStatic( Math.class ) ).setMethod( "min" ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeWithArgsRevOrder() throws Exception + { + String target = "java.lang.Math.min(3,4);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().addArgument( literal( 3 ) ).addArgument( literal( 4 ) ).setTarget( classStatic( Math.class ) ).setMethod( "min" ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testNestedInvoke() throws Exception + { + String target = "java.lang.Math.min(java.lang.Math.max(java.lang.Math.round(3,4),6),4);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setTarget( classStatic( Math.class ) ).setMethod( "min" ) + .addArgument( invoke( "max" ).setTarget( classStatic( Math.class ) ) + .addArgument( invoke( "round" ).setTarget( classStatic( Math.class ) ) + .addArgument( literal( 3 ) ) + .addArgument( literal( 4 ) ) ) + .addArgument( literal( 6 ) ) ) + .addArgument( literal( 4 ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeWithArgz() throws Exception + { + String target = "java.lang.Math.min(2 + 3,4 * 5);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setTarget( classStatic( Math.class ) ).setMethod( "min" ) + .addArgument( operator( Op.PLUS ).addArgument( literal( 2 ) ).addArgument( literal( 3 ) ) ) + .addArgument( operator( Op.TIMES ).addArgument( literal( 4 ) ).addArgument( literal( 5 ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeOnThis() throws Exception + { + String target = "this.toString();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setTarget( thisLiteral() ).setMethod( "toString" ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testInvokeOnLongChain() throws Exception + { + String target = "this.getName().foo().bar().baz.toString();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void foo()" ); + + method.setBody( newInvoke().setMethod( "toString" ) + .setTarget( + thisLiteral().getter( "name", "String" ).invoke( "foo" ).dot().invoke( "bar" ).dot().field( "baz" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ReturnStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ReturnStatementsTest.java new file mode 100644 index 00000000..f66fe766 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/ReturnStatementsTest.java @@ -0,0 +1,250 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.expressions.PrefixOp; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import java.util.UUID; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + +public class ReturnStatementsTest +{ + @Test + public void testReturn() throws Exception + { + String target = "return;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn() ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnArg() throws Exception + { + String target = "return x;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String echo( String x )" ); + + method.setBody( newReturn().setReturn( var( "x" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnExpr() throws Exception + { + String target = "return x + 5;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String echo( String x )" ); + + method.setBody( newReturn().setReturn( operator( Op.PLUS ).addArgument( var( "x" ) ).addArgument( literal( 5 ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnInvoke() throws Exception + { + String target = "return java.util.UUID.randomUUID();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( invoke( "randomUUID" ).setTarget( classStatic( UUID.class ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnInvokeWithArgs() throws Exception + { + String target = "return java.util.UUID.fromString(\"xyz\");"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( invoke( "fromString" ) + .setTarget( classStatic( UUID.class ) ) + .addArgument( literal( "xyz" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnTernary() throws Exception + { + String target = "return x > 0 ? 4 : 5;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public int foo( int x )" ); + + method.setBody( newReturn().setReturn( ternary() + .setCondition( operator( Op.GREATER ).addArgument( var( "x" ) ).addArgument( literal( 0 ) ) ) + .setIfExpression( literal( 4 ) ) + .setElseExpression( literal( 5 ) ) ) ); + ; + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnTernaryWithParen() throws Exception + { + String target = "return 1 + (x > 3 ? 4 : 5) + 2;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public int foo( in x )" ); + + method.setBody( newReturn().setReturn( + operator( Op.PLUS ) + .addArgument( literal( 1 ) ) + .addArgument( paren( ternary() + .setCondition( operator( Op.GREATER ).addArgument( var( "x" ) ).addArgument( literal( 3 ) ) ) + .setIfExpression( literal( 4 ) ) + .setElseExpression( literal( 5 ) ) ) ) + .addArgument( literal( 2 ) ) ) ); + ; + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnCast() throws Exception + { + String target = "return (long)(x);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public long foo( int x )" ); + + method.setBody( newReturn().setReturn( cast( long.class, var( "x" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnNull() throws Exception + { + String target = "return null;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( nullLiteral() ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnChain() throws Exception + { + String target = "return getName().bar();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( getter( "name", "String" ).invoke( "bar" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnChainWithField() throws Exception + { + String target = "return getName().baz;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( getter( "name", "String" ).field( "baz" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnChainWithFields() throws Exception + { + String target = "return this.foo.bar.baz;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( field( "foo" ).field( "bar" ).field( "baz" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnChainWithFieldsAndMethods() throws Exception + { + String target = "return this.foo.getBar().baz.doSomething(this.x.y).getRes();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( field( "foo" ).getter( "bar", String.class.getName() ).field( "baz" ) + .invoke( "doSomething" ).addArgument( field( "x" ).field( "y" ) ).dot().invoke( "getRes" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnUnary() throws Exception + { + String target = "return 3 * -2;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( operator( Op.TIMES ).addArgument( literal( 3 ) ).addArgument( operator( PrefixOp.MINUS, literal( 2 ) ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnUnaryParen() throws Exception + { + String target = "return 3 * -(2 + 1);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public String foo()" ); + + method.setBody( newReturn().setReturn( operator( Op.TIMES ) + .addArgument( literal( 3 ) ) + .addArgument( operator( PrefixOp.MINUS, + paren( operator( Op.PLUS ) + .addArgument( literal( 2 ) ).addArgument( literal( 1 ) ) ) ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnArray() throws Exception + { + String target = "return new int[2][3];"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public int[][] foo()" ); + + method.setBody( newReturn().setReturn( newArray( int.class ).addDimension( literal( 2 ) ).addDimension( literal( 3 ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnArrayWithImpliedInit() throws Exception + { + String target = "return new int[][]{{1,2},{3,4}};"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public int[][] foo()" ); + + method.setBody( newReturn().setReturn( newArray( int.class ).init( + vec().addElement( + vec().addElement( literal( 1 ) ).addElement( literal( 2 ) ) ) + .addElement( + vec().addElement( literal( 3 ) ).addElement( literal( 4 ) ) + ) + ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testReturnArrayAccess() throws Exception + { + String target = "return x[4][2].getY();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public int[][] foo()" ); + + method.setBody( newReturn().setReturn( + var( "x" ).itemAt( literal( 4 ) ).itemAt( literal( 2 ) ).getter( "y", String.class ) + ) ); + + assertEquals( target, method.getBody().trim() ); + } + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/SuperTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/SuperTest.java new file mode 100644 index 00000000..e6d749ba --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/SuperTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import java.util.UUID; + +import static org.jboss.forge.roaster.model.expressions.Expressions.cast; +import static org.jboss.forge.roaster.model.expressions.Expressions.classStatic; +import static org.jboss.forge.roaster.model.expressions.Expressions.field; +import static org.jboss.forge.roaster.model.expressions.Expressions.getter; +import static org.jboss.forge.roaster.model.expressions.Expressions.invoke; +import static org.jboss.forge.roaster.model.expressions.Expressions.literal; +import static org.jboss.forge.roaster.model.expressions.Expressions.nullLiteral; +import static org.jboss.forge.roaster.model.expressions.Expressions.operator; +import static org.jboss.forge.roaster.model.expressions.Expressions.paren; +import static org.jboss.forge.roaster.model.expressions.Expressions.sup; +import static org.jboss.forge.roaster.model.expressions.Expressions.ternary; +import static org.jboss.forge.roaster.model.expressions.Expressions.var; +import static org.jboss.forge.roaster.model.statements.Statements.newReturn; +import static org.junit.Assert.assertEquals; + +public class SuperTest +{ + @Test + public void testSuperField() throws Exception + { + String target = "return super.x;"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn().setReturn( sup().field( "x" ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSuperGetter() throws Exception + { + String target = "return super.getX();"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn().setReturn( sup().getter( "x", String.class ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSuperSetter() throws Exception + { + String target = "return super.setX(y);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn().setReturn( sup().setter( "x", String.class, var( "y" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + @Test + public void testSuperInvoke() throws Exception + { + String target = "return super.foo(x);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newReturn().setReturn( sup().invoke( "foo" ).addArgument( var( "x" ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + +} diff --git a/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/WhileStatementsTest.java b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/WhileStatementsTest.java new file mode 100644 index 00000000..0e1682a8 --- /dev/null +++ b/impl/src/test/java/org/jboss/forge/test/roaster/model/statements/WhileStatementsTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Eclipse Public License version 1.0, available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jboss.forge.test.roaster.model.statements; + +import org.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.expressions.Op; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import static org.jboss.forge.roaster.model.statements.Statements.*; +import static org.jboss.forge.roaster.model.expressions.Expressions.*; + + +public class WhileStatementsTest +{ + @Test + public void testSimpleWhile() throws Exception + { + String target = "while (x < 0) {\n x=x + 1;\n}"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newWhile() + .setCondition( operator( Op.LESS ) + .addArgument( var( "x" ) ) + .addArgument( literal( 0 ) ) ) + .setBody( newAssign() + .setLeft( var( "x" ) ) + .setRight( operator( Op.PLUS ).addArgument( var( "x" ) ).addArgument( literal( 1 ) ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + + @Test + public void testSimpleDoWhile() throws Exception + { + String target = "do {\n x=x + 1;\n}\n while (x < 0);"; + MethodSource method = Roaster.create( JavaClassSource.class ).addMethod( "public void hello()" ); + + method.setBody( newDoWhile() + .setCondition( operator( Op.LESS ) + .addArgument( var( "x" ) ) + .addArgument( literal( 0 ) ) ) + .setBody( newAssign() + .setLeft( var( "x" ) ) + .setRight( operator( Op.PLUS ).addArgument( var( "x" ) ).addArgument( literal( 1 ) ) ) ) ); + + assertEquals( target, method.getBody().trim() ); + } + + +}