當前位置: 首頁>>代碼示例>>Java>>正文


Java CompilationUnit.getType方法代碼示例

本文整理匯總了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;
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:17,代碼來源:Extends.java

示例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;
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:16,代碼來源:Extends.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:9,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:12,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:8,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:10,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:9,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:9,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:11,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:10,代碼來源:JavaParserAPIIntegrationTest.java

示例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());
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:12,代碼來源:JavaParserAPIIntegrationTest.java

示例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();
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:13,代碼來源:JavaParserAPIIntegrationTest.java


注:本文中的com.github.javaparser.ast.CompilationUnit.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。