use of com.github.javaparser.ast.body.VariableDeclarator in project javaparser by javaparser.
the class NodeTest method removeOrphanCommentNegativeCase.
@Test
public void removeOrphanCommentNegativeCase() {
ClassOrInterfaceDeclaration aClass = new ClassOrInterfaceDeclaration(EnumSet.noneOf(Modifier.class), false, "A");
FieldDeclaration aField = new FieldDeclaration(EnumSet.noneOf(Modifier.class), new VariableDeclarator(PrimitiveType.intType(), "f"));
aClass.getMembers().add(aField);
Comment c = new LineComment("A comment");
aField.addOrphanComment(c);
// the comment is an orphan comment of the field, so trying to remove it on the class should not work
assertFalse(aClass.removeOrphanComment(c));
assertEquals(1, aField.getOrphanComments().size());
assertTrue(c.getParentNode().isPresent());
}
use of com.github.javaparser.ast.body.VariableDeclarator in project javaparser by javaparser.
the class NodeTest method cantFindCompilationUnit.
@Test
public void cantFindCompilationUnit() {
VariableDeclarator x = new VariableDeclarator();
assertFalse(x.findCompilationUnit().isPresent());
}
use of com.github.javaparser.ast.body.VariableDeclarator in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldWithGenericTypeToInteger.
@Test
public void resolveFieldWithGenericTypeToInteger() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics");
VariableDeclarator fieldS = Navigator.demandField(clazz, "i");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("i", fieldS);
assertEquals(true, symbolReference.isPresent());
assertEquals("i", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals("java.lang.Integer", type.asReferenceType().typeParametersValues().get(0).describe());
}
use of com.github.javaparser.ast.body.VariableDeclarator in project javaparser by javaparser.
the class GenericsResolutionTest method resolveElementOfList.
@Test
public void resolveElementOfList() {
CompilationUnit cu = parseSample("ElementOfList");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ElementOfList");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
VariableDeclarator variableDeclarator = Navigator.demandVariableDeclaration(method, "a").get();
Expression expression = variableDeclarator.getInitializer().get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals(false, type.isTypeVariable());
assertEquals("Comment", type.describe());
}
use of com.github.javaparser.ast.body.VariableDeclarator in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldWithGenericTypeToDeclaredClass.
@Test
public void resolveFieldWithGenericTypeToDeclaredClass() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics");
VariableDeclarator fieldS = Navigator.demandField(clazz, "g");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("g", fieldS);
assertEquals(true, symbolReference.isPresent());
assertEquals("g", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals("me.tomassetti.symbolsolver.javaparser.Generics", type.asReferenceType().typeParametersValues().get(0).describe());
}
Aggregations