Fix bugs in metaprogramming. Add run configuration that rebuilds TeaVM

This commit is contained in:
Alexey Andreev 2017-02-04 18:24:23 +03:00
parent 751587bddc
commit 5e44c13caf
4 changed files with 62 additions and 22 deletions

View File

@ -0,0 +1,28 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-teavm-fast" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="install" />
<option value="-DskipTests" />
<option value="-Dteavm.build.all=false" />
</list>
</option>
<option name="profilesMap">
<map />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method />
</configuration>
</component>

View File

@ -15,7 +15,6 @@
*/
package org.teavm.metaprogramming;
import java.util.Arrays;
import org.teavm.metaprogramming.reflect.ReflectAnnotatedElement;
import org.teavm.metaprogramming.reflect.ReflectField;
import org.teavm.metaprogramming.reflect.ReflectMethod;
@ -49,15 +48,9 @@ public interface ReflectClass<T> extends ReflectAnnotatedElement {
<U> ReflectClass<U> asSubclass(Class<U> cls);
default boolean isAssignableFrom(ReflectClass<?> cls) {
return cls == this
|| cls.getSuperclass() != null && this.isAssignableFrom(cls.getSuperclass())
|| Arrays.stream(cls.getInterfaces()).anyMatch(this::isAssignableFrom);
}
boolean isAssignableFrom(ReflectClass<?> cls);
default boolean isAssignableFrom(Class<?> cls) {
return isAssignableFrom(Metaprogramming.findClass(cls));
}
boolean isAssignableFrom(Class<?> cls);
ReflectMethod[] getDeclaredMethods();
@ -65,21 +58,11 @@ public interface ReflectClass<T> extends ReflectAnnotatedElement {
ReflectMethod getDeclaredMethod(String name, ReflectClass<?>... parameterTypes);
default ReflectMethod getDeclaredJMethod(String name, Class<?>... parameterTypes) {
ReflectClass<?>[] mappedParamTypes = Arrays.stream(parameterTypes)
.map(Metaprogramming::findClass)
.toArray(ReflectClass[]::new);
return getDeclaredMethod(name, mappedParamTypes);
}
ReflectMethod getDeclaredJMethod(String name, Class<?>... parameterTypes);
ReflectMethod getMethod(String name, ReflectClass<?>... parameterTypes);
default ReflectMethod getJMethod(String name, Class<?>... parameterTypes) {
ReflectClass<?>[] mappedParamTypes = Arrays.stream(parameterTypes)
.map(Metaprogramming::findClass)
.toArray(ReflectClass[]::new);
return getMethod(name, mappedParamTypes);
}
ReflectMethod getJMethod(String name, Class<?>... parameterTypes);
ReflectField[] getDeclaredFields();

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.teavm.metaprogramming.ReflectClass;
import org.teavm.metaprogramming.impl.MetaprogrammingImpl;
import org.teavm.metaprogramming.reflect.ReflectField;
import org.teavm.metaprogramming.reflect.ReflectMethod;
import org.teavm.model.AccessLevel;
@ -197,6 +198,18 @@ public class ReflectClassImpl<T> implements ReflectClass<T> {
return (ReflectClass<U>) this;
}
@Override
public boolean isAssignableFrom(ReflectClass<?> cls) {
return cls == this
|| cls.getSuperclass() != null && this.isAssignableFrom(cls.getSuperclass())
|| Arrays.stream(cls.getInterfaces()).anyMatch(this::isAssignableFrom);
}
@Override
public boolean isAssignableFrom(Class<?> cls) {
return isAssignableFrom(MetaprogrammingImpl.findClass(cls));
}
@Override
public ReflectMethod[] getDeclaredMethods() {
resolve();
@ -273,6 +286,22 @@ public class ReflectClassImpl<T> implements ReflectClass<T> {
});
}
@Override
public ReflectMethod getDeclaredJMethod(String name, Class<?>... parameterTypes) {
ReflectClass<?>[] mappedParamTypes = Arrays.stream(parameterTypes)
.map(MetaprogrammingImpl::findClass)
.toArray(ReflectClass[]::new);
return getDeclaredMethod(name, mappedParamTypes);
}
@Override
public ReflectMethod getJMethod(String name, Class<?>... parameterTypes) {
ReflectClass<?>[] mappedParamTypes = Arrays.stream(parameterTypes)
.map(MetaprogrammingImpl::findClass)
.toArray(ReflectClass[]::new);
return getMethod(name, mappedParamTypes);
}
@Override
public ReflectMethod getMethod(String name, ReflectClass<?>... parameterTypes) {
resolve();

View File

@ -59,7 +59,7 @@ public final class TeaVMProblemRenderer {
renderCallLocation(location.getMethod(), location.getSourceLocation(), sb);
if (location.getMethod() != null) {
CallGraphNode node = cg.getNode(location.getMethod());
while (true) {
for (int i = 0; i < 100; ++i) {
Iterator<? extends CallSite> callSites = node.getCallerCallSites().iterator();
if (!callSites.hasNext()) {
break;