Skip to content

Commit

Permalink
pmd-plsql: checkstyle / formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Dec 2, 2016
1 parent b771a37 commit 2682bf1
Show file tree
Hide file tree
Showing 80 changed files with 3,710 additions and 3,731 deletions.
31 changes: 15 additions & 16 deletions pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLLanguage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.cpd;

import java.util.Properties;
Expand All @@ -10,21 +11,19 @@
* @author Stuart Turton [email protected]
*/
public class PLSQLLanguage extends AbstractLanguage {
public PLSQLLanguage() {
super("PL/SQL", "plsql", new PLSQLTokenizer()
,".sql"
,".trg" //Triggers
,".prc",".fnc" // Standalone Procedures and Functions
,".pld" // Oracle*Forms
,".pls" ,".plh" ,".plb" // Packages
,".pck" ,".pks" ,".pkh" ,".pkb" // Packages
,".typ" ,".tyb" // Object Types
,".tps" ,".tpb" // Object Types
);
}
public PLSQLLanguage() {
super("PL/SQL", "plsql", new PLSQLTokenizer(), ".sql", ".trg" // Triggers
, ".prc", ".fnc" // Standalone Procedures and Functions
, ".pld" // Oracle*Forms
, ".pls", ".plh", ".plb" // Packages
, ".pck", ".pks", ".pkh", ".pkb" // Packages
, ".typ", ".tyb" // Object Types
, ".tps", ".tpb" // Object Types
);
}

@Override
public final void setProperties(Properties properties) {
((PLSQLTokenizer)getTokenizer()).setProperties(properties);
}
@Override
public final void setProperties(Properties properties) {
((PLSQLTokenizer) getTokenizer()).setProperties(properties);
}
}
145 changes: 68 additions & 77 deletions pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLTokenizer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.cpd;

import java.io.StringReader;
Expand All @@ -13,7 +14,7 @@
import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserTokenManager;
import net.sourceforge.pmd.lang.plsql.ast.Token;

