Skip to content

Commit

Permalink
make materialize returning the created ast node
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco authored and sotty committed Dec 30, 2014
1 parent 49c6938 commit 5955b08
Show file tree
Hide file tree
Showing 55 changed files with 262 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ public interface ASTNode<J extends org.eclipse.jdt.core.dom.ASTNode> {

public AST getAst();

public J getInternal();

public void materialize( AST ast );
public J materialize( AST ast );

void setAst( AST ast );
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -29,12 +28,7 @@ public void setBlock( BlockStatement body ) {
}

@Override
public org.eclipse.jdt.core.dom.Block getInternal() {
public org.eclipse.jdt.core.dom.Block materialize( AST ast ) {
return block;
}

@Override
public void materialize( AST ast ) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@
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;
Expand Down Expand Up @@ -50,16 +44,14 @@ public <X extends org.eclipse.jdt.core.dom.Expression, P> X wireAndGetExpression
JdtExpressionWrapper<O,P,X> node = (JdtExpressionWrapper<O,P,X>) expression;
node.setOrigin( parent );
node.setAst( ast );
node.materialize( ast );
return node.getInternal();
return node.materialize( ast );
}

public <K extends org.eclipse.jdt.core.dom.Statement, P> org.eclipse.jdt.core.dom.Statement wireAndGetStatement( Statement statement, P parent, AST ast ) {
JdtStatementWrapper<O,P,K> node = (JdtStatementWrapper<O,P,K>) statement;
node.setOrigin( parent );
node.setAst( ast );
node.materialize( ast );
return node.getInternal();
return node.materialize( ast );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ public ArrayAccessImpl( Expression<O,ArrayIndexer<O,T>> index ) {
}

@Override
public ArrayAccess getInternal() {
return axx;
}

@Override
public void materialize( AST ast ) {
public ArrayAccess materialize( AST ast ) {
if (axx != null) {
return axx;
}
axx = ast.newArrayAccess();
axx.setIndex( wireAndGetExpression( index, this, ast ) );
if ( target != null ) {
axx.setArray( wireAndGetExpression( target, this, ast ) );
}
return axx;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public ArrayImpl( String type ) {
}

@Override
public ArrayCreation getInternal() {
return array;
}

@Override
public void materialize( AST ast ) {
public ArrayCreation materialize( AST ast ) {
if (array != null) {
return array;
}
array = ast.newArrayCreation();
array.setType( (ArrayType) JDTHelper.getType( type + new String( new char[ getDimension() ] ).replace( "\0", "[]" ), ast ) );
for ( Expression<O,ArrayConstructorExpression<O,T>> dim : dims ) {
Expand All @@ -52,6 +50,7 @@ public void materialize( AST ast ) {
if ( init != null ) {
array.setInitializer( (ArrayInitializer) wireAndGetExpression( init, this, ast ) );
}
return array;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ public int size() {
}

@Override
public ArrayInitializer getInternal() {
return init;
}

@Override
public void materialize( AST ast ) {
public ArrayInitializer materialize( AST ast ) {
if (init != null) {
return init;
}
this.init = ast.newArrayInitializer();
for ( ExpressionSource<O> src : elements ) {
this.init.expressions().add( wireAndGetExpression( src, this, ast ) );
}
return init;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ public AssignExpression<O, T> setRight( Expression right ) {
}

@Override
public Assignment getInternal() {
return axx;
}

@Override
public void materialize( AST ast ) {
public Assignment materialize( AST ast ) {
if (axx != null) {
return axx;
}
axx = ast.newAssignment();
axx.setOperator( Assignment.Operator.toOperator( op.getOp() ) );

Expand All @@ -57,5 +55,6 @@ public void materialize( AST ast ) {
if ( right != null ) {
axx.setRightHandSide( wireAndGetExpression( right, this, ast ) );
}
return axx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ public BooleanLiteralImpl( boolean val ) {
}

@Override
public BooleanLiteral getInternal() {
public BooleanLiteral materialize( AST ast ) {
if (literal == null) {
literal = ast.newBooleanLiteral(val);
}
return literal;
}

@Override
public void materialize( AST ast ) {
literal = ast.newBooleanLiteral( val );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ public CastImpl( String klass, Expression<O,CastExpression<O,T>> expression ) {
this.expression = expression;
}


@Override
public org.eclipse.jdt.core.dom.CastExpression getInternal() {
return cast;
}

@Override
public void materialize( AST ast ) {
public org.eclipse.jdt.core.dom.CastExpression materialize( AST ast ) {
if (cast != null) {
return cast;
}
cast = ast.newCastExpression();
cast.setType( JDTHelper.getType( type, ast ) );
if ( expression != null ) {
Expand All @@ -45,5 +42,6 @@ public void materialize( AST ast ) {
paren.setExpression( expr );
cast.setExpression( paren );
}
return cast;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public CharacterLiteralImpl( Character val ) {
}

@Override
public CharacterLiteral getInternal() {
return literal;
}

@Override
public void materialize( AST ast ) {
public CharacterLiteral materialize( AST ast ) {
if (literal != null) {
return literal;
}
literal = ast.newCharacterLiteral();
literal.setCharValue( val );
return literal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ public ClassLiteralImpl( String val ) {
}

@Override
public TypeLiteral getInternal() {
return literal;
}

@Override
public void materialize( AST ast ) {
public TypeLiteral materialize( AST ast ) {
if (literal != null) {
return literal;
}
literal = ast.newTypeLiteral();
literal.setType( JDTHelper.getType( val, ast ) );
return literal;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ public ConstructorExpression<O,T> addArgument( Argument<O,ConstructorExpression<
}

@Override
public ClassInstanceCreation getInternal() {
return constr;
}

@Override
public void materialize( AST ast ) {
public ClassInstanceCreation materialize( AST ast ) {
if (constr != null) {
return constr;
}
constr = ast.newClassInstanceCreation();
constr.setType( JDTHelper.getType( type, ast ) );

for ( Argument<O,ConstructorExpression<O,T>> arg : arguments ) {
constr.arguments().add( wireAndGetExpression( arg, this, ast ) );
}
return constr;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public DeclareExpression<O, T> init( Expression expr ) {
}

@Override
public VariableDeclarationExpression getInternal() {
return var;
}

@Override
public void materialize( AST ast ) {
public VariableDeclarationExpression materialize( AST ast ) {
if (var != null) {
return var;
}
VariableDeclarationFragment frag = ast.newVariableDeclarationFragment();
frag.setName( ast.newSimpleName( name ) );
var = ast.newVariableDeclarationExpression( frag );
Expand All @@ -52,5 +50,6 @@ public void materialize( AST ast ) {
if ( init != null ) {
frag.setInitializer( wireAndGetExpression( init, this, ast ) );
}
return var;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

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;
Expand Down Expand Up @@ -88,9 +87,4 @@ private void swap( Expression child, Expression parent ) {
sup.wireParent( child );
sub.wireExpression( parent );
}

@Override
public void materialize( AST ast ) {
super.materialize( ast );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ public FieldImpl( String fieldName ) {
}

@Override
public FieldAccess getInternal() {
return fld;
}

@Override
public void materialize( AST ast ) {
public FieldAccess materialize( AST ast ) {
if (fld != null) {
return fld;
}
fld = ast.newFieldAccess();
fld.setName( ast.newSimpleName( fieldName ) );
if ( expression == null ) {
fld.setExpression( ast.newThisExpression() );
} else {
fld.setExpression( wireAndGetExpression( expression, this, ast ) );
}
return fld;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ public InvokeExpression<O, T> setTarget( Expression<O, InvokeExpression<O, T>> t
}

@Override
public MethodInvocation getInternal() {
return invoke;
}

@Override
public void materialize( AST ast ) {
public MethodInvocation materialize( AST ast ) {
if (invoke != null) {
return invoke;
}
invoke = ast.newMethodInvocation();

getInternal().setName( ast.newSimpleName( method ) );
invoke.setName(ast.newSimpleName(method));
if ( target != null ) {
getInternal().setExpression( wireAndGetExpression( target, this, ast ) );
invoke.setExpression(wireAndGetExpression(target, this, ast));
}
return invoke;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ public InstanceofImpl( String klass, Expression<O, InstanceofExpression<O, T>> e
}

@Override
public org.eclipse.jdt.core.dom.InstanceofExpression getInternal() {
return isA;
}

@Override
public void materialize( AST ast ) {
public org.eclipse.jdt.core.dom.InstanceofExpression materialize( AST ast ) {
if (isA != null) {
return isA;
}
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 );
}
return isA;
}
}

0 comments on commit 5955b08

Please sign in to comment.