private String getClassName(ASTCompilationUnit node) { ASTAnyTypeDeclaration classDecl = node.getFirstDescendantOfType(ASTAnyTypeDeclaration.class); if (classDecl == null) { // package-info.java? return null; } if (node.declarationsAreInDefaultPackage()) { return classDecl.getImage(); } importedOnDemand.add(node.getPackageDeclaration().getPackageNameImage()); return classDecl.getQualifiedName().toString(); }
/** * Creates a new global scope for an AST node. The new scope is stored on * the scope stack. * * @param node * the AST node for which the scope has to be created. */ private void createSourceFileScope(ASTCompilationUnit node) { // When we do full symbol resolution, we'll need to add a truly // top-level GlobalScope. SourceFileScope scope; ASTPackageDeclaration n = node.getPackageDeclaration(); if (n != null) { scope = new SourceFileScope(classLoader, n.jjtGetChild(0).getImage()); } else { scope = new SourceFileScope(classLoader); } scope.configureImports(node.findChildrenOfType(ASTImportDeclaration.class)); scopes.push(scope); node.setScope(scope); }
protected SortedMap<Integer, Node> orderedCommentsAndDeclarations(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.getComments()); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTFieldDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTMethodDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTConstructorDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTEnumDeclaration.class, true)); return itemsByLineNumber; }
public void initializeWith(ClassLoader classLoader, ASTCompilationUnit node) { ClassTypeResolver classTypeResolver = new ClassTypeResolver(classLoader); node.setClassTypeResolver(classTypeResolver); node.jjtAccept(classTypeResolver, null); }
private boolean isTestNgClass(ASTCompilationUnit node) { List<ASTImportDeclaration> imports = node.findDescendantsOfType(ASTImportDeclaration.class); for (ASTImportDeclaration i : imports) { if (i.getImportedName() != null && i.getImportedName().startsWith("org.testng")) { return true; } } return false; }
@Override public Object visit(final ASTCompilationUnit node, final Object data) { interestingLineNumberComments.clear(); final List<Comment> comments = node.getComments(); for (final Comment comment : comments) { if (getProperty(REGEX_DESCRIPTOR).matcher(comment.getImage()).matches()) { interestingLineNumberComments.add(comment.getBeginLine()); } } return super.visit(node, data); }
public static boolean importsPackage(ASTCompilationUnit node, String packageName) { List<ASTImportDeclaration> nodes = node.findChildrenOfType(ASTImportDeclaration.class); for (ASTImportDeclaration n : nodes) { if (n.getPackageName().startsWith(packageName)) { return true; } } return false; }
ASTCompilationUnit jjtn000 = new ASTCompilationUnit(this, JJTCOMPILATIONUNIT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (jj_2_1(2147483647)) { jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); jjtn000.setComments(token_source.comments); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
@Override public Object visit(ASTCompilationUnit node, Object data) { boolean hasImportSqlMapClient = hasSqlMapClientImport(node.findChildrenOfType(ASTImportDeclaration.class)); if (!hasImportSqlMapClient) { return super.visit(node, data); } List<ASTClassOrInterfaceDeclaration> classOrInterfaceDeclarations = node.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class); if (classOrInterfaceDeclarations == null || classOrInterfaceDeclarations.isEmpty()) { return super.visit(node, data); } for (ASTClassOrInterfaceDeclaration classOrInterfaceDeclaration : classOrInterfaceDeclarations) { visitASTClassOrInterfaceDeclaration(classOrInterfaceDeclaration, data); } return super.visit(node, data); }
private boolean isJUnit3Class(ASTCompilationUnit node) { ASTClassOrInterfaceDeclaration cid = node.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class); if (cid == null) { return false; } if (node.getType() != null && TypeHelper.isA(node, JUNIT3_CLASS_NAME)) { return true; } else if (node.getType() == null) { ASTExtendsList extendsList = cid.getFirstChildOfType(ASTExtendsList.class); if (extendsList == null) { return false; } if (((ASTClassOrInterfaceType) extendsList.jjtGetChild(0)).getImage().endsWith("TestCase")) { return true; } String className = cid.getImage(); return className.endsWith("Test"); } else if (hasImports(node, JUNIT3_CLASS_NAME)) { return cid.getImage().endsWith("Test"); } return false; }
List<ASTImportDeclaration> theImportDeclarations = node.findChildrenOfType(ASTImportDeclaration.class); if (staticClassWithField != null) { JavaTypeDefinition typeDef = getFieldType(JavaTypeDefinition.forClass(staticClassWithField), fieldName, currentAcu.getType()); staticFieldImageToTypeDef.put(fieldName, typeDef);
private void populateClassName(ASTCompilationUnit node, String className) throws ClassNotFoundException { node.setType(pmdClassLoader.loadClass(className)); importedClasses.putAll(pmdClassLoader.getImportedClasses(className)); } }
public boolean declarationsAreInDefaultPackage() { return getPackageDeclaration() == null; }
public void initializeWith(ClassLoader classLoader, ASTCompilationUnit node) { ClassTypeResolver classTypeResolver = new ClassTypeResolver(classLoader); node.setClassTypeResolver(classTypeResolver); node.jjtAccept(classTypeResolver, null); }
private boolean hasImports(ASTCompilationUnit cu, String className) { List<ASTImportDeclaration> imports = cu.findDescendantsOfType(ASTImportDeclaration.class); for (ASTImportDeclaration importDeclaration : imports) { ASTName name = importDeclaration.getFirstChildOfType(ASTName.class); if (name != null && name.hasImageEqualTo(className)) { return true; } } return false; } }
return; for (Comment comment : node.getComments()) { if (!(comment instanceof FormalComment)) { continue;
public void initializeWith(ASTCompilationUnit rootNode) { PackageStats projectMirror = PackageStats.INSTANCE; MultifileVisitor visitor = new MultifileVisitor(projectMirror); rootNode.jjtAccept(visitor, null); }
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { ASTCompilationUnit acu = node.getFirstParentOfType(ASTCompilationUnit.class); List<ASTImportDeclaration> imports = acu.findChildrenOfType(ASTImportDeclaration.class); int increment = imports.size(); if (!acu.findChildrenOfType(ASTPackageDeclaration.class).isEmpty()) { increment++; } ((MutableInt) data).add(increment); return super.visit(node, data); } }
ASTCompilationUnit jjtn000 = new ASTCompilationUnit(this, JJTCOMPILATIONUNIT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (jj_2_1(2147483647)) { jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); jjtn000.setComments(token_source.comments); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));