use of spoon.reflect.declaration.CtMethod in project spoon by INRIA.
the class EqualsChecker method visitCtMethod.
@Override
public <T> void visitCtMethod(CtMethod<T> e) {
final CtMethod peek = (CtMethod) this.other;
if (e.isDefaultMethod() != peek.isDefaultMethod()) {
isNotEqual = true;
return;
}
super.visitCtMethod(e);
}
use of spoon.reflect.declaration.CtMethod in project spoon by INRIA.
the class JavaReflectionTreeBuilder method visitAnnotation.
@Override
public void visitAnnotation(final Annotation annotation) {
final CtAnnotation<Annotation> ctAnnotation = factory.Core().createAnnotation();
enter(new AnnotationRuntimeBuilderContext(ctAnnotation) {
@Override
public void addMethod(CtMethod ctMethod) {
try {
Object value = annotation.annotationType().getMethod(ctMethod.getSimpleName()).invoke(annotation);
ctAnnotation.addValue(ctMethod.getSimpleName(), value);
} catch (Exception ignore) {
ctAnnotation.addValue(ctMethod.getSimpleName(), "");
}
}
});
super.visitAnnotation(annotation);
exit();
contexts.peek().addAnnotation(ctAnnotation);
}
use of spoon.reflect.declaration.CtMethod in project spoon by INRIA.
the class JavaReflectionTreeBuilder method visitInterface.
@Override
public <T> void visitInterface(Class<T> clazz) {
final CtInterface<Object> ctInterface = factory.Core().createInterface();
ctInterface.setSimpleName(clazz.getSimpleName());
setModifier(ctInterface, clazz.getModifiers());
enter(new TypeRuntimeBuilderContext(ctInterface) {
@Override
public void addMethod(CtMethod ctMethod) {
super.addMethod(ctMethod);
ctMethod.setBody(null);
}
});
super.visitInterface(clazz);
exit();
contexts.peek().addType(ctInterface);
}
use of spoon.reflect.declaration.CtMethod in project spoon by INRIA.
the class AnnotationTest method testGetAnnotationFromParameter.
@Test
public void testGetAnnotationFromParameter() {
// contract: Java 8 receiver parameters are handled
Launcher spoon = new Launcher();
spoon.addInputResource("src/test/resources/noclasspath/Initializer.java");
String output = "target/spooned-" + this.getClass().getSimpleName() + "-firstspoon/";
spoon.setSourceOutputDirectory(output);
spoon.getEnvironment().setNoClasspath(true);
Factory factory = spoon.getFactory();
spoon.buildModel();
List<CtMethod> methods = factory.getModel().getElements(new NamedElementFilter<>(CtMethod.class, "setField"));
assertThat(methods.size(), is(1));
CtMethod methodSet = methods.get(0);
assertThat(methodSet.getSimpleName(), is("setField"));
List<CtParameter> parameters = methodSet.getParameters();
assertThat(parameters.size(), is(1));
CtParameter thisParameter = parameters.get(0);
assertThat(thisParameter.getSimpleName(), is("this"));
CtTypeReference thisParamType = thisParameter.getType();
assertThat(thisParamType.getSimpleName(), is("Initializer"));
List<CtAnnotation<?>> annotations = thisParameter.getType().getAnnotations();
assertThat(annotations.size(), is(2));
CtAnnotation unknownInit = annotations.get(0);
CtAnnotation raw = annotations.get(1);
assertThat(unknownInit.getAnnotationType().getSimpleName(), is("UnknownInitialization"));
assertThat(raw.getAnnotationType().getSimpleName(), is("Raw"));
}
use of spoon.reflect.declaration.CtMethod in project spoon by INRIA.
the class AnnotationTest method annotationAddValue.
@Test
public void annotationAddValue() {
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/annotation/testclasses/Bar.java");
spoon.buildModel();
Factory factory = spoon.getFactory();
List<CtMethod> methods = factory.getModel().getElements(new NamedElementFilter<CtMethod>(CtMethod.class, "bidule"));
assertThat(methods.size(), is(1));
CtAnnotation anno1 = factory.Annotation().annotate(methods.get(0), TypeAnnotation.class).addValue("params", new String[] { "test" });
assertThat(anno1.getValue("params").getType(), is(factory.Type().createReference(String[].class)));
CtAnnotation anno = factory.Annotation().annotate(methods.get(0), TypeAnnotation.class).addValue("params", new String[0]);
assertThat(anno.getValue("params").getType(), is(factory.Type().createReference(String[].class)));
}
Aggregations