Adds checkstyle and findbugs into configuration of teavm-core

This commit is contained in:
konsoletyper 2014-03-05 12:54:26 +04:00
parent 226f4c2c8a
commit d714e880d3
31 changed files with 212 additions and 228 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/.directory
/.project
/.settings
.checkstyle

87
teavm-core/checkstyle.xml Normal file
View File

@ -0,0 +1,87 @@
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="AnnotationUseStyle"/>
<module name="MissingOverride">
<property name="javaFiveCompatibility" value="true"/>
</module>
<module name="EmptyBlock">
<property name="option" value="text"/>
<property name="tokens" value="LITERAL_CATCH"/>
</module>
<module name="EmptyBlock">
<property name="tokens" value="LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT"/>
</module>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="HideUtilityClassConstructor"/>
<module name="MutableException"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="InnerAssignment"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="IllegalThrows"/>
<module name="ExplicitInitialization"/>
<module name="DefaultComesLast"/>
<module name="FallThrough"/>
<module name="MultipleVariableDeclarations"/>
<module name="UnnecessaryParentheses"/>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<module name="ImportOrder">
<property name="option" value="top"/>
</module>
<module name="UpperEll"/>
<module name="ArrayTypeStyle"/>
<module name="TrailingComment"/>
<module name="RedundantModifier"/>
<module name="ClassTypeParameterName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="MethodTypeParameterName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="GenericWhitespace"/>
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS,TYPECAST"/>
</module>
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true"/>
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS,TYPECAST"/>
</module>
<module name="OperatorWrap">
<property name="option" value="eol"/>
</module>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA,SEMI"/>
</module>
</module>
<module name="RegexpHeader">
<property name="headerFile" value="${config_loc}/license-regexp.txt"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="FileTabCharacter">
<property name="fileExtensions" value="java"/>
</module>
</module>

View File

@ -0,0 +1,15 @@
/\*
\* Copyright 2[0-9]{3} .+
\*
\* Licensed 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.
\*/

View File

