use of com.github.javaparser.ast.body.TypeDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(TypeDeclarationStmt _n, Object _arg) {
TypeDeclaration typeDecl = cloneNodes(_n.getTypeDeclaration(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
TypeDeclarationStmt r = new TypeDeclarationStmt(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), typeDecl);
r.setComment(comment);
return r;
}
use of com.github.javaparser.ast.body.TypeDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(CompilationUnit _n, Object _arg) {
PackageDeclaration package_ = cloneNodes(_n.getPackage(), _arg);
List<ImportDeclaration> imports = visit(_n.getImports(), _arg);
List<TypeDeclaration> types = visit(_n.getTypes(), _arg);
return new CompilationUnit(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), package_, imports, types);
}
use of com.github.javaparser.ast.body.TypeDeclaration in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(final CompilationUnit n, final Object arg) {
printJavaComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
printer.printLn();
}
if (n.getTypes() != null) {
for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext(); ) {
i.next().accept(this, arg);
printer.printLn();
if (i.hasNext()) {
printer.printLn();
}
}
}
printOrphanCommentsEnding(n);
}
use of com.github.javaparser.ast.body.TypeDeclaration in project javaparser by javaparser.
the class Issue2602Test method setUp.
@BeforeEach
public void setUp() {
typeSolver = new MemoryTypeSolver();
configuration = new ParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
javaParser = new JavaParser(configuration);
// language=JAVA
String src = "package java.lang;" + " class Object {}\n" + "\n" + "class A extends Object {}\n" + "\n" + "class B extends Object {}\n";
ParseResult<CompilationUnit> parseResult = javaParser.parse(ParseStart.COMPILATION_UNIT, provider(src));
System.out.println("parseResult = " + parseResult);
parseResult.getProblems().forEach(problem -> System.out.println("problem.getVerboseMessage() = " + problem.getVerboseMessage()));
assertTrue(parseResult.isSuccessful());
assertEquals(0, parseResult.getProblems().size(), "Expected zero errors when attempting to parse the input code.");
assertTrue(parseResult.getResult().isPresent(), "Must have a parse result to run this test.");
this.cu = parseResult.getResult().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(this.typeSolver);
for (TypeDeclaration t : this.cu.getTypes()) {
JavaParserClassDeclaration classDecl = new JavaParserClassDeclaration((ClassOrInterfaceDeclaration) t, this.typeSolver);
this.typeSolver.addDeclaration((String) t.getFullyQualifiedName().get(), classDecl);
}
}
use of com.github.javaparser.ast.body.TypeDeclaration in project javaparser by javaparser.
the class AnonymousClassDeclarationContext method solveType.
@Override
public SymbolReference<ResolvedTypeDeclaration> solveType(String name) {
List<TypeDeclaration> typeDeclarations = myDeclaration.findMembersOfKind(TypeDeclaration.class);
Optional<SymbolReference<ResolvedTypeDeclaration>> exactMatch = typeDeclarations.stream().filter(internalType -> internalType.getName().getId().equals(name)).findFirst().map(internalType -> SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration(internalType)));
if (exactMatch.isPresent()) {
return exactMatch.get();
}
Optional<SymbolReference<ResolvedTypeDeclaration>> recursiveMatch = typeDeclarations.stream().filter(internalType -> name.startsWith(String.format("%s.", internalType.getName()))).findFirst().map(internalType -> JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(internalType.getName().getId().length() + 1)));
if (recursiveMatch.isPresent()) {
return recursiveMatch.get();
}
Optional<SymbolReference<ResolvedTypeDeclaration>> typeArgumentsMatch = wrappedNode.getTypeArguments().map(nodes -> ((NodeWithTypeArguments<?>) nodes).getTypeArguments().orElse(new NodeList<>())).orElse(new NodeList<>()).stream().filter(type -> type.toString().equals(name)).findFirst().map(matchingType -> SymbolReference.solved(new JavaParserTypeParameter(new TypeParameter(matchingType.toString()), typeSolver)));
if (typeArgumentsMatch.isPresent()) {
return typeArgumentsMatch.get();
}
// Look into extended classes and implemented interfaces
for (ResolvedReferenceType ancestor : myDeclaration.getAncestors()) {
// look at names of extended classes and implemented interfaces (this may not be important because they are checked in CompilationUnitContext)
Optional<ResolvedReferenceTypeDeclaration> optionalTypeDeclaration = ancestor.getTypeDeclaration();
if (optionalTypeDeclaration.isPresent()) {
ResolvedReferenceTypeDeclaration typeDeclaration = optionalTypeDeclaration.get();
if (typeDeclaration.getName().equals(name)) {
return SymbolReference.solved(typeDeclaration);
}
// look into internal types of extended classes and implemented interfaces
try {
for (ResolvedTypeDeclaration internalTypeDeclaration : typeDeclaration.internalTypes()) {
if (internalTypeDeclaration.getName().equals(name)) {
return SymbolReference.solved(internalTypeDeclaration);
}
}
} catch (UnsupportedOperationException e) {
// just continue using the next ancestor
}
}
}
return solveTypeInParentContext(name);
}
Aggregations