public void testStaticInitializer() { JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST_STATIC_INITIALIZER)); ASTCompilationUnit c = parser.CompilationUnit(); ASTInitializer a = (ASTInitializer) (c.findChildrenOfType(ASTInitializer.class)).get(0); assertTrue(a.isStatic()); }
public void testFindFieldDecl() { JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST4)); ASTCompilationUnit c = parser.CompilationUnit(); SymbolFacade stb = new SymbolFacade(); stb.initializeWith(c); List children = c.findChildrenOfType(ASTVariableDeclaratorId.class); ASTVariableDeclaratorId v1 = (ASTVariableDeclaratorId) children.get(0); }
/** * @param reader - a Reader to the Java code to analyse * @param ruleSet - the set of rules to process against the file * @param ctx - the context in which PMD is operating. This contains the Renderer and whatnot */ public void processFile(Reader reader, RuleSet ruleSet, RuleContext ctx) throws PMDException { try { JavaParser parser = targetJDKVersion.createParser(reader); ASTCompilationUnit c = parser.CompilationUnit(); Thread.yield(); SymbolFacade stb = new SymbolFacade(); stb.initializeWith(c); List acus = new ArrayList(); acus.add(c); ruleSet.apply(acus, ctx); reader.close(); } catch (ParseException pe) { throw new PMDException("Error while parsing " + ctx.getSourceCodeFilename(), pe); } catch (Exception e) { throw new PMDException("Error while processing " + ctx.getSourceCodeFilename(), e); } }
public void testClashingSymbols() { JavaParser parser = (new TargetJDK1_4()).createParser(new StringReader(TEST1)); ASTCompilationUnit c = parser.CompilationUnit(); SymbolFacade stb = new SymbolFacade(); stb.initializeWith(c); }