当前位置: 首页>>代码示例>>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;未经允许,请勿转载。