use of com.github.javaparser.ast.NodeList in project mybatis-generator-gui-extension by spawpaw.
the class MyShellCallback method mergeCompilationUnit.
/**
* 合并可编译单元(即合并两个Java文件)
*/
private CompilationUnit mergeCompilationUnit(CompilationUnit oldCompilationUnit, CompilationUnit newCompilationUnit) {
CompilationUnit finalCompilationUnit = new CompilationUnit();
// 修改包名为新类的包名
if (newCompilationUnit.getPackageDeclaration().isPresent())
finalCompilationUnit.setPackageDeclaration(newCompilationUnit.getPackageDeclaration().get());
// 合并import
Set<ImportDeclaration> importSet = new HashSet<>();
importSet.addAll(oldCompilationUnit.getImports());
importSet.addAll(newCompilationUnit.getImports());
NodeList<ImportDeclaration> imports = new NodeList<>();
imports.addAll(importSet);
finalCompilationUnit.setImports(imports);
// 合并topLevelClass
finalCompilationUnit.setTypes(mergeTypes(oldCompilationUnit.getTypes(), newCompilationUnit.getTypes()));
return finalCompilationUnit;
}
use of com.github.javaparser.ast.NodeList in project flow by vaadin.
the class GeneratorUtilsTest method should_Not_BeConsideredAsHavingAnAnnotation_When_GivenClassHavsAnnotationDeclarationButWithDifferentImport.
@Test
public void should_Not_BeConsideredAsHavingAnAnnotation_When_GivenClassHavsAnnotationDeclarationButWithDifferentImport() {
NodeWithAnnotations<?> declarationWithEndpointAnnotation = Mockito.mock(NodeWithAnnotations.class);
CompilationUnit compilationUnitWithNonVaadinEndpointImport = Mockito.mock(CompilationUnit.class);
AnnotationExpr endpointAnnotation = Mockito.mock(AnnotationExpr.class);
Mockito.doReturn(Optional.of(endpointAnnotation)).when(declarationWithEndpointAnnotation).getAnnotationByClass(Endpoint.class);
NodeList<ImportDeclaration> imports = new NodeList<>();
ImportDeclaration importDeclaration = Mockito.mock(ImportDeclaration.class);
Mockito.doReturn("some.non.vaadin.Endpoint").when(importDeclaration).getNameAsString();
imports.add(importDeclaration);
Mockito.doReturn(imports).when(compilationUnitWithNonVaadinEndpointImport).getImports();
Assert.assertFalse("A class with a non Vaadin Endpoint should not be considered as an Endpoint", GeneratorUtils.hasAnnotation(declarationWithEndpointAnnotation, compilationUnitWithNonVaadinEndpointImport, Endpoint.class));
}
use of com.github.javaparser.ast.NodeList in project flow by vaadin.
the class OpenAPIObjectGenerator method toMappedType.
ResolvedType toMappedType(Type type) {
ResolvedType resolvedType;
try {
resolvedType = type.resolve();
} catch (UnsupportedOperationException e) {
// This is called for T
return null;
}
if (!resolvedType.isReferenceType()) {
return null;
}
String className = getFullyQualifiedName(new GeneratorType(type));
String mappedClassName = endpointTransferMapper.getTransferType(className);
if (mappedClassName == null) {
return null;
}
List<ResolvedType> typeArguments = new ArrayList<>();
if (type.isClassOrInterfaceType()) {
Optional<NodeList<Type>> maybeTypeArgs = type.asClassOrInterfaceType().getTypeArguments();
if (maybeTypeArgs.isPresent()) {
NodeList<Type> typeArgs = maybeTypeArgs.get();
for (Type typeArg : typeArgs) {
typeArguments.add(typeArg.resolve());
}
}
}
ResolvedReferenceTypeDeclaration solved = typeSolver.solveType(mappedClassName);
return new ReferenceTypeImpl(solved, typeArguments, typeSolver);
}
Aggregations