Skip to content

Commit

Permalink
Merge pull request #611 from leventov/pr_611
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Apr 22, 2016
2 parents aa2bc75 + 36908e1 commit 71b02dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/main/java/spoon/reflect/factory/CodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,27 @@ public <T> CtBinaryOperator<T> createBinaryOperator(CtExpression<?> left, CtExpr

/**
* Creates a accessed type.
*
* <p>This method sets a <i>clone</i> of the given {@code accessedType} object to the
* {@linkplain CtTypeAccess#getAccessedType() accessedType} field of the returned {@link CtTypeAccess}. If the
* given {@code accessedType} is unique and cloning is not needed, use
* {@link #createTypeAccessWithoutCloningReference(CtTypeReference)} instead of this method.</p>
* @param accessedType a type reference to the accessed type.
* @param <T> the type of the expression.
* @return a accessed type expression.
*/
public <T> CtTypeAccess<T> createTypeAccess(CtTypeReference<T> accessedType) {
CtTypeReference<T> accessedTypeClone = factory.Core().clone(accessedType);
return createTypeAccessWithoutCloningReference(accessedTypeClone);
}

/**
* Creates a accessed type, see {@link #createTypeAccess(CtTypeReference)} for details.
* @param accessedType a type reference to the accessed type.
* @param <T> the type of the expression.
* @return a accessed type expression.
*/
public <T> CtTypeAccess<T> createTypeAccessWithoutCloningReference(CtTypeReference<T> accessedType) {
final CtTypeAccess<T> typeAccess = factory.Core().createTypeAccess();
typeAccess.setAccessedType(accessedType);
return typeAccess;
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3099,7 +3099,8 @@ public boolean visit(ParameterizedQualifiedTypeReference parameterizedQualifiedT
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(parameterizedQualifiedTypeReference.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(parameterizedQualifiedTypeReference.resolvedType));
context.enter(typeAccess, parameterizedQualifiedTypeReference);
return true;
}
Expand All @@ -3109,7 +3110,8 @@ public boolean visit(ParameterizedQualifiedTypeReference parameterizedQualifiedT
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(parameterizedQualifiedTypeReference.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(parameterizedQualifiedTypeReference.resolvedType));
context.enter(typeAccess, parameterizedQualifiedTypeReference);
return true;
}
Expand All @@ -3119,7 +3121,8 @@ public boolean visit(ParameterizedSingleTypeReference parameterizedSingleTypeRef
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(parameterizedSingleTypeReference.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(parameterizedSingleTypeReference.resolvedType));
context.enter(typeAccess, parameterizedSingleTypeReference);
return true;
}
Expand All @@ -3129,7 +3132,8 @@ public boolean visit(ParameterizedSingleTypeReference parameterizedSingleTypeRef
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(parameterizedSingleTypeReference.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(parameterizedSingleTypeReference.resolvedType));
context.enter(typeAccess, parameterizedSingleTypeReference);
return super.visit(parameterizedSingleTypeReference, scope);
}
Expand Down Expand Up @@ -3304,15 +3308,16 @@ public boolean onAccess(char[][] tokens, int index) {
context.enter(va, qualifiedNameReference);
return false;
} else if (qualifiedNameReference.binding instanceof TypeBinding) {
CtTypeAccess<Object> ta = factory.Code().createTypeAccess(references.getTypeReference((TypeBinding) qualifiedNameReference.binding));
CtTypeAccess<Object> ta = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference((TypeBinding) qualifiedNameReference.binding));
context.enter(ta, qualifiedNameReference);
return false;
} else if (qualifiedNameReference.binding instanceof ProblemBinding) {
CtVariableAccess<Object> va;
if (context.stack.peek().element instanceof CtInvocation) {
final CtTypeReference<Object> typeReference = factory.Core().createTypeReference();
typeReference.setSimpleName(qualifiedNameReference.toString());
final CtTypeAccess<Object> ta = factory.Code().createTypeAccess(typeReference);
final CtTypeAccess<Object> ta = factory.Code().createTypeAccessWithoutCloningReference(typeReference);
context.enter(ta, qualifiedNameReference);
return false;
} else if (context.stack.peek().element instanceof CtAssignment && context.assigned) {
Expand Down Expand Up @@ -3354,7 +3359,8 @@ public boolean visit(QualifiedTypeReference arg0, BlockScope arg1) {
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(arg0.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(arg0.resolvedType));
context.enter(typeAccess, arg0);
return true; // do nothing by default, keep traversing
}
Expand Down Expand Up @@ -3415,7 +3421,8 @@ public boolean visit(SingleNameReference singleNameReference, BlockScope scope)
}
va.setVariable(references.getVariableReference((VariableBinding) singleNameReference.binding));
} else if (singleNameReference.binding instanceof TypeBinding) {
CtTypeAccess<Object> ta = factory.Code().createTypeAccess(references.getTypeReference((TypeBinding) singleNameReference.binding));
CtTypeAccess<Object> ta = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference((TypeBinding) singleNameReference.binding));
context.enter(ta, singleNameReference);
} else if (singleNameReference.binding instanceof ProblemBinding) {
if (context.stack.peek().element instanceof CtInvocation
Expand Down Expand Up @@ -3471,7 +3478,7 @@ public boolean visit(QualifiedSuperReference qualifiedSuperReference, BlockScope
CtTypeReference<Object> typeRefOfSuper = references.getTypeReference(qualifiedSuperReference.qualification.resolvedType);
final CtSuperAccess<Object> superAccess = factory.Core().createSuperAccess();

CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(typeRefOfSuper);
CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(typeRefOfSuper);
superAccess.setTarget(typeAccess);

context.enter(superAccess, qualifiedSuperReference);
Expand Down Expand Up @@ -3514,7 +3521,8 @@ public boolean visit(SingleTypeReference singleTypeReference, BlockScope scope)
if (skipTypeInAnnotation) {
return true;
}
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(singleTypeReference.resolvedType));
final CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(singleTypeReference.resolvedType));
context.enter(typeAccess, singleTypeReference);
return true; // do nothing by default, keep traversing
}
Expand All @@ -3524,7 +3532,8 @@ public boolean visit(SingleTypeReference singleTypeReference, ClassScope scope)
if (skipTypeInAnnotation) {
return true;
}
CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccess(references.getTypeReference(singleTypeReference.resolvedType));
CtTypeAccess<Object> typeAccess = factory.Code().createTypeAccessWithoutCloningReference(
references.getTypeReference(singleTypeReference.resolvedType));
context.enter(typeAccess, singleTypeReference);
return true; // do nothing by default, keep traversing
}
Expand Down

0 comments on commit 71b02dd

Please sign in to comment.