本文整理汇总了Java中com.github.javaparser.ast.CompilationUnit.getType方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getType方法的具体用法?Java CompilationUnit.getType怎么用?Java CompilationUnit.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeName
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
protected String getTypeName(CompilationUnit compilationUnit, int index) {
ClassOrInterfaceDeclaration type = (ClassOrInterfaceDeclaration) compilationUnit.getType(0);
NodeList<ClassOrInterfaceType> extendedTypes = type.getExtendedTypes();
ClassOrInterfaceType extendedType = extendedTypes.get(index);
String typeSimpleName = extendedType.getName().getIdentifier();
Optional<ClassOrInterfaceType> scope = extendedType.getScope();
String typeName;
if (scope.isPresent()) {
String typePackageName = scope.get().toString();
typeName = String.format("%s.%s", typePackageName, typeSimpleName);
} else {
typeName = typeSimpleName;
}
return typeName;
}
示例2: getNumberOfTypes
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
protected int getNumberOfTypes(CompilationUnit compilationUnit) {
TypeDeclaration<?> typeDeclaration = compilationUnit.getType(0);
if (typeDeclaration instanceof ClassOrInterfaceDeclaration) {
ClassOrInterfaceDeclaration type = (ClassOrInterfaceDeclaration) compilationUnit.getType(0);
NodeList<ClassOrInterfaceType> extendedTypes = type.getExtendedTypes();
return extendedTypes.size();
}
// If typeDeclaration is not ClassOrInterfaceDeclaration, then it is
// EnumDeclaration or AnnotationDeclaration, and none of them have
// a getExtendedTypes operation
return 0;
}
示例3: annotationDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void annotationDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/Annotations.java.txt"));
CompilationUnit cu = parseWithSymbolResolution(f);
AnnotationDeclaration declaration = (AnnotationDeclaration)cu.getType(0);
assertEquals("MyAnnotation", declaration.getNameAsString());
ResolvedAnnotationDeclaration resolvedDeclaration = declaration.resolve();
}
示例4: annotationMemberDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void annotationMemberDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/Annotations.java.txt"));
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
AnnotationDeclaration declaration = (AnnotationDeclaration)cu.getType(2);
assertEquals("MyAnnotationWithFields", declaration.getNameAsString());
AnnotationMemberDeclaration memberDeclaration = (AnnotationMemberDeclaration)declaration.getMember(0);
ResolvedAnnotationMemberDeclaration resolvedDeclaration = memberDeclaration.resolve();
}
示例5: classDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void classDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration)cu.getType(0);
declaration.resolve();
}
示例6: interfaceDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void interfaceDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/MethodTypeParams.java.txt"));
CompilationUnit cu = parseWithSymbolResolution(f);
ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration)cu.getType(1);
assertEquals("VoidVisitor", declaration.getNameAsString());
assertEquals(true, declaration.isInterface());
declaration.resolve();
}
示例7: constructorDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void constructorDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration)cu.getType(0);
ConstructorDeclaration constructorDeclaration = classOrInterfaceDeclaration.getDefaultConstructor().get();
ResolvedConstructorDeclaration resolvedConstructorDeclaration = constructorDeclaration.resolve();
}
示例8: enumDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void enumDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
EnumDeclaration declaration = (EnumDeclaration) cu.getType(0);
assertEquals("AccessSpecifier", declaration.getNameAsString());
ResolvedEnumDeclaration resolvedDeclaration = declaration.resolve();
}
示例9: enumConstantDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void enumConstantDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
EnumDeclaration enumDeclaration = (EnumDeclaration) cu.getType(0);
assertEquals("AccessSpecifier", enumDeclaration.getNameAsString());
EnumConstantDeclaration declaration = enumDeclaration.getEntry(0);
assertEquals("PUBLIC", declaration.getNameAsString());
ResolvedEnumConstantDeclaration resolvedDeclaration = declaration.resolve();
}
示例10: fieldDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void fieldDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
assertEquals("CompilationUnit", classDeclaration.getNameAsString());
FieldDeclaration declaration = classDeclaration.getFields().get(0);
ResolvedFieldDeclaration resolvedDeclaration = declaration.resolve();
}
示例11: methodDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void methodDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
assertEquals("CompilationUnit", classDeclaration.getNameAsString());
MethodDeclaration declaration = classDeclaration.getMethodsByName("getComments").get(0);
ResolvedMethodDeclaration resolvedDeclaration = declaration.resolve();
assertEquals("getComments", resolvedDeclaration.getName());
assertEquals(0, resolvedDeclaration.getNumberOfParams());
}
示例12: parameterDeclarationResolve
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void parameterDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
assertEquals("CompilationUnit", classDeclaration.getNameAsString());
MethodDeclaration methodDeclaration = classDeclaration.getMethodsByName("setComments").get(0);
Parameter declaration = methodDeclaration.getParameter(0);
ResolvedParameterDeclaration resolvedDeclaration = declaration.resolve();
}