use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaRuleViolation method isSupressed.
/**
* Check for suppression on this node, on parents, and on contained types
* for ASTCompilationUnit
*
* @param node
*/
public static boolean isSupressed(Node node, Rule rule) {
boolean result = suppresses(node, rule);
if (!result && node instanceof ASTCompilationUnit) {
for (int i = 0; !result && i < node.jjtGetNumChildren(); i++) {
result = suppresses(node.jjtGetChild(i), rule);
}
}
if (!result) {
Node parent = node.jjtGetParent();
while (!result && parent != null) {
result = suppresses(parent, rule);
parent = parent.jjtGetParent();
}
}
return result;
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverJava8Test method testSuperExpression.
@Test
public void testSuperExpression() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass18(SuperExpression.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix"), AbstractJavaTypeNode.class);
int index = 0;
assertEquals(SuperClass.class, expressions.get(index++).getType());
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class NcssCountImportsDecorator method visit.
@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);
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ParserTstUtil method parseJava.
/**
* Parses Java code and executes the symbol table visitor.
*
* @param languageVersionHandler The version handler for the wanted version
* @param code The source code
*
* @return The compilation unit
*/
public static ASTCompilationUnit parseJava(LanguageVersionHandler languageVersionHandler, String code) {
ASTCompilationUnit rootNode = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(code));
languageVersionHandler.getQualifiedNameResolutionFacade(ParserTstUtil.class.getClassLoader()).start(rootNode);
languageVersionHandler.getSymbolFacade().start(rootNode);
return rootNode;
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ParserTstUtil method getOrderedNodes.
public static <E> List<E> getOrderedNodes(Class<E> clazz, String javaCode) {
Collector<E> coll = new Collector<>(clazz, new ArrayList<E>());
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
ASTCompilationUnit cu = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(javaCode));
JavaParserVisitor jpv = (JavaParserVisitor) Proxy.newProxyInstance(JavaParserVisitor.class.getClassLoader(), new Class[] { JavaParserVisitor.class }, coll);
jpv.visit(cu, null);
new QualifiedNameResolver().initializeWith(ParserTstUtil.class.getClassLoader(), cu);
new SymbolFacade().initializeWith(cu);
new DataFlowFacade().initializeWith(languageVersionHandler.getDataFlowHandler(), cu);
return (List<E>) coll.getCollection();
}
Aggregations