dogfood, whitespaces

This commit is contained in:
Andreas Dangel
2015-03-23 22:11:23 +01:00
parent 45a0227f17
commit 056b2fbaea
17 changed files with 759 additions and 753 deletions

View File

@ -380,6 +380,13 @@ public class PMD {
*/
public static List<DataSource> getApplicableFiles(PMDConfiguration configuration, Set<Language> languages) {
long startFiles = System.nanoTime();
List<DataSource> files = internalGetApplicableFiles(configuration, languages);
long endFiles = System.nanoTime();
Benchmarker.mark(Benchmark.CollectFiles, endFiles - startFiles, 0);
return files;
}
private static List<DataSource> internalGetApplicableFiles(PMDConfiguration configuration, Set<Language> languages) {
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(languages);
List<DataSource> files = new ArrayList<DataSource>();
@ -398,8 +405,6 @@ public class PMD {
throw new RuntimeException("Problem with DBURI: " + uriString, ex);
}
}
long endFiles = System.nanoTime();
Benchmarker.mark(Benchmark.CollectFiles, endFiles - startFiles, 0);
return files;
}

View File

@ -309,17 +309,15 @@ public class RuleSet {
Benchmarker.mark(Benchmark.Rule, rule.getName(), end - start, 1);
start = end;
}
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
throw (ThreadDeath)t;
} else if (ctx.isIgnoreExceptions()) {
} catch (RuntimeException e) {
if (ctx.isIgnoreExceptions()) {
if (LOG.isLoggable(Level.WARNING)) {
LOG.log(Level.WARNING, "Exception applying rule " + rule.getName()
+ " on file " + ctx.getSourceCodeFilename() + ", continuing with next rule",
t);
e);
}
} else {
throw new RuntimeException(t);
throw e;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -39,8 +39,6 @@ import org.apache.commons.lang3.StringUtils;
* @version $Id: ASTMethod.java 720228 2008-11-24 16:58:33Z nbubna $
*/
public class ASTMethod extends AbstractVmNode {
private final String methodName = "";
/**
* @param id
*/
@ -139,7 +137,7 @@ public class ASTMethod extends AbstractVmNode {
* @since 1.5
*/
public String getMethodName() {
return methodName;
return "";
}
}

View File

@ -94,8 +94,9 @@ public class ASTReference extends AbstractVmNode {
* do only once
*/
if (this.literal == null)
if (this.literal == null) {
this.literal = literal;
}
}
/**
@ -106,8 +107,9 @@ public class ASTReference extends AbstractVmNode {
*/
@Override
public String literal() {
if (literal != null)
if (literal != null) {
return literal;
}
// this value could be cached in this.literal but it increases memory usage
return super.literal();

View File

@ -28,9 +28,6 @@ import org.apache.commons.lang3.text.StrBuilder;
* @version $Id: ASTStringLiteral.java 705297 2008-10-16 17:59:24Z nbubna $
*/
public class ASTStringLiteral extends AbstractVmNode {
/* cache the value of the interpolation switch */
private final boolean interpolate = true;
/**
* @param id
*/
@ -59,11 +56,13 @@ public class ASTStringLiteral extends AbstractVmNode {
// If tok is on the first line, then the actual column is
// offset by the template column.
if (tok.beginLine == 1)
if (tok.beginLine == 1) {
tok.beginColumn += getColumn();
}
if (tok.endLine == 1)
if (tok.endLine == 1) {
tok.endColumn += getColumn();
}
tok.beginLine += getLine() - 1;
tok.endLine += getLine() - 1;
@ -76,8 +75,9 @@ public class ASTStringLiteral extends AbstractVmNode {
*/
public static String unescape(final String string) {
int u = string.indexOf("\\u");
if (u < 0)
if (u < 0) {
return string;
}
final StrBuilder result = new StrBuilder();
@ -118,7 +118,7 @@ public class ASTStringLiteral extends AbstractVmNode {
* @since 1.6
*/
public boolean isConstant() {
return !interpolate;
return false;
}
}

View File

@ -162,7 +162,7 @@ public class AbstractVmNode extends AbstractNode implements VmNode {
* @param prefix
*/
public void dump(final String prefix, final boolean recurse, final Writer writer) {
final PrintWriter printWriter = (writer instanceof PrintWriter) ? (PrintWriter) writer
final PrintWriter printWriter = writer instanceof PrintWriter ? (PrintWriter) writer
: new PrintWriter(writer);
printWriter.println(toString(prefix));
if (children != null && recurse) {
@ -183,13 +183,13 @@ public class AbstractVmNode extends AbstractNode implements VmNode {
public String literal() {
// if we have only one string, just return it and avoid
// buffer allocation. VELOCITY-606
if (first == last) {
if (first != null && first.equals(last)) {
return NodeUtils.tokenLiteral(first);
}
Token t = first;
final StrBuilder sb = new StrBuilder(NodeUtils.tokenLiteral(t));
while (t != last) {
while (t != null && !t.equals(last)) {
t = t.next;
sb.append(NodeUtils.tokenLiteral(t));
}

View File

@ -66,7 +66,7 @@ public class MacroParseException extends ParseException {
* @since 1.5
*/
public int getLineNumber() {
if ((currentToken != null) && (currentToken.next != null)) {
if (currentToken != null && currentToken.next != null) {
return currentToken.next.beginLine;
}
else if (currentToken != null) {
@ -84,7 +84,7 @@ public class MacroParseException extends ParseException {
* @since 1.5
*/
public int getColumnNumber() {
if ((currentToken != null) && (currentToken.next != null)) {
if (currentToken != null && currentToken.next != null) {
return currentToken.next.beginColumn;
}
else if (currentToken != null) {

View File

@ -42,16 +42,16 @@ public class NodeUtils {
private static StrBuilder getSpecialText(final Token t) {
final StrBuilder sb = new StrBuilder();
Token tmp_t = t.specialToken;
Token tmpToken = t.specialToken;
while (tmp_t.specialToken != null) {
tmp_t = tmp_t.specialToken;
while (tmpToken.specialToken != null) {
tmpToken = tmpToken.specialToken;
}
while (tmp_t != null) {
final String st = tmp_t.image;
while (tmpToken != null) {
final String st = tmpToken.image;
for (int i = 0, is = st.length(); i < is; i++) {
for (int i = 0; i < st.length(); i++) {
final char c = st.charAt(i);
if (c == '#' || c == '$') {
@ -69,7 +69,7 @@ public class NodeUtils {
boolean term = false;
int j = i;
for (ok = true; ok && j < is; j++) {
for (ok = true; ok && j < st.length(); j++) {
final char cc = st.charAt(j);
if (cc == '\\') {
@ -101,7 +101,7 @@ public class NodeUtils {
}
}
tmp_t = tmp_t.next;
tmpToken = tmpToken.next;
}
return sb;
}

View File

@ -109,7 +109,7 @@ public class TemplateParseException extends ParseException {
* @return The line number where this exception occured.
*/
public int getLineNumber() {
if ((currentToken != null) && (currentToken.next != null)) {
if (currentToken != null && currentToken.next != null) {
return currentToken.next.beginLine;
}
else {
@ -123,7 +123,7 @@ public class TemplateParseException extends ParseException {
* @return The column number where this exception occured.
*/
public int getColumnNumber() {
if ((currentToken != null) && (currentToken.next != null)) {
if (currentToken != null && currentToken.next != null) {
return currentToken.next.beginColumn;
}
else {
@ -158,7 +158,7 @@ public class TemplateParseException extends ParseException {
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" ");
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
@ -173,7 +173,7 @@ public class TemplateParseException extends ParseException {
for (int i = 0; i < maxSize; i++) {
if (i != 0) {
retval.append(" ");
retval.append(' ');
}
if (tok.kind == 0) {

View File

@ -2,7 +2,7 @@ package net.sourceforge.pmd.lang.vm.ast;
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
public class TokenMgrError extends Error {
public class TokenMgrError extends RuntimeException {
/*
* Ordinals for various reasons why an Error of this type can be thrown.
*/
@ -46,40 +46,41 @@ public class TokenMgrError extends Error {
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i)) {
case 0:
continue;
break;
case '\b':
retval.append("\\b");
continue;
break;
case '\t':
retval.append("\\t");
continue;
break;
case '\n':
retval.append("\\n");
continue;
break;
case '\f':
retval.append("\\f");
continue;
break;
case '\r':
retval.append("\\r");
continue;
break;
case '\"':
retval.append("\\\"");
continue;
break;
case '\'':
retval.append("\\\'");
continue;
break;
case '\\':
retval.append("\\\\");
continue;
break;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
ch = str.charAt(i);
if (ch < 0x20 || ch > 0x7e) {
final String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
}
else {
retval.append(ch);
}
continue;
break;
}
}
return retval.toString();
@ -103,19 +104,6 @@ public class TokenMgrError extends Error {
+ "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
}
/**
* You can also modify the body of this method to customize your error messages. For example, cases like
* LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
@Override
public String getMessage() {
return super.getMessage();
}
/*
* Constructors of various flavors follow.
*/

View File

@ -26,8 +26,14 @@ package net.sourceforge.pmd.lang.vm.directive;
* @author Nathan Bubna
* @version $Id: Directive.java 778045 2009-05-23 22:17:46Z nbubna $
*/
public abstract class Directive implements DirectiveConstants, Cloneable
public abstract class Directive implements Cloneable
{
/** Block directive indicator */
public static final int BLOCK = 1;
/** Line directive indicator */
public static final int LINE = 2;
private int line = 0;
private int column = 0;
private boolean provideScope = false;

View File

@ -1,35 +0,0 @@
package net.sourceforge.pmd.lang.vm.directive;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Base class for all directives used in Velocity.
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @version $Id: DirectiveConstants.java 463298 2006-10-12 16:10:32Z henning $
*/
public interface DirectiveConstants
{
/** Block directive indicator */
public static final int BLOCK = 1;
/** Line directive indicator */
public static final int LINE = 2;
}

View File

@ -28,5 +28,9 @@ package net.sourceforge.pmd.lang.vm.directive;
*/
public abstract class InputBase extends Directive
{
/**
* Return name of this directive.
* @return The name of this directive.
*/
public abstract String getName();
}

View File

@ -30,8 +30,6 @@ package net.sourceforge.pmd.lang.vm.directive;
public class VelocimacroProxy extends Directive
{
private String macroName;
private String[] argArray = null;
private String[] literalArgArray = null;
private int numMacroArgs = 0;
/**
@ -69,22 +67,11 @@ public class VelocimacroProxy extends Directive
*/
public void setArgArray(String[] arr)
{
argArray = arr;
// for performance reasons we precache these strings - they are needed in
// "render literal if null" functionality
literalArgArray = new String[arr.length];
for(int i = 0; i < arr.length; i++)
{
literalArgArray[i] = ".literal.$" + argArray[i];
}
/*
* get the arg count from the arg array. remember that the arg array has the macro name as
* it's 0th element
*/
numMacroArgs = argArray.length - 1;
numMacroArgs = arr.length - 1;
}
/**

View File

@ -40,7 +40,7 @@ import net.sourceforge.pmd.lang.ast.CharStream;
public final class VelocityCharStream
implements CharStream
{
public static final boolean staticFlag = false;
public static final boolean STATIC_FLAG = false;
int bufsize;
private int nextBufExpand;
int available;
@ -62,7 +62,7 @@ implements CharStream
private int maxNextCharInd = 0;
private int inBuf = 0;
private final void ExpandBuff(boolean wrapAround)
private void ExpandBuff(boolean wrapAround)
{
char[] newbuffer = new char[bufsize + nextBufExpand];
int newbufline[] = new int[bufsize + nextBufExpand];
@ -85,7 +85,7 @@ implements CharStream
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;
maxNextCharInd = (bufpos += (bufsize - tokenBegin));
maxNextCharInd = (bufpos += bufsize - tokenBegin);
}
else
{
@ -113,7 +113,7 @@ implements CharStream
tokenBegin = 0;
}
private final void FillBuff() throws java.io.IOException
private void FillBuff() throws java.io.IOException
{
if (maxNextCharInd == available)
{
@ -150,8 +150,8 @@ implements CharStream
int i;
try
{
if ((i = inputStream.read(buffer, maxNextCharInd,
available - maxNextCharInd)) == -1)
i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd);
if (i == -1)
{
inputStream.close();
throw new java.io.IOException();
@ -177,7 +177,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#BeginToken()
*/
public final char BeginToken() throws java.io.IOException
public char BeginToken() throws java.io.IOException
{
tokenBegin = -1;
char c = readChar();
@ -186,7 +186,7 @@ implements CharStream
return c;
}
private final void UpdateLineColumn(char c)
private void UpdateLineColumn(char c)
{
column++;
@ -218,7 +218,7 @@ implements CharStream
break;
case '\t' :
column--;
column += (8 - (column & 07));
column += 8 - (column & 07);
break;
default :
break;
@ -231,7 +231,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#readChar()
*/
public final char readChar() throws java.io.IOException
public char readChar() throws java.io.IOException
{
if (inBuf > 0)
{
@ -243,7 +243,8 @@ implements CharStream
return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
}
if (++bufpos >= maxNextCharInd)
bufpos++;
if (bufpos >= maxNextCharInd)
{
FillBuff();
}
@ -254,14 +255,14 @@ implements CharStream
char c = buffer[bufpos];
UpdateLineColumn(c);
return (c);
return c;
}
/**
* @see org.apache.velocity.runtime.parser.CharStream#getColumn()
* @deprecated
*/
public final int getColumn()
public int getColumn()
{
return bufcolumn[bufpos];
}
@ -270,7 +271,7 @@ implements CharStream
* @see org.apache.velocity.runtime.parser.CharStream#getLine()
* @deprecated
*/
public final int getLine()
public int getLine()
{
return bufline[bufpos];
}
@ -278,7 +279,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#getEndColumn()
*/
public final int getEndColumn()
public int getEndColumn()
{
return bufcolumn[bufpos];
}
@ -286,7 +287,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#getEndLine()
*/
public final int getEndLine()
public int getEndLine()
{
return bufline[bufpos];
}
@ -294,7 +295,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#getBeginColumn()
*/
public final int getBeginColumn()
public int getBeginColumn()
{
return bufcolumn[tokenBegin];
}
@ -302,7 +303,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#getBeginLine()
*/
public final int getBeginLine()
public int getBeginLine()
{
return bufline[tokenBegin];
}
@ -310,12 +311,14 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#backup(int)
*/
public final void backup(int amount)
public void backup(int amount)
{
inBuf += amount;
if ((bufpos -= amount) < 0)
bufpos -= amount;
if (bufpos < 0) {
bufpos += bufsize;
}
}
/**
@ -429,7 +432,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#GetImage()
*/
public final String GetImage()
public String GetImage()
{
if (bufpos >= tokenBegin)
{
@ -445,7 +448,7 @@ implements CharStream
/**
* @see org.apache.velocity.runtime.parser.CharStream#GetSuffix(int)
*/
public final char[] GetSuffix(int len)
public char[] GetSuffix(int len)
{
char[] ret = new char[len];
@ -492,8 +495,11 @@ implements CharStream
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}
int i = 0, j = 0, k = 0;
int nextColDiff = 0, columnDiff = 0;
int i = 0;
int j = 0;
int k = 0;
int nextColDiff = 0;
int columnDiff = 0;
while (i < len &&
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
@ -512,10 +518,13 @@ implements CharStream
while (i++ < len)
{
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
j = start % bufsize;
start++;
if (bufline[j] != bufline[start % bufsize]) {
bufline[j] = newLine++;
else
} else {
bufline[j] = newLine;
}
}
}

View File

@ -11,8 +11,6 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Entity;
import org.w3c.dom.EntityReference;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;