use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.
the class NodeListTest method replace.
@Test
public void replace() {
final NodeList<Name> list = nodeList(new Name("a"), new Name("b"), new Name("c"));
final boolean replaced = list.replace(new Name("b"), new Name("z"));
assertEquals(true, replaced);
assertEquals(3, list.size());
assertEquals("a", list.get(0).asString());
assertEquals("z", list.get(1).asString());
assertEquals("c", list.get(2).asString());
}
use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.
the class NodeListTest method addBefore.
@Test
public void addBefore() {
Name n = new Name("bcd");
final NodeList<Name> list = nodeList(new Name("abc"), n, new Name("cde"));
list.addBefore(new Name("xxx"), n);
assertEquals("[abc, xxx, bcd, cde]", list.toString());
}
use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.
the class CompilationUnitContext method solveMethod.
@Override
public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly, TypeSolver typeSolver) {
for (ImportDeclaration importDecl : wrappedNode.getImports()) {
if (importDecl.isStatic()) {
if (importDecl.isAsterisk()) {
String importString = importDecl.getNameAsString();
if (this.wrappedNode.getPackageDeclaration().isPresent() && this.wrappedNode.getPackageDeclaration().get().getName().getIdentifier().equals(packageName(importString)) && this.wrappedNode.getTypes().stream().anyMatch(it -> it.getName().getIdentifier().equals(toSimpleName(importString)))) {
// a lower level so this will fail
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
ResolvedTypeDeclaration ref = typeSolver.solveType(importString);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
} else {
String qName = importDecl.getNameAsString();
if (qName.equals(name) || qName.endsWith("." + name)) {
String typeName = getType(qName);
ResolvedTypeDeclaration ref = typeSolver.solveType(typeName);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
}
}
}
}
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.
the class AnnotationMemberDeclarationTransformationsTest method replacingAnnotation.
@Test
public void replacingAnnotation() {
AnnotationMemberDeclaration it = consider("@myAnno int foo();");
it.getAnnotations().set(0, new NormalAnnotationExpr(new Name("myOtherAnno"), new NodeList<>()));
assertTransformedToString("@myOtherAnno() int foo();", it);
}
use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.
the class NodeListTest method addLast.
@Test
public void addLast() {
final NodeList<Name> list = nodeList(new Name("abc"), new Name("bcd"), new Name("cde"));
list.addLast(new Name("xxx"));
assertEquals("[abc, bcd, cde, xxx]", list.toString());
}
Aggregations