use of com.github.javaparser.ast.type.ClassOrInterfaceType in project cas by apereo.
the class ConfigurationMetadataGenerator method parseCompilationUnit.
@SneakyThrows
private void parseCompilationUnit(final Set<ConfigurationMetadataProperty> collectedProps, final Set<ConfigurationMetadataProperty> collectedGroups, final ConfigurationMetadataProperty p, final String typePath, final String typeName, final boolean indexNameWithBrackets) {
try (InputStream is = new FileInputStream(typePath)) {
final CompilationUnit cu = JavaParser.parse(is);
new FieldVisitor(collectedProps, collectedGroups, indexNameWithBrackets, typeName).visit(cu, p);
if (cu.getTypes().size() > 0) {
final ClassOrInterfaceDeclaration decl = ClassOrInterfaceDeclaration.class.cast(cu.getType(0));
for (int i = 0; i < decl.getExtendedTypes().size(); i++) {
final ClassOrInterfaceType parentType = decl.getExtendedTypes().get(i);
final Class parentClazz = locatePropertiesClassForType(parentType);
final String parentTypePath = buildTypeSourcePath(parentClazz.getName());
parseCompilationUnit(collectedProps, collectedGroups, p, parentTypePath, parentClazz.getName(), indexNameWithBrackets);
}
}
}
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project javaparser by javaparser.
the class NodeWithImplements method addImplements.
/**
* Add an implements to this
*
* @param name the name of the type to extends from
* @return this
*/
@SuppressWarnings("unchecked")
public default T addImplements(String name) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
getImplements().add(classOrInterfaceType);
classOrInterfaceType.setParentNode((Node) this);
return (T) this;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project javaparser by javaparser.
the class NodeWithExtends method addExtends.
/**
* Add an extends to this
*
* @param name the name of the type to extends from
* @return this
*/
@SuppressWarnings("unchecked")
public default T addExtends(String name) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
getExtends().add(classOrInterfaceType);
classOrInterfaceType.setParentNode((Node) this);
return (T) this;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project javaparser by javaparser.
the class DefaultPackageTest method aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageImportingIt.
@Test(expected = UnsolvedSymbolException.class)
public void aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageImportingIt() {
String code = "package myPackage; import B; class A extends B {}";
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B"));
ClassOrInterfaceType jpType = JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0);
ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(jpType);
assertEquals("B", resolvedType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project javaparser by javaparser.
the class DefaultPackageTest method aClassInDefaultPackageCanBeAccessedFromTheDefaultPackage.
@Test
public void aClassInDefaultPackageCanBeAccessedFromTheDefaultPackage() {
String code = "class A extends B {}";
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B"));
ClassOrInterfaceType jpType = JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0);
ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(jpType);
assertEquals("B", resolvedType.asReferenceType().getQualifiedName());
}
Aggregations