@ -42,4 +42,41 @@
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.11</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<propertyExpansion>config_loc=${basedir}</propertyExpansion>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -87,12 +87,13 @@ public class DefaultNamingStrategy implements NamingStrategy {
@Override
public String getFullNameFor(MethodReference method) throws NamingException {
MethodReference originalMethod = method;
if (!minifying) {
return getNameFor(method.getClassName()) + "_" + getNameFor(method);
}
method = getRealMethod(method);
if (method == null) {
throw new NamingException("Can't provide name for method as it was not found: " + method);
throw new NamingException("Can't provide name for method as it was not found: " + originalMethod);
}
String key = method.toString();
String alias = privateAliases.get(key);

View File

@ -27,7 +27,7 @@ import org.teavm.model.ValueType;
*/
public class SourceWriter implements Appendable {
private Appendable innerWriter;
private int indentSize = 0;
private int indentSize;
private NamingStrategy naming;
private boolean lineStart;
private boolean minified;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2013 Alexey Andreev.
*
* Licensed 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.
*/
package org.teavm.common;
import java.util.ArrayList;
@ -71,7 +86,7 @@ public class ConcurrentCachedMapper<T, R> implements Mapper<T, R> {
keyListeners.add(listener);
}
public static interface KeyListener<S> {
public interface KeyListener<S> {
void keyAdded(S key);
}
}

View File

@ -26,7 +26,7 @@ public class DisjointSet {
private int[] rank = new int[16];
private int[] setSize = new int[16];
private int maxRank;
private int size = 0;
private int size;
public int find(int node) {
int initial = node;

View File

@ -27,7 +27,7 @@ import java.util.List;
public class GraphBuilder {
private GraphImpl builtGraph;
private List<IntegerArray> addedEdges = new ArrayList<>();
private int sz = 0;
private int sz;
public GraphBuilder() {
}

View File

@ -23,6 +23,9 @@ import java.util.Comparator;
* @author Alexey Andreev
*/
public class GraphIndexer {
static final byte NONE = 0;
static final byte VISITING = 1;
static final byte VISITED = 2;
private int[] indexToNode;
private int[] nodeToIndex;
private Graph graph;
@ -37,9 +40,6 @@ public class GraphIndexer {
}
private int sort(Graph graph) {
final byte NONE = 0;
final byte VISITING = 1;
final byte VISITED = 2;
LoopGraph loopGraph = new LoopGraph(graph);
int sz = graph.size();
int[] indexToNode = new int[sz + 1];
@ -89,6 +89,8 @@ public class GraphIndexer {
case NONE:
stack[stackSize++] = next;
break;
default:
break;
}
}
break;

View File

@ -22,7 +22,14 @@ import java.util.Arrays;
*
* @author Alexey Andreev
*/
public class GraphUtils {
public final class GraphUtils {
static final byte NONE = 0;
static final byte VISITING = 1;
static final byte VISITED = 2;
private GraphUtils() {
}
public static Graph invert(Graph graph) {
int sz = graph.size();
GraphBuilder result = new GraphBuilder();
@ -52,9 +59,6 @@ public class GraphUtils {
}
public static Graph removeLoops(Graph graph) {
final byte NONE = 0;
final byte VISITING = 1;
final byte VISITED = 2;
int sz = graph.size();
GraphBuilder result = new GraphBuilder();
int[] stack = new int[sz * 2];

View File

@ -1,99 +0,0 @@
/*
* Copyright 2013 Alexey Andreev.
*
* Licensed 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.
*/
package org.teavm.common;
import java.util.Arrays;
/**
*
* @author Alexey Andreev
*/
public class GraphWithIndexedEdges implements Graph {
private int[][] incoming;
private int[][] outgoing;
private int[][] edgeIndex;
public GraphWithIndexedEdges(Graph graph) {
incoming = new int[graph.size()][];
outgoing = new int[graph.size()][];
edgeIndex = new int[graph.size()][];
for (int i = 0; i < graph.size(); ++i) {
outgoing[i] = graph.outgoingEdges(i);
incoming[i] = new int[graph.incomingEdgesCount(i)];
edgeIndex[i] = new int[graph.outgoingEdgesCount(i)];
}
int[] lastIncoming = new int[graph.size()];
for (int i = 0; i < graph.size(); ++i) {
int[] localOutgoing = outgoing[i];
int[] localEdgeIndex = edgeIndex[i];
for (int j = 0; j < localOutgoing.length; ++j) {
int target = localOutgoing[j];
int index = lastIncoming[target]++;
incoming[target][index] = i;
localEdgeIndex[j] = index;
}
}
}
@Override
public int size() {
return incoming.length;
}
@Override
public int[] incomingEdges(int node) {
int[] edges = incoming[node];
return Arrays.copyOf(edges, edges.length);
}
@Override
public int copyIncomingEdges(int node, int[] target) {
int[] edges = incoming[node];
System.arraycopy(edges, 0, target, 0, edges.length);
return edges.length;
}
@Override
public int[] outgoingEdges(int node) {
int[] edges = outgoing[node];
return Arrays.copyOf(edges, edges.length);
}
@Override
public int copyOutgoingEdges(int node, int[] target) {
int[] edges = outgoing[node];
System.arraycopy(edges, 0, target, 0, edges.length);
return edges.length;
}
@Override
public int incomingEdgesCount(int node) {
return incoming[node].length;
}
@Override
public int outgoingEdgesCount(int node) {
return outgoing[node].length;
}
/**
* For given edge, identified by source node and index in source node edge array,
* returns index in target node edge array. Works in constant time.
*/
public int getEdgeIndex(int sourceNode, int sourceEdgeIndex) {
return edgeIndex[sourceNode][sourceEdgeIndex];
}
}

View File

@ -37,7 +37,7 @@ public class RangeTree {
}
}
public static interface Node {
public interface Node {
Node getParent();
int getStart();

View File

@ -410,11 +410,12 @@ public class DependencyChecker implements DependencyInfo {
DependencyStack stack = stackMap.get(item);
if (stack == null) {
sb.append(" at unknown location\n");
}
} else {
while (stack.getMethod() != null) {
sb.append(" at " + stack.getMethod() + "\n");
stack = stack.getCause();
}
}
sb.append('\n');
}
}

View File

@ -414,7 +414,7 @@ class DependencyGraphBuilder {
public void invoke(VariableReader receiver, VariableReader instance, MethodReference method,
List<? extends VariableReader> arguments, InvocationType type) {
if (instance == null) {
invokeSpecial(receiver, instance, method, arguments);
invokeSpecial(receiver, null, method, arguments);
} else {
switch (type) {
case SPECIAL:

View File

@ -55,7 +55,7 @@ public class Decompiler {
return this.graph.size();
}
class Block {
static class Block {
public final IdentifiedStatement statement;
public final List<Statement> body;
public final int end;

View File

@ -21,7 +21,10 @@ import org.teavm.javascript.ast.*;
*
* @author Alexey Andreev
*/
class ExprOptimizer {
final class ExprOptimizer {
private ExprOptimizer() {
}
public static Expr invert(Expr expr) {
if (expr instanceof UnaryExpr) {
UnaryExpr unary = (UnaryExpr)expr;

View File

@ -1,94 +0,0 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed 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.
*/
package org.teavm.javascript;
import java.util.ArrayList;
import java.util.List;
import org.teavm.model.*;
import org.teavm.model.util.InstructionTransitionExtractor;
import org.teavm.model.util.UsageExtractor;
/**
*
* @author Alexey Andreev
*/
class PhiEliminator {
public static void eliminatePhis(Program program) {
// Count how many times each variable is used
int[] variableUsageCount = new int[program.variableCount()];
int[] definitionRenamings = new int[program.variableCount()];
for (int i = 0; i < definitionRenamings.length; ++i) {
definitionRenamings[i] = i;
}
UsageExtractor usageExtractor = new UsageExtractor();
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
int blockCount = program.basicBlockCount();
for (int i = 0; i < blockCount; ++i) {
BasicBlock block = program.basicBlockAt(i);
for (Instruction insn : block.getInstructions()) {
insn.acceptVisitor(usageExtractor);
for (Variable var : usageExtractor.getUsedVariables()) {
variableUsageCount[var.getIndex()]++;
}
}
for (Phi phi : block.getPhis()) {
for (Incoming incoming : phi.getIncomings()) {
variableUsageCount[incoming.getValue().getIndex()]++;
}
}
}
// Places assignments at the end of each block
for (int i = 0; i < blockCount; ++i) {
BasicBlock block = program.basicBlockAt(i);
block.getLastInstruction().acceptVisitor(transitionExtractor);
BasicBlock[] targets = transitionExtractor.getTargets();
if (targets.length == 1) {
} else {
for (BasicBlock targetBlock : transitionExtractor.getTargets()) {
List<Incoming> incomings = new ArrayList<>();
for (Incoming incoming : getIncomings(block, targetBlock)) {
if (variableUsageCount[incoming.getSource().getIndex()] <= 1) {
definitionRenamings[incoming.getValue().getIndex()] =
incoming.getPhi().getReceiver().getIndex();
} else {
incomings.add(incoming);
}
}
}
}
}
// Removes phi functions
for (int i = 0; i < blockCount; ++i) {
BasicBlock block = program.basicBlockAt(i);
block.getPhis().clear();
}
}
private static List<Incoming> getIncomings(BasicBlock block, BasicBlock targetBlock) {
List<Incoming> incomings = new ArrayList<>();
for (Phi phi : targetBlock.getPhis()) {
for (Incoming incoming : phi.getIncomings()) {
if (incoming.getSource() == block) {
incomings.add(incoming);
}
}
}
return incomings;
}
}

View File

@ -396,7 +396,7 @@ class StatementGenerator implements InstructionVisitor {
Map<Integer, List<Integer>> switchMap = new HashMap<>();
for (int i = 0; i < insn.getEntries().size(); ++i) {
SwitchTableEntry entry = insn.getEntries().get(i);
List<Integer> conditions = switchMap.get(entry.getTarget());
List<Integer> conditions = switchMap.get(entry.getTarget().getIndex());
if (conditions == null) {
conditions = new ArrayList<>();
switchMap.put(entry.getTarget().getIndex(), conditions);

View File

@ -41,7 +41,7 @@ public class DefinitionExtractor implements InstructionVisitor {
@Override
public void visit(NullConstantInstruction insn) {
definedVariables = new Variable[] { insn.getReceiver() };
definedVariables = new Variable[] {insn.getReceiver()};
}
@Override

View File

@ -24,7 +24,10 @@ import org.teavm.model.instructions.*;
*
* @author Alexey Andreev
*/
public class ProgramUtils {
public final class ProgramUtils {
private ProgramUtils() {
}
public static Graph buildControlFlowGraphWithoutTryCatch(Program program) {
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();

View File

@ -161,9 +161,8 @@ public class RegisterAllocator {
if (!interfere) {
int newClass = congruenceClasses.union(copyClass, origClass);
block.getInstructions().set(j, new EmptyInstruction());
MutableGraphNode newNode = interferenceGraph.get(origClass);
if (newClass == interferenceGraph.size()) {
newNode = new MutableGraphNode(interferenceGraph.size());
MutableGraphNode newNode = new MutableGraphNode(interferenceGraph.size());
interferenceGraph.add(newNode);
}
for (MutableGraphEdge edge : interferenceGraph.get(origClass).getEdges()

View File

@ -117,7 +117,7 @@ public class CommonSubexpressionElimination implements MethodOptimization {
}
program.pack();
program = null;
this.program = null;
}
private List<List<Incoming>> findOutgoings(Program program) {

View File

@ -73,7 +73,7 @@ public class UnusedVariableElimination implements MethodOptimization {
}
}
private class InstructionOptimizer implements InstructionVisitor {
private static class InstructionOptimizer implements InstructionVisitor {
private boolean[] used;
boolean eliminate;

View File

@ -25,7 +25,10 @@ import org.teavm.model.instructions.*;
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class VariableEscapeAnalyzer {
public final class VariableEscapeAnalyzer {
private VariableEscapeAnalyzer() {
}
public static boolean[] findEscapingVariables(Program program) {
boolean[] escaping = new boolean[program.variableCount()];
InstructionAnalyzer analyzer = new InstructionAnalyzer(escaping);

View File

@ -24,7 +24,10 @@ import org.teavm.model.instructions.*;
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class VariableUsageGraphBuilder {
public final class VariableUsageGraphBuilder {
private VariableUsageGraphBuilder() {
}
public static Graph build(Program program) {
GraphBuilder builder = new GraphBuilder(program.variableCount());
InstructionAnalyzer analyzer = new InstructionAnalyzer(builder);

View File

@ -28,8 +28,8 @@ import org.teavm.model.ClassHolder;
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class ClasspathResourceMapper implements Mapper<String, ClassHolder> {
private static String PACKAGE_PREFIX = "packagePrefix.";
private static String CLASS_PREFIX = "classPrefix.";
private static final String PACKAGE_PREFIX = "packagePrefix.";
private static final String CLASS_PREFIX = "classPrefix.";
private Mapper<String, ClassHolder> innerMapper;
private List<Transformation> transformations = new ArrayList<>();
private ClassRefsRenamer renamer;

View File

@ -27,7 +27,10 @@ import org.teavm.optimization.UnreachableBasicBlockEliminator;
*
* @author Alexey Andreev
*/
public class Parser {
public final class Parser {
private Parser() {
}
public static MethodHolder parseMethod(MethodNode node, String className) {
ValueType[] signature = MethodDescriptor.parseSignature(node.desc);
MethodHolder method = new MethodHolder(node.name, signature);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Alexey Andreev.
* Copyright 2011 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -199,7 +199,7 @@ public class TeaVM implements TeaVMHost {
if (bytecodeLogging) {
try {
logBytecode(new PrintWriter(new OutputStreamWriter(logStream, "UTF-8")), classSet);
} catch (IOException e) {
} catch (UnsupportedEncodingException e) {
// Just don't do anything
}
}

View File

@ -19,6 +19,6 @@ package org.teavm.html4j.test;
*
* @author Alexey Andreev
*/
interface A {
public interface A {
int foo();
}