use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class Issue1364 method setup.
@Before
public void setup() {
ClassOrInterfaceDeclaration fakeObject = new ClassOrInterfaceDeclaration();
fakeObject.setName(new SimpleName("java.lang.Object"));
TypeSolver typeSolver = new TypeSolver() {
@Override
public TypeSolver getParent() {
return null;
}
@Override
public void setParent(TypeSolver parent) {
}
@Override
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
if ("java.lang.Object".equals(name)) {
// custom handling
return SymbolReference.solved(new JavaParserClassDeclaration(fakeObject, this));
}
return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
}
};
ParserConfiguration config = new ParserConfiguration();
config.setSymbolResolver(new JavaSymbolSolver(typeSolver));
javaParser = new JavaParser(config);
}
use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class NodeListTest method replaceAll.
@Test
public void replaceAll() {
List<String> changes = new LinkedList<>();
String code = "class A { int a; int b; int c; }";
CompilationUnit cu = JavaParser.parse(code);
ClassOrInterfaceDeclaration cd = cu.getClassByName("A").get();
cd.getMembers().register(createObserver(changes));
cd.getMembers().replaceAll(bodyDeclaration -> {
FieldDeclaration clone = (FieldDeclaration) bodyDeclaration.clone();
SimpleName id = clone.getVariable(0).getName();
id.setIdentifier(id.getIdentifier().toUpperCase());
return clone;
});
assertEquals(Arrays.asList("'int a;' REMOVAL in list at 0", "'int A;' ADDITION in list at 0", "'int b;' REMOVAL in list at 1", "'int B;' ADDITION in list at 1", "'int c;' REMOVAL in list at 2", "'int C;' ADDITION in list at 2"), changes);
}
use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class AnnotationMemberDeclarationTest method removeDefaultValueWhenDefaultValueIsPresent.
@Test
public void removeDefaultValueWhenDefaultValueIsPresent() {
AnnotationMemberDeclaration decl = new AnnotationMemberDeclaration();
SimpleName name = new SimpleName("foo");
decl.setName(name);
Expression defaultValue = new IntegerLiteralExpr("2");
decl.setDefaultValue(defaultValue);
decl.removeDefaultValue();
assertFalse(defaultValue.getParentNode().isPresent());
}
use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class AnnotationMemberDeclarationTest method removeDefaultValueWhenNoDefaultValueIsPresent.
@Test
public void removeDefaultValueWhenNoDefaultValueIsPresent() {
AnnotationMemberDeclaration decl = new AnnotationMemberDeclaration();
SimpleName name = new SimpleName("foo");
decl.setName(name);
decl.removeDefaultValue();
assertFalse(decl.getDefaultValue().isPresent());
}
use of com.github.javaparser.ast.expr.SimpleName in project meghanada-server by mopemope.
the class ParameterNameVisitor method visit.
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
final EnumSet<Modifier> modifiers = n.getModifiers();
if (!modifiers.contains(Modifier.PRIVATE)) {
final List<BodyDeclaration<?>> members = n.getMembers();
final SimpleName simpleName = n.getName();
final String clazz = simpleName.getId();
// String clazz = n.getName();
this.className = this.pkg + '.' + clazz;
log.debug("class {}", this.className);
int i = 0;
for (final BodyDeclaration<?> body : members) {
if (body instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) body;
this.getParameterNames(methodDeclaration, n.isInterface());
i++;
} else if (body instanceof ConstructorDeclaration) {
// Constructor
} else if (body instanceof ClassOrInterfaceDeclaration) {
final ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) body;
String name = classOrInterfaceDeclaration.getName().getIdentifier();
String key = this.pkg + '.' + name;
name = this.originClassName + '.' + name;
for (MethodParameterNames mpn : this.parameterNamesList) {
if (mpn != null && mpn.className != null && mpn.className.equals(key)) {
mpn.className = name;
}
}
}
}
if (i > 0 && this.names.className != null) {
this.parameterNamesList.add(this.names);
this.names = new MethodParameterNames();
}
}
}
Aggregations