Refactoring and bugfixes

This commit is contained in:
konsoletyper 2014-08-30 23:29:24 +04:00
parent 1aca1d5a1e
commit b51d8fe452
25 changed files with 193 additions and 48 deletions

View File

@ -27,7 +27,9 @@
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="IllegalThrows"/>
<module name="IllegalThrows">
<property name="illegalClassNames" value="java.lang.Error, java.lang.RuntimeException"/>
</module>
<module name="ExplicitInitialization"/>
<module name="DefaultComesLast"/>
<module name="FallThrough"/>

22
pom.xml
View File

@ -208,6 +208,28 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<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>
</pluginManagement>
</build>

View File

@ -42,6 +42,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>

View File

@ -24,7 +24,10 @@ import org.teavm.tooling.TeaVMTool;
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMRunner {
public final class TeaVMRunner {
private TeaVMRunner() {
}
@SuppressWarnings("static-access")
public static void main(String[] args) {
Options options = new Options();

View File

@ -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();

View File

@ -50,24 +50,10 @@
<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>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -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];

View File

@ -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));

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -43,6 +43,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>

View File

@ -38,6 +38,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>

View File

@ -212,7 +212,7 @@ public final class JS {
return new Iterable<T>() {
@Override public Iterator<T> iterator() {
return new Iterator<T>() {
int index = 0;
int index;
@Override public boolean hasNext() {
return index < array.getLength();
}

View File

@ -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;

View File

@ -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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -9,6 +24,9 @@
</parent>
<artifactId>teavm-platform</artifactId>
<name>TeaVM platform</name>
<description>A low-level classes that help to implement Java class library</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
@ -21,4 +39,24 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);

View File

@ -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.*;

View File

@ -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");

View File

@ -38,6 +38,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>

View File

@ -34,7 +34,10 @@ import org.teavm.jso.JS;
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
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");

View File

@ -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;

View File

@ -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;

View File

@ -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();