diff --git a/teavm-core/checkstyle.xml b/checkstyle.xml similarity index 95% rename from teavm-core/checkstyle.xml rename to checkstyle.xml index ada1c9ec6..f09602312 100644 --- a/teavm-core/checkstyle.xml +++ b/checkstyle.xml @@ -27,7 +27,9 @@ - + + + diff --git a/teavm-core/license-regexp.txt b/license-regexp.txt similarity index 100% rename from teavm-core/license-regexp.txt rename to license-regexp.txt diff --git a/pom.xml b/pom.xml index 95f370fc7..c5ac77314 100644 --- a/pom.xml +++ b/pom.xml @@ -208,6 +208,28 @@ maven-surefire-plugin 2.17 + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.11 + + + validate + validate + + config_loc=${basedir}/.. + ../checkstyle.xml + UTF-8 + true + true + false + + + check + + + + diff --git a/teavm-cli/pom.xml b/teavm-cli/pom.xml index cca0a2556..e3a7460a5 100644 --- a/teavm-cli/pom.xml +++ b/teavm-cli/pom.xml @@ -42,6 +42,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../checkstyle.xml + + org.apache.maven.plugins maven-source-plugin diff --git a/teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java b/teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java index b8b205a3d..95da2b399 100644 --- a/teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java +++ b/teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java @@ -24,7 +24,10 @@ import org.teavm.tooling.TeaVMTool; * * @author Alexey Andreev */ -public class TeaVMRunner { +public final class TeaVMRunner { + private TeaVMRunner() { + } + @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); diff --git a/teavm-cli/src/main/java/org/teavm/cli/TeaVMTestRunner.java b/teavm-cli/src/main/java/org/teavm/cli/TeaVMTestRunner.java index 988d18858..8d4f627d0 100644 --- a/teavm-cli/src/main/java/org/teavm/cli/TeaVMTestRunner.java +++ b/teavm-cli/src/main/java/org/teavm/cli/TeaVMTestRunner.java @@ -1,3 +1,18 @@ +/* + * 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.cli; import java.io.File; @@ -14,7 +29,10 @@ import org.teavm.tooling.TeaVMToolException; * * @author Alexey Andreev */ -public class TeaVMTestRunner { +public final class TeaVMTestRunner { + private TeaVMTestRunner() { + } + @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); diff --git a/teavm-core/pom.xml b/teavm-core/pom.xml index 70d4e0d2b..6a81a5c88 100644 --- a/teavm-core/pom.xml +++ b/teavm-core/pom.xml @@ -50,24 +50,10 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.11 - - - validate - validate - - config_loc=${basedir} - checkstyle.xml - UTF-8 - true - true - false - - - check - - - + + config_loc=${basedir} + ../checkstyle.xml + org.apache.maven.plugins diff --git a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java index f7a210be3..b2e344ced 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java @@ -208,7 +208,20 @@ public class DebugInformation { if (mapping == null) { return new String[0]; } - return componentSetByKey(mapping, variableNames, location); + int keyIndex = indexByKey(mapping, location); + if (keyIndex < 0) { + return new String[0]; + } + GeneratedLocation keyLocation = key(mapping.get(keyIndex)); + if (!Objects.equals(getMethodAt(keyLocation), getMethodAt(location))) { + return new String[0]; + } + int[] valueIndexes = mapping.get(keyIndex).getArray(0); + String[] result = new String[valueIndexes.length]; + for (int i = 0; i < result.length; ++i) { + result[i] = variableNames[valueIndexes[i]]; + } + return result; } public SourceLocation[] getFollowingLines(SourceLocation location) { @@ -349,19 +362,6 @@ public class DebugInformation { return valueIndex >= 0 ? values[valueIndex] : null; } - private String[] componentSetByKey(RecordArray mapping, String[] values, GeneratedLocation location) { - int keyIndex = indexByKey(mapping, location); - if (keyIndex < 0) { - return new String[0]; - } - int[] valueIndexes = mapping.get(keyIndex).getArray(0); - String[] result = new String[valueIndexes.length]; - for (int i = 0; i < result.length; ++i) { - result[i] = values[valueIndexes[i]]; - } - return result; - } - private int indexByKey(RecordArray mapping, GeneratedLocation location) { int index = Collections.binarySearch(new LocationList(mapping), location); return index >= 0 ? index : -index - 2; @@ -509,7 +509,7 @@ public class DebugInformation { ClassMetadata superclsData = classesMetadata.get(clsData.parentId); Integer parentId = clsData.parentId; while (superclsData != null) { - if (Arrays.binarySearch(superclsData.methods, methodIndex) >= 0) { + if (superclsData.methods != null && Arrays.binarySearch(superclsData.methods, methodIndex) >= 0) { int childMethod = getExactMethodIndex(i, methodIndex); int parentMethod = getExactMethodIndex(parentId, methodIndex); int ptr = start[parentMethod]; diff --git a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java index 0d125f4aa..c43d0835a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java @@ -226,6 +226,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter { for (int i = 0; i < builder.size(); ++i) { RecordArrayBuilder.Record record = builder.get(i); if (i == 0 || lastValue != record.get(2)) { + lastValue = record.get(2); RecordArrayBuilder.Record compressedRecord = compressed.add(); for (int j = 0; j < builder.getRecordSize(); ++j) { compressedRecord.set(j, record.get(j)); diff --git a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java index 084f41582..5610cfaa5 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java @@ -115,8 +115,8 @@ class DebugInformationReader { for (int sz : sizes) { totalSize += sz; } - int files[] = readRle(totalSize); - int lines[] = readRle(totalSize); + int[] files = readRle(totalSize); + int[] lines = readRle(totalSize); int lastFile = 0; int lastLine = 0; int index = 0; @@ -150,7 +150,7 @@ class DebugInformationReader { RecordArrayBuilder.SubArray array = builder.get(i).getArray(0); int last = 0; for (int j = 0; j < count; ++j) { - last += readUnsignedNumber(); + last += readNumber(); array.add(last); } } diff --git a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java index cffc1c58c..7f840a5a3 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java @@ -119,11 +119,11 @@ class DebugInformationWriter { private void writeMultiMapping(RecordArray mapping) throws IOException { writeLinesAndColumns(mapping); for (int i = 0; i < mapping.size(); ++i) { - int[] array = mapping.get(0).getArray(0); + int[] array = mapping.get(i).getArray(0); writeUnsignedNumber(array.length); int lastNumber = 0; for (int elem : array) { - writeUnsignedNumber(elem - lastNumber); + writeNumber(elem - lastNumber); lastNumber = elem; } } diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index 993396ddd..fc2ec8aa9 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -250,6 +250,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext try { writer.append("function ").appendClass(cls.getName()).append("()").ws().append("{") .indent().softNewLine(); + if (cls.getParentName() != null) { + writer.appendClass(cls.getParentName()).append(".call(this);").softNewLine(); + } for (FieldNode field : cls.getFields()) { if (field.getModifiers().contains(NodeModifier.STATIC)) { continue; diff --git a/teavm-dom/pom.xml b/teavm-dom/pom.xml index 58a2d8596..1970229e3 100644 --- a/teavm-dom/pom.xml +++ b/teavm-dom/pom.xml @@ -43,6 +43,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../checkstyle.xml + + org.apache.maven.plugins maven-source-plugin diff --git a/teavm-jso/pom.xml b/teavm-jso/pom.xml index 7cebb7bab..ec7159c83 100644 --- a/teavm-jso/pom.xml +++ b/teavm-jso/pom.xml @@ -38,6 +38,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../checkstyle.xml + + org.apache.maven.plugins maven-source-plugin diff --git a/teavm-jso/src/main/java/org/teavm/jso/JS.java b/teavm-jso/src/main/java/org/teavm/jso/JS.java index 693200466..3a500c537 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JS.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JS.java @@ -212,7 +212,7 @@ public final class JS { return new Iterable() { @Override public Iterator iterator() { return new Iterator() { - int index = 0; + int index; @Override public boolean hasNext() { return index < array.getLength(); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSConstructor.java b/teavm-jso/src/main/java/org/teavm/jso/JSConstructor.java index 256c685dd..3e5cf7240 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSConstructor.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSConstructor.java @@ -1,3 +1,18 @@ +/* + * 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.jso; import java.lang.annotation.ElementType; diff --git a/teavm-platform/pom.xml b/teavm-platform/pom.xml index a4fd22179..3d07e1d73 100644 --- a/teavm-platform/pom.xml +++ b/teavm-platform/pom.xml @@ -1,3 +1,18 @@ + 4.0.0 @@ -9,6 +24,9 @@ teavm-platform + TeaVM platform + A low-level classes that help to implement Java class library + org.teavm @@ -21,4 +39,24 @@ test + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../checkstyle.xml + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + \ No newline at end of file diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceAccessor.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceAccessor.java index 22cbff38e..04f176913 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceAccessor.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceAccessor.java @@ -22,6 +22,9 @@ import org.teavm.platform.metadata.Resource; * @author Alexey Andreev */ final class ResourceAccessor { + private ResourceAccessor() { + } + public static native Object getProperty(Object obj, String propertyName); public static native Resource get(Object obj, String propertyName); diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java index 6d71fb628..f075ef597 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java @@ -1,3 +1,18 @@ +/* + * 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.platform.plugin; import java.util.*; diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceWriterHelper.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceWriterHelper.java index b263a3f24..af816217f 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceWriterHelper.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceWriterHelper.java @@ -23,6 +23,9 @@ import org.teavm.codegen.SourceWriter; * @author Alexey Andreev */ final class ResourceWriterHelper { + private ResourceWriterHelper() { + } + public static void write(SourceWriter writer, Object resource) throws IOException { if (resource == null) { writer.append("null"); diff --git a/teavm-samples/pom.xml b/teavm-samples/pom.xml index 37fd07637..351a7c08d 100644 --- a/teavm-samples/pom.xml +++ b/teavm-samples/pom.xml @@ -38,6 +38,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../checkstyle.xml + + org.teavm teavm-maven-plugin diff --git a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java index 00bdce3d6..daf5b64c5 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java +++ b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java @@ -34,7 +34,10 @@ import org.teavm.jso.JS; * * @author Alexey Andreev */ -public class DateTime { +public final class DateTime { + private DateTime() { + } + private static Window window = (Window)JS.getGlobal(); private static HTMLDocument document = window.getDocument(); private static HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale"); diff --git a/teavm-samples/src/main/java/org/teavm/samples/HelloWorld.java b/teavm-samples/src/main/java/org/teavm/samples/HelloWorld.java index fea65aa24..c8255a95b 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/HelloWorld.java +++ b/teavm-samples/src/main/java/org/teavm/samples/HelloWorld.java @@ -23,12 +23,14 @@ import org.teavm.dom.events.EventListener; import org.teavm.dom.events.EventTarget; import org.teavm.jso.JS; - /** * * @author Alexey Andreev */ -public class HelloWorld { +public final class HelloWorld { + private HelloWorld() { + } + private static Window window; private static Document document; private static Element body; diff --git a/teavm-samples/src/main/java/org/teavm/samples/Matrix.java b/teavm-samples/src/main/java/org/teavm/samples/Matrix.java index 650baca5e..daf7db9fc 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/Matrix.java +++ b/teavm-samples/src/main/java/org/teavm/samples/Matrix.java @@ -42,7 +42,7 @@ import java.util.Arrays; */ public class Matrix { private final int rank; - private final float data[][]; + private final float[][] data; public Matrix(int r) { this(r, new float[r][r]); @@ -75,7 +75,7 @@ public class Matrix { throw new IllegalArgumentException("Rank doesn't match"); } - final float res[][] = new float[rank][rank]; + final float[][] res = new float[rank][rank]; for (int i = 0; i < rank; i++) { for (int j = 0; j < rank; j++) { float ij = 0; diff --git a/teavm-samples/src/main/java/org/teavm/samples/MatrixMultiplication.java b/teavm-samples/src/main/java/org/teavm/samples/MatrixMultiplication.java index c6734114c..a2445bd6f 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/MatrixMultiplication.java +++ b/teavm-samples/src/main/java/org/teavm/samples/MatrixMultiplication.java @@ -21,7 +21,10 @@ import java.io.IOException; * * @author Alexey Andreev */ -public class MatrixMultiplication { +public final class MatrixMultiplication { + private MatrixMultiplication() { + } + public static void main(String[] args) throws IOException { for (int k = 0; k < 20; ++k) { long startTime = System.currentTimeMillis();