use of spoon.reflect.visitor.CtAbstractVisitor in project spoon by INRIA.
the class CtParameterRemoveRefactoring method canRemoveExpression.
/**
* Detects whether `toBeRemovedExpression` can be safely removed during the refactoring
*
* @param toBeRemovedExpression the {@link CtExpression}, which will be removed by this refactoring
* @return true if the expression used to deliver argument of removed parameter can be removed
* false if cannot be removed and this refactoring has to be avoided.
*/
protected boolean canRemoveExpression(CtExpression<?> toBeRemovedExpression) {
class Context {
boolean canBeRemoved = false;
}
final Context context = new Context();
toBeRemovedExpression.accept(new CtAbstractVisitor() {
@Override
public <T> void visitCtVariableRead(CtVariableRead<T> variableRead) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtArrayRead(CtArrayRead<T> arrayRead) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtParameterReference(CtParameterReference<T> reference) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtLiteral(CtLiteral<T> literal) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtNewArray(CtNewArray<T> newArray) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtAnnotationFieldAccess(CtAnnotationFieldAccess<T> annotationFieldAccess) {
context.canBeRemoved = true;
}
@Override
public <T> void visitCtThisAccess(CtThisAccess<T> thisAccess) {
context.canBeRemoved = true;
}
});
return context.canBeRemoved;
}
use of spoon.reflect.visitor.CtAbstractVisitor in project spoon by INRIA.
the class TypeFactory method createTypeAdapter.
/**
* Create a {@link GenericTypeAdapter} for adapting of formal type parameters from any compatible context to the context of provided `formalTypeDeclarer`
*
* @param formalTypeDeclarer
* the target scope of the returned {@link GenericTypeAdapter}
*/
public GenericTypeAdapter createTypeAdapter(CtFormalTypeDeclarer formalTypeDeclarer) {
class Visitor extends CtAbstractVisitor {
GenericTypeAdapter adapter;
@Override
public <T> void visitCtClass(CtClass<T> ctClass) {
adapter = new ClassTypingContext(ctClass);
}
@Override
public <T> void visitCtInterface(CtInterface<T> intrface) {
adapter = new ClassTypingContext(intrface);
}
@Override
public <T> void visitCtMethod(CtMethod<T> m) {
adapter = new MethodTypingContext().setMethod(m);
}
@Override
public <T> void visitCtConstructor(CtConstructor<T> c) {
adapter = new MethodTypingContext().setConstructor(c);
}
}
Visitor visitor = new Visitor();
((CtElement) formalTypeDeclarer).accept(visitor);
return visitor.adapter;
}
Aggregations