本文整理了Java中com.github.javaparser.ast.CompilationUnit.getType()
方法的一些代码示例,展示了CompilationUnit.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.getType()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:getType
暂无
代码示例来源:origin: hs-web/hsweb-framework
if (oldFields.get(name) == null) {
VariableDeclarator declarator = declaration.getVariable(0);
FieldDeclaration newField = old.getType(0)
.addField(declarator.getType(), declarator.getNameAsString(),
declaration.getModifiers().toArray(new Modifier[]{}));
String name = declaration.getNameAsString();
if (oldMethod.get(name) == null) {
MethodDeclaration newMethod = old.getType(0)
.addMethod(name, declaration.getModifiers().toArray(new Modifier[]{}));
代码示例来源:origin: org.apereo.cas/cas-server-core-api-configuration-model
new ConfigurationMetadataFieldVisitor(collectedProps, collectedGroups, indexNameWithBrackets, typeName, sourcePath).visit(cu, p);
if (!cu.getTypes().isEmpty()) {
val decl = ClassOrInterfaceDeclaration.class.cast(cu.getType(0));
for (var i = 0; i < decl.getExtendedTypes().size(); i++) {
val parentType = decl.getExtendedTypes().get(i);
代码示例来源:origin: com.paypal.butterfly/butterfly-utilities
@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;
}
代码示例来源:origin: com.paypal.butterfly/butterfly-utilities
@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;
}
代码示例来源:origin: org.apache.uima/uimaj-v3migration-jcas
(node = pnode.get()) instanceof CompilationUnit) {
CompilationUnit cu2 = (CompilationUnit) node;
className = cu2.getType(0).getNameAsString();
String packageAndClassName =
(className.contains("."))
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
@Test
代码示例来源:origin: com.reprezen.jsonoverlay/jsonoverlay
private Collection<Member> gatherFinalMembers(List<Member> members, CompilationUnit cu) {
Map<String, Member> memberMap = new LinkedHashMap<>();
for (Member member : members) {
String key = member.getKey();
if (!memberMap.containsKey(key)) {
memberMap.put(key, member);
} else {
BodyDeclaration<?> copy = member.getDeclaration().clone();
if (copy instanceof ConstructorDeclaration) {
((ConstructorDeclaration) copy).setBody(JavaParser.parseBlock("{}"));
((ConstructorDeclaration) copy).setComment(null);
} else if (copy instanceof MethodDeclaration) {
((MethodDeclaration) copy).setBody(null);
((MethodDeclaration) copy).setComment(null);
} else if (copy instanceof FieldDeclaration) {
((FieldDeclaration) copy).getVariable(0).setInitializer((Expression) null);
((FieldDeclaration) copy).setComment(null);
}
copy.setAnnotations(new NodeList<>());
Logger.getGlobal().warning(String.format("Suppressing already-present generated member in type %s: %s",
cu.getType(0).getNameAsString(), copy.toString()));
}
}
return memberMap.values();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
代码示例来源:origin: javaparser/javasymbolsolver
@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());
}
代码示例来源:origin: javaparser/javasymbolsolver
@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();
}
内容来源于网络,如有侵权,请联系作者删除!