Move java into own sub-module pmd-java

This commit is contained in:
Andreas Dangel
2014-10-04 17:36:41 +02:00
parent fa950a8296
commit ad88b4784d
743 changed files with 53 additions and 111 deletions

View File

@ -0,0 +1,22 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.util.Properties;
public class JavaLanguage extends AbstractLanguage {
public JavaLanguage() {
this(System.getProperties());
}
public JavaLanguage(Properties properties) {
super(new JavaTokenizer(), ".java");
setProperties(properties);
}
public final void setProperties(Properties properties) {
JavaTokenizer tokenizer = (JavaTokenizer)getTokenizer();
tokenizer.setProperties(properties);
}
}

View File

@ -0,0 +1,181 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.StringReader;
import java.util.Properties;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.lang.java.ast.JavaParserConstants;
import net.sourceforge.pmd.lang.java.ast.Token;
public class JavaTokenizer implements Tokenizer {
public static final String CPD_START = "\"CPD-START\"";
public static final String CPD_END = "\"CPD-END\"";
private boolean ignoreAnnotations;
private boolean ignoreLiterals;
private boolean ignoreIdentifiers;
public void setProperties(Properties properties) {
ignoreAnnotations = Boolean.parseBoolean(properties.getProperty(IGNORE_ANNOTATIONS, "false"));
ignoreLiterals = Boolean.parseBoolean(properties.getProperty(IGNORE_LITERALS, "false"));
ignoreIdentifiers = Boolean.parseBoolean(properties.getProperty(IGNORE_IDENTIFIERS, "false"));
}
public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
StringBuilder stringBuilder = sourceCode.getCodeBuffer();
// Note that Java version is irrelevant for tokenizing
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.4").getLanguageVersionHandler();
String fileName = sourceCode.getFileName();
TokenManager tokenMgr = languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).getTokenManager(
fileName, new StringReader(stringBuilder.toString()));
Token currentToken = (Token) tokenMgr.getNextToken();
TokenDiscarder discarder = new TokenDiscarder(ignoreAnnotations);
while (currentToken.image.length() > 0) {
discarder.updateState(currentToken);
if (discarder.isDiscarding()) {
currentToken = (Token) tokenMgr.getNextToken();
continue;
}
processToken(tokenEntries, fileName, currentToken);
currentToken = (Token) tokenMgr.getNextToken();
}
tokenEntries.add(TokenEntry.getEOF());
}
private void processToken(Tokens tokenEntries, String fileName, Token currentToken) {
String image = currentToken.image;
if (ignoreLiterals
&& (currentToken.kind == JavaParserConstants.STRING_LITERAL
|| currentToken.kind == JavaParserConstants.CHARACTER_LITERAL
|| currentToken.kind == JavaParserConstants.DECIMAL_LITERAL
|| currentToken.kind == JavaParserConstants.FLOATING_POINT_LITERAL)) {
image = String.valueOf(currentToken.kind);
}
if (ignoreIdentifiers && currentToken.kind == JavaParserConstants.IDENTIFIER) {
image = String.valueOf(currentToken.kind);
}
tokenEntries.add(new TokenEntry(image, fileName, currentToken.beginLine));
}
public void setIgnoreLiterals(boolean ignore) {
this.ignoreLiterals = ignore;
}
public void setIgnoreIdentifiers(boolean ignore) {
this.ignoreIdentifiers = ignore;
}
public void setIgnoreAnnotations(boolean ignoreAnnotations) {
this.ignoreAnnotations = ignoreAnnotations;
}
/**
* The {@link TokenDiscarder} consumes token by token and maintains state.
* It can detect, whether the current token belongs to an annotation and whether
* the current token should be discarded by CPD.
* <p>
* By default, it discards semicolons, package and import statements, and enables CPD suppression.
* Optionally, all annotations can be ignored, too.
* </p>
*/
private static class TokenDiscarder {
private boolean isAnnotation = false;
private boolean nextTokenEndsAnnotation = false;
private int annotationStack = 0;
private boolean discardingSemicolon = false;
private boolean discardingKeywords = false;
private boolean discardingSuppressing = false;
private boolean discardingAnnotations = false;
private boolean ignoreAnnotations = false;
public TokenDiscarder(boolean ignoreAnnotations) {
this.ignoreAnnotations = ignoreAnnotations;
}
public void updateState(Token currentToken) {
detectAnnotations(currentToken);
skipSemicolon(currentToken);
skipPackageAndImport(currentToken);
skipCPDSuppression(currentToken);
if (ignoreAnnotations) {
skipAnnotations();
}
}
public void skipPackageAndImport(Token currentToken) {
if (currentToken.kind == JavaParserConstants.PACKAGE || currentToken.kind == JavaParserConstants.IMPORT) {
discardingKeywords = true;
} else if (discardingKeywords && currentToken.kind == JavaParserConstants.SEMICOLON) {
discardingKeywords = false;
}
}
public void skipSemicolon(Token currentToken) {
if (currentToken.kind == JavaParserConstants.SEMICOLON) {
discardingSemicolon = true;
} else if (discardingSemicolon && currentToken.kind != JavaParserConstants.SEMICOLON) {
discardingSemicolon = false;
}
}
public void skipCPDSuppression(Token currentToken) {
//if processing an annotation, look for a CPD-START or CPD-END
if (isAnnotation) {
if (!discardingSuppressing && currentToken.kind == JavaParserConstants.STRING_LITERAL && CPD_START.equals(currentToken.image)) {
discardingSuppressing = true;
} else if (discardingSuppressing && currentToken.kind == JavaParserConstants.STRING_LITERAL && CPD_END.equals(currentToken.image)) {
discardingSuppressing = false;
}
}
}
public void skipAnnotations() {
if (!discardingAnnotations && isAnnotation) {
discardingAnnotations = true;
} else if (discardingAnnotations && !isAnnotation) {
discardingAnnotations = false;
}
}
public boolean isDiscarding() {
boolean result = discardingSemicolon || discardingKeywords || discardingAnnotations || discardingSuppressing;
return result;
}
public void detectAnnotations(Token currentToken) {
if (isAnnotation && nextTokenEndsAnnotation) {
isAnnotation = false;
nextTokenEndsAnnotation = false;
}
if (isAnnotation) {
if (currentToken.kind == JavaParserConstants.LPAREN) {
annotationStack++;
} else if (currentToken.kind == JavaParserConstants.RPAREN) {
annotationStack--;
if (annotationStack == 0) {
nextTokenEndsAnnotation = true;
}
} else if (annotationStack == 0 && currentToken.kind != JavaParserConstants.IDENTIFIER && currentToken.kind != JavaParserConstants.LPAREN) {
isAnnotation = false;
}
}
if (currentToken.kind == JavaParserConstants.AT) {
isAnnotation = true;
}
}
}
}

View File

@ -0,0 +1,106 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Writer;
import net.sf.saxon.sxpath.IndependentContext;
import net.sourceforge.pmd.lang.*;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler;
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.DumpFacade;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.dfa.DataFlowFacade;
import net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule;
import net.sourceforge.pmd.lang.java.rule.JavaRuleViolationFactory;
import net.sourceforge.pmd.lang.java.symboltable.SymbolFacade;
import net.sourceforge.pmd.lang.java.typeresolution.TypeResolutionFacade;
import net.sourceforge.pmd.lang.java.xpath.GetCommentOnFunction;
import net.sourceforge.pmd.lang.java.xpath.JavaFunctions;
import net.sourceforge.pmd.lang.java.xpath.TypeOfFunction;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
/**
* Implementation of LanguageVersionHandler for the Java AST. It uses anonymous classes
* as adapters of the visitors to the VisitorStarter interface.
*
* @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
*/
public abstract class AbstractJavaHandler extends AbstractLanguageVersionHandler {
@Override
public DataFlowHandler getDataFlowHandler() {
return new JavaDataFlowHandler();
}
@Override
public XPathHandler getXPathHandler() {
return new AbstractASTXPathHandler() {
public void initialize() {
TypeOfFunction.registerSelfInSimpleContext();
GetCommentOnFunction.registerSelfInSimpleContext();
}
public void initialize(IndependentContext context) {
super.initialize(context, LanguageRegistry.getLanguage(JavaLanguageModule.NAME), JavaFunctions.class);
}
};
}
public RuleViolationFactory getRuleViolationFactory() {
return JavaRuleViolationFactory.INSTANCE;
}
@Override
public VisitorStarter getDataFlowFacade() {
return new VisitorStarter() {
public void start(Node rootNode) {
new DataFlowFacade().initializeWith(getDataFlowHandler(), (ASTCompilationUnit) rootNode);
}
};
}
@Override
public VisitorStarter getSymbolFacade() {
return new VisitorStarter() {
public void start(Node rootNode) {
new SymbolFacade().initializeWith(null, (ASTCompilationUnit) rootNode);
}
};
}
@Override
public VisitorStarter getSymbolFacade(final ClassLoader classLoader) {
return new VisitorStarter() {
public void start(Node rootNode) {
new SymbolFacade().initializeWith(classLoader, (ASTCompilationUnit) rootNode);
}
};
}
@Override
public VisitorStarter getTypeResolutionFacade(final ClassLoader classLoader) {
return new VisitorStarter() {
public void start(Node rootNode) {
new TypeResolutionFacade().initializeWith(classLoader, (ASTCompilationUnit) rootNode);
}
};
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (JavaNode) rootNode);
}
};
}
@Override
public DFAGraphRule getDFAGraphRule() {
return new JavaDFAGraphRule();
}
}

View File

@ -0,0 +1,62 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import java.util.Map;
import net.sourceforge.pmd.lang.AbstractParser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.AbstractTokenManager;
import net.sourceforge.pmd.lang.ast.JavaCharStream;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* This is a generic Java specific implementation of the Parser interface. It
* creates a JavaParser instance, and sets the exclude marker. It also exposes
* the exclude map from the JavaParser instance.
*
* @see AbstractParser
* @see JavaParser
*/
public abstract class AbstractJavaParser extends AbstractParser {
private JavaParser parser;
public AbstractJavaParser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
public TokenManager createTokenManager(Reader source) {
return new JavaTokenManager(source);
}
/**
* Subclass should override this method to modify the JavaParser as needed.
*/
protected JavaParser createJavaParser(Reader source) throws ParseException {
parser = new JavaParser(new JavaCharStream(source));
String suppressMarker = getParserOptions().getSuppressMarker();
if (suppressMarker != null) {
parser.setSuppressMarker(suppressMarker);
}
return parser;
}
public boolean canParse() {
return true;
}
public Node parse(String fileName, Reader source) throws ParseException {
AbstractTokenManager.setFileName(fileName);
return createJavaParser(source).CompilationUnit();
}
public Map<Integer, String> getSuppressMap() {
return parser.getSuppressMap();
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java13Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java13Parser(parserOptions);
}
}

View File

@ -0,0 +1,29 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.3 grammar.
*
* @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
*/
public class Java13Parser extends AbstractJavaParser {
public Java13Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(3);
return javaParser;
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java14Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java14Parser(parserOptions);
}
}

View File

@ -0,0 +1,29 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.4 grammar.
*
* @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
*/
public class Java14Parser extends AbstractJavaParser {
public Java14Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(4);
return javaParser;
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java15Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java15Parser(parserOptions);
}
}

View File

@ -0,0 +1,29 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.5 grammar.
*
* @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
*/
public class Java15Parser extends AbstractJavaParser {
public Java15Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(5);
return javaParser;
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java16Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java16Parser(parserOptions);
}
}

View File

@ -0,0 +1,27 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.6 grammar.
*/
public class Java16Parser extends AbstractJavaParser {
public Java16Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(6);
return javaParser;
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java17Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java17Parser(parserOptions);
}
}

View File

@ -0,0 +1,27 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.7 grammar.
*/
public class Java17Parser extends AbstractJavaParser {
public Java17Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(7);
return javaParser;
}
}

View File

@ -0,0 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
public class Java18Handler extends AbstractJavaHandler {
public Parser getParser(ParserOptions parserOptions) {
return new Java18Parser(parserOptions);
}
}

View File

@ -0,0 +1,27 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.java.ast.JavaParser;
import net.sourceforge.pmd.lang.java.ast.ParseException;
/**
* Adapter for the JavaParser, using Java 1.8 grammar.
*/
public class Java18Parser extends AbstractJavaParser {
public Java18Parser(ParserOptions parserOptions) {
super(parserOptions);
}
@Override
protected JavaParser createJavaParser(Reader source) throws ParseException {
JavaParser javaParser = super.createJavaParser(source);
javaParser.setJdkVersion(8);
return javaParser;
}
}

View File

@ -0,0 +1,22 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.util.List;
import net.sourceforge.pmd.lang.DataFlowHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.dfa.DataFlowNode;
import net.sourceforge.pmd.lang.java.ast.ASTLabeledStatement;
import net.sourceforge.pmd.lang.java.dfa.JavaDataFlowNode;
public class JavaDataFlowHandler implements DataFlowHandler {
public DataFlowNode createDataFlowNode(List<DataFlowNode> dataFlow, Node node) {
return new JavaDataFlowNode(dataFlow, node);
}
public Class<ASTLabeledStatement> getLabelStatementNodeClass() {
return ASTLabeledStatement.class;
}
}

View File

@ -0,0 +1,24 @@
package net.sourceforge.pmd.lang.java;
import net.sourceforge.pmd.lang.BaseLanguageModule;
import net.sourceforge.pmd.lang.java.rule.JavaRuleChainVisitor;
/**
* Created by christoferdutz on 20.09.14.
*/
public class JavaLanguageModule extends BaseLanguageModule {
public static final String NAME = "Java";
public static final String TERSE_NAME = "java";
public JavaLanguageModule() {
super(NAME, null, TERSE_NAME, JavaRuleChainVisitor.class, "java");
addVersion("1.3", new Java13Handler(), false);
addVersion("1.4", new Java14Handler(), false);
addVersion("1.5", new Java15Handler(), false);
addVersion("1.6", new Java16Handler(), false);
addVersion("1.7", new Java17Handler(), false);
addVersion("1.8", new Java18Handler(), true);
}
}

View File

@ -0,0 +1,29 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java;
import java.io.Reader;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.JavaCharStream;
import net.sourceforge.pmd.lang.java.ast.JavaParserTokenManager;
/**
* Java Token Manager implementation.
*/
public class JavaTokenManager implements TokenManager {
private final JavaParserTokenManager tokenManager;
public JavaTokenManager(Reader source) {
tokenManager = new JavaParserTokenManager(new JavaCharStream(source));
}
public Object getNextToken() {
return tokenManager.getNextToken();
}
public void setFileName(String fileName) {
tokenManager.setFileName(fileName);
}
}

View File

@ -0,0 +1,25 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAdditiveExpression.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAdditiveExpression extends AbstractJavaTypeNode {
public ASTAdditiveExpression(int id) {
super(id);
}
public ASTAdditiveExpression(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAllocationExpression.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAllocationExpression extends AbstractJavaTypeNode {
public ASTAllocationExpression(int id) {
super(id);
}
public ASTAllocationExpression(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAndExpression.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAndExpression extends AbstractJavaTypeNode {
public ASTAndExpression(int id) {
super(id);
}
public ASTAndExpression(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,70 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAnnotation.java */
package net.sourceforge.pmd.lang.java.ast;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.lang.ast.Node;
public class ASTAnnotation extends AbstractJavaNode {
private static List<String> unusedRules = Arrays.asList(new String[] { "UnusedPrivateField", "UnusedLocalVariable",
"UnusedPrivateMethod", "UnusedFormalParameter" });
private static List<String> serialRules = Arrays.asList(new String[] { "BeanMembersShouldSerialize", "MissingSerialVersionUID"});
public ASTAnnotation(int id) {
super(id);
}
public ASTAnnotation(JavaParser p, int id) {
super(p, id);
}
public boolean suppresses(Rule rule) {
final String ruleAnno = "\"PMD." + rule.getName() + "\"";
if (jjtGetChild(0) instanceof ASTSingleMemberAnnotation) {
ASTSingleMemberAnnotation n = (ASTSingleMemberAnnotation) jjtGetChild(0);
return checkAnnototation(n, ruleAnno, rule);
} else if (jjtGetChild(0) instanceof ASTNormalAnnotation) {
ASTNormalAnnotation n = (ASTNormalAnnotation) jjtGetChild(0);
return checkAnnototation(n, ruleAnno, rule);
}
return false;
}
private boolean checkAnnototation(Node n, String ruleAnno, Rule rule) {
if (n.jjtGetChild(0) instanceof ASTName) {
ASTName annName = (ASTName) n.jjtGetChild(0);
if ("SuppressWarnings".equals(annName.getImage())
|| "java.lang.SuppressWarnings".equals(annName.getImage())) {
List<ASTLiteral> nodes = n.findDescendantsOfType(ASTLiteral.class);
for (ASTLiteral element : nodes) {
if (element.hasImageEqualTo("\"PMD\"") || element.hasImageEqualTo(ruleAnno)
// Check for standard annotations values
|| element.hasImageEqualTo("\"all\"")
|| element.hasImageEqualTo("\"serial\"") && serialRules.contains(rule.getName())
|| element.hasImageEqualTo("\"unused\"") && unusedRules.contains(rule.getName())) {
return true;
}
}
}
}
return false;
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,23 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAnnotationMethodDeclaration.java Version 4.1 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY= */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAnnotationMethodDeclaration extends AbstractJavaAccessNode {
public ASTAnnotationMethodDeclaration(int id) {
super(id);
}
public ASTAnnotationMethodDeclaration(JavaParser p, int id) {
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=f6dd440446f8aa5c9c191ae760080ee0 (do not edit this line) */

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAnnotationTypeBody.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAnnotationTypeBody extends AbstractJavaNode {
public ASTAnnotationTypeBody(int id) {
super(id);
}
public ASTAnnotationTypeBody(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,25 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAnnotationTypeDeclaration.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAnnotationTypeDeclaration extends AbstractJavaAccessTypeNode {
public ASTAnnotationTypeDeclaration(int id) {
super(id);
}
public ASTAnnotationTypeDeclaration(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTAnnotationTypeMemberDeclaration.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTAnnotationTypeMemberDeclaration extends AbstractJavaNode {
public ASTAnnotationTypeMemberDeclaration(int id) {
super(id);
}
public ASTAnnotationTypeMemberDeclaration(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTArgumentList.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArgumentList extends AbstractJavaNode {
public ASTArgumentList(int id) {
super(id);
}
public ASTArgumentList(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,31 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTArguments.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArguments extends AbstractJavaNode {
public ASTArguments(int id) {
super(id);
}
public ASTArguments(JavaParser p, int id) {
super(p, id);
}
public int getArgumentCount() {
if (this.jjtGetNumChildren() == 0) {
return 0;
}
return this.jjtGetChild(0).jjtGetNumChildren();
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTArrayDimsAndInits.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArrayDimsAndInits extends AbstractJavaNode {
public ASTArrayDimsAndInits(int id) {
super(id);
}
public ASTArrayDimsAndInits(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

Some files were not shown because too many files have changed in this diff Show More