public class PLSQLTokenizer implements Tokenizer{
public class PLSQLTokenizer implements Tokenizer {
private static final Logger LOGGER = Logger.getLogger(PLSQLTokenizer.class.getName());

public static final String IGNORE_COMMENTS = "ignore_comments";
Expand All @@ -25,101 +26,91 @@ public class PLSQLTokenizer implements Tokenizer{
private boolean ignoreLiterals;

public void setProperties(Properties properties) {
/* The Tokenizer is derived from PLDoc, in which comments are very important
* When looking for duplication, we are probably not interested in comment variation,
* so we shall default ignoreComments to true
*/
/*
* The Tokenizer is derived from PLDoc, in which comments are very
* important When looking for duplication, we are probably not
* interested in comment variation, so we shall default ignoreComments
* to true
*/
ignoreComments = Boolean.parseBoolean(properties.getProperty(IGNORE_COMMENTS, "true"));
ignoreIdentifiers = Boolean.parseBoolean(properties.getProperty(IGNORE_IDENTIFIERS, "false"));
ignoreLiterals = Boolean.parseBoolean(properties.getProperty(IGNORE_LITERALS, "false"));
}

public void setIgnoreComments(boolean ignore) {
this.ignoreComments = ignore;
this.ignoreComments = ignore;
}

public void setIgnoreLiterals(boolean ignore) {
this.ignoreLiterals = ignore;
this.ignoreLiterals = ignore;
}

public void setIgnoreIdentifiers(boolean ignore) {
this.ignoreIdentifiers = ignore;
this.ignoreIdentifiers = ignore;
}

/**
* Read Reader from SourceCode and output an ordered tree of PLSQL tokens.
* @param sourceCode PLSQL source in file, string or database (any suitable object that can return
* a Reader).
* @param tokenEntries Derived based on PLSQL Abstract Syntax Tree (derived from PLDOc parser.)
*/
@Override
public void tokenize (SourceCode sourceCode, Tokens tokenEntries )
{
/**
* Read Reader from SourceCode and output an ordered tree of PLSQL tokens.
*
* @param sourceCode
* PLSQL source in file, string or database (any suitable object
* that can return a Reader).
* @param tokenEntries
* Derived based on PLSQL Abstract Syntax Tree (derived from
* PLDOc parser.)
*/
@Override
public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
long encounteredTokens = 0;
long addedTokens = 0;

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("PLSQLTokenizer: ignoreComments=="+ignoreComments);
LOGGER.fine("PLSQLTokenizer: ignoreIdentifiers=="+ignoreIdentifiers);
LOGGER.fine("PLSQLTokenizer: ignoreLiterals=="+ignoreLiterals);
LOGGER.fine("PLSQLTokenizer: ignoreComments==" + ignoreComments);
LOGGER.fine("PLSQLTokenizer: ignoreIdentifiers==" + ignoreIdentifiers);
LOGGER.fine("PLSQLTokenizer: ignoreLiterals==" + ignoreLiterals);
}

String fileName = sourceCode.getFileName();
StringBuilder sb = sourceCode.getCodeBuffer();

PLSQLParserTokenManager tokenMgr = new PLSQLParserTokenManager( new SimpleCharStream( new StringReader(sb.toString())));
Token currentToken = tokenMgr.getNextToken();
while (currentToken.image.length() > 0)
{
String image = currentToken.image;

encounteredTokens++;
if (ignoreComments &&
( currentToken.kind == PLSQLParserConstants.SINGLE_LINE_COMMENT
||currentToken.kind == PLSQLParserConstants.MULTI_LINE_COMMENT
||currentToken.kind == PLSQLParserConstants.FORMAL_COMMENT
||currentToken.kind == PLSQLParserConstants.COMMENT
||currentToken.kind == PLSQLParserConstants.IN_MULTI_LINE_COMMENT
||currentToken.kind == PLSQLParserConstants.IN_FORMAL_COMMENT
)
) {
image = String.valueOf(currentToken.kind);
}

if (ignoreIdentifiers &&
currentToken.kind == PLSQLParserConstants.IDENTIFIER
) {
image = String.valueOf(currentToken.kind);
}

if (ignoreLiterals
&& (
currentToken.kind == PLSQLParserConstants.UNSIGNED_NUMERIC_LITERAL
|| currentToken.kind == PLSQLParserConstants.FLOAT_LITERAL
|| currentToken.kind == PLSQLParserConstants.INTEGER_LITERAL
|| currentToken.kind == PLSQLParserConstants.CHARACTER_LITERAL
|| currentToken.kind == PLSQLParserConstants.STRING_LITERAL
|| currentToken.kind == PLSQLParserConstants.QUOTED_LITERAL
)
) {
image = String.valueOf(currentToken.kind);
}

tokenEntries.add(new TokenEntry(image, fileName, currentToken.beginLine));
addedTokens++;
currentToken = tokenMgr.getNextToken();
}
tokenEntries.add(TokenEntry.getEOF() );
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(sourceCode.getFileName()
+ ": encountered " + encounteredTokens + " tokens;"
+ " added " + addedTokens + " tokens"
);
}
}


String fileName = sourceCode.getFileName();
StringBuilder sb = sourceCode.getCodeBuffer();

PLSQLParserTokenManager tokenMgr = new PLSQLParserTokenManager(
new SimpleCharStream(new StringReader(sb.toString())));
Token currentToken = tokenMgr.getNextToken();
while (currentToken.image.length() > 0) {
String image = currentToken.image;

encounteredTokens++;
if (ignoreComments && (currentToken.kind == PLSQLParserConstants.SINGLE_LINE_COMMENT
|| currentToken.kind == PLSQLParserConstants.MULTI_LINE_COMMENT
|| currentToken.kind == PLSQLParserConstants.FORMAL_COMMENT
|| currentToken.kind == PLSQLParserConstants.COMMENT
|| currentToken.kind == PLSQLParserConstants.IN_MULTI_LINE_COMMENT
|| currentToken.kind == PLSQLParserConstants.IN_FORMAL_COMMENT)) {
image = String.valueOf(currentToken.kind);
}

if (ignoreIdentifiers && currentToken.kind == PLSQLParserConstants.IDENTIFIER) {
image = String.valueOf(currentToken.kind);
}

if (ignoreLiterals && (currentToken.kind == PLSQLParserConstants.UNSIGNED_NUMERIC_LITERAL
|| currentToken.kind == PLSQLParserConstants.FLOAT_LITERAL
|| currentToken.kind == PLSQLParserConstants.INTEGER_LITERAL
|| currentToken.kind == PLSQLParserConstants.CHARACTER_LITERAL
|| currentToken.kind == PLSQLParserConstants.STRING_LITERAL
|| currentToken.kind == PLSQLParserConstants.QUOTED_LITERAL)) {
image = String.valueOf(currentToken.kind);
}

tokenEntries.add(new TokenEntry(image, fileName, currentToken.beginLine));
addedTokens++;
currentToken = tokenMgr.getNextToken();
}
tokenEntries.add(TokenEntry.getEOF());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(sourceCode.getFileName() + ": encountered " + encounteredTokens + " tokens;" + " added "
+ addedTokens + " tokens");
}
}

}


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.plsql;

import java.util.List;
Expand All @@ -13,11 +14,10 @@

public class PLSQLDataFlowHandler implements DataFlowHandler {
public DataFlowNode createDataFlowNode(List<DataFlowNode> dataFlow, Node node) {
return new PLSQLDataFlowNode(dataFlow, node);
return new PLSQLDataFlowNode(dataFlow, node);
}

public Class<ASTLabelledStatement> getLabelStatementNodeClass() {
return ASTLabelledStatement.class;
return ASTLabelledStatement.class;
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.plsql;

import java.io.Writer;
import net.sf.saxon.sxpath.IndependentContext;

import org.jaxen.Navigator;

import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
import net.sourceforge.pmd.lang.DataFlowHandler;
Expand All @@ -23,23 +25,23 @@
import net.sourceforge.pmd.lang.plsql.rule.PLSQLRuleViolationFactory;
import net.sourceforge.pmd.lang.plsql.symboltable.SymbolFacade;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
import org.jaxen.Navigator;

import net.sf.saxon.sxpath.IndependentContext;

/**
* Implementation of LanguageVersionHandler for the PLSQL AST. It uses anonymous classes
* as adapters of the visitors to the VisitorStarter interface.
* Implementation of LanguageVersionHandler for the PLSQL AST. It uses anonymous
* classes as adapters of the visitors to the VisitorStarter interface.
*
* @author sturton - PLDoc - pldoc.sourceforge.net
*/
public class PLSQLHandler extends AbstractLanguageVersionHandler {
public class PLSQLHandler extends AbstractLanguageVersionHandler {


public Parser getParser(ParserOptions parserOptions) {
return new PLSQLParser(parserOptions);
}

public RuleViolationFactory getRuleViolationFactory() {
return PLSQLRuleViolationFactory.INSTANCE;
return PLSQLRuleViolationFactory.INSTANCE;
}

@Override
Expand All @@ -49,52 +51,51 @@ public DFAGraphRule getDFAGraphRule() {

@Override
public DataFlowHandler getDataFlowHandler() {
return new PLSQLDataFlowHandler();
return new PLSQLDataFlowHandler();
}

@Override
public VisitorStarter getDataFlowFacade() {
return new VisitorStarter() {
public void start(Node rootNode) {
new DataFlowFacade().initializeWith(getDataFlowHandler(), (ASTInput) rootNode);
}
};
return new VisitorStarter() {
public void start(Node rootNode) {
new DataFlowFacade().initializeWith(getDataFlowHandler(), (ASTInput) rootNode);
}
};
}

@Override
public VisitorStarter getSymbolFacade() {
return new VisitorStarter() {
public void start(Node rootNode) {
new SymbolFacade().initializeWith((ASTInput) rootNode);
}
};
return new VisitorStarter() {
public void start(Node rootNode) {
new SymbolFacade().initializeWith((ASTInput) 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, (PLSQLNode) rootNode);
}
};
return new VisitorStarter() {
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (PLSQLNode) rootNode);
}
};
}



@Override
/**
* Return minimal XPathHandler to cope with Jaxen XPath Rules.
*/
public XPathHandler getXPathHandler() {
return new XPathHandler() {
public void initialize() {
}
return new XPathHandler() {
public void initialize() {
}

public void initialize(IndependentContext context) {
}
public void initialize(IndependentContext context) {
}

public Navigator getNavigator() {
return new DocumentNavigator();
}
};
public Navigator getNavigator() {
return new DocumentNavigator();
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package net.sourceforge.pmd.lang.plsql;

import net.sourceforge.pmd.lang.BaseLanguageModule;
Expand All @@ -16,10 +17,10 @@ public PLSQLLanguageModule() {
"sql", "trg",
"prc", "fnc",
"pld", // Oracle*Forms
"pls" ,"plh" ,"plb", // Packages
"pck" ,"pks" ,"pkh" ,"pkb", // Packages
"typ" ,"tyb", // Object Types
"tps" ,"tpb" /* Object Types*/);
"pls", "plh", "plb", // Packages
"pck", "pks", "pkh", "pkb", // Packages
"typ", "tyb", // Object Types
"tps", "tpb" /* Object Types */);
addVersion("", new PLSQLHandler(), true);
}

Expand Down
Loading

0 comments on commit 2682bf1

Please sign in to comment.