mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-08 16:04:10 -08:00
Refactor dependency checker
This commit is contained in:
parent
3e036619a2
commit
8926306f17
|
@ -20,9 +20,20 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.teavm.codegen.SourceWriter;
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyConsumer;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.DependencyType;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.javascript.spi.Generator;
|
||||
import org.teavm.javascript.spi.GeneratorContext;
|
||||
import org.teavm.model.CallLocation;
|
||||
|
@ -34,7 +45,7 @@ import org.teavm.model.ValueType;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class ServiceLoaderSupport implements Generator, DependencyListener {
|
||||
public class ServiceLoaderSupport extends AbstractDependencyListener implements Generator {
|
||||
private Set<String> achievedClasses = new HashSet<>();
|
||||
private Map<String, List<String>> serviceMap = new HashMap<>();
|
||||
private DependencyNode allClassesNode;
|
||||
|
@ -84,7 +95,7 @@ public class ServiceLoaderSupport implements Generator, DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
if (!achievedClasses.add(className)) {
|
||||
return;
|
||||
}
|
||||
|
@ -123,7 +134,7 @@ public class ServiceLoaderSupport implements Generator, DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, MethodDependency method, final CallLocation location) {
|
||||
public void methodReached(final DependencyAgent agent, MethodDependency method, final CallLocation location) {
|
||||
MethodReference ref = method.getReference();
|
||||
if (ref.getClassName().equals("java.util.ServiceLoader") && ref.getName().equals("loadServices")) {
|
||||
method.getResult().propagate(agent.getType("[java.lang.Object"));
|
||||
|
@ -140,8 +151,4 @@ public class ServiceLoaderSupport implements Generator, DependencyListener {
|
|||
MethodReference ctor = new MethodReference(type, new MethodDescriptor("<init>", ValueType.VOID));
|
||||
agent.linkMethod(ctor, location).use();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,8 @@ package org.teavm.classlib.java.lang.reflect;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyListener;
|
||||
import org.teavm.dependency.FieldDependency;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.AccessLevel;
|
||||
import org.teavm.model.AnnotationReader;
|
||||
|
@ -41,13 +40,9 @@ import org.teavm.model.emit.ValueEmitter;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class AnnotationDependencyListener implements DependencyListener {
|
||||
public class AnnotationDependencyListener extends AbstractDependencyListener {
|
||||
@Override
|
||||
public void started(final DependencyAgent agent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
ClassReader cls = agent.getClassSource().get(className);
|
||||
if (cls == null) {
|
||||
return;
|
||||
|
@ -132,7 +127,7 @@ public class AnnotationDependencyListener implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
ValueType type = method.getMethod().getResultType();
|
||||
while (type instanceof ValueType.Array) {
|
||||
type = ((ValueType.Array)type).getItemType();
|
||||
|
@ -145,8 +140,4 @@ public class AnnotationDependencyListener implements DependencyListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2015 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.dependency;
|
||||
|
||||
import org.teavm.model.CallLocation;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public abstract class AbstractDependencyListener implements DependencyListener {
|
||||
@Override
|
||||
public void started(DependencyAgent agent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldReached(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
|
@ -219,7 +219,7 @@ public class DependencyChecker implements DependencyInfo {
|
|||
@Override
|
||||
public void run() {
|
||||
for (DependencyListener listener : listeners) {
|
||||
listener.classAchieved(agent, className, callLocation);
|
||||
listener.classReached(agent, className, callLocation);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -278,7 +278,7 @@ public class DependencyChecker implements DependencyInfo {
|
|||
MethodDependency graph = methodCache.map(methodRef);
|
||||
if (!graph.isMissing() && added) {
|
||||
for (DependencyListener listener : listeners) {
|
||||
listener.methodAchieved(agent, graph, callLocation);
|
||||
listener.methodReached(agent, graph, callLocation);
|
||||
}
|
||||
activateDependencyPlugin(graph, callLocation);
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ public class DependencyChecker implements DependencyInfo {
|
|||
}
|
||||
if (!dep.isMissing() && added) {
|
||||
for (DependencyListener listener : listeners) {
|
||||
listener.fieldAchieved(agent, dep, location);
|
||||
listener.fieldReached(agent, dep, location);
|
||||
}
|
||||
}
|
||||
return dep;
|
||||
|
|
|
@ -24,9 +24,9 @@ import org.teavm.model.CallLocation;
|
|||
public interface DependencyListener {
|
||||
void started(DependencyAgent agent);
|
||||
|
||||
void classAchieved(DependencyAgent agent, String className, CallLocation location);
|
||||
void classReached(DependencyAgent agent, String className, CallLocation location);
|
||||
|
||||
void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location);
|
||||
void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location);
|
||||
|
||||
void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location);
|
||||
void fieldReached(DependencyAgent agent, FieldDependency field, CallLocation location);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
package org.teavm.tooling;
|
||||
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
|
@ -25,7 +28,7 @@ import org.teavm.model.MethodReference;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
class TestExceptionDependency implements DependencyListener {
|
||||
class TestExceptionDependency extends AbstractDependencyListener {
|
||||
private MethodReference getMessageRef = new MethodReference(ExceptionHelper.class, "showException",
|
||||
Throwable.class, String.class);
|
||||
private DependencyNode allClasses;
|
||||
|
@ -36,7 +39,7 @@ class TestExceptionDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
if (isException(agent.getClassSource(), className)) {
|
||||
allClasses.propagate(agent.getType(className));
|
||||
}
|
||||
|
@ -57,13 +60,9 @@ class TestExceptionDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
if (method.getReference().equals(getMessageRef)) {
|
||||
allClasses.connect(method.getVariable(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,14 +75,14 @@ public class EntryPointGenerator extends AbstractRendererListener implements Dep
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
public void fieldReached(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,27 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.java.html.js.JavaScriptBody;
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.model.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyConsumer;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.DependencyType;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.AnnotationReader;
|
||||
import org.teavm.model.AnnotationValue;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.ElementModifier;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
import org.teavm.model.MethodReader;
|
||||
import org.teavm.model.MethodReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class JavaScriptBodyDependency implements DependencyListener {
|
||||
public class JavaScriptBodyDependency extends AbstractDependencyListener {
|
||||
private DependencyNode allClassesNode;
|
||||
private Map<MethodReference, Set<MethodReference>> achievedMethods = new HashMap<>();
|
||||
|
||||
|
@ -48,7 +61,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
ClassReader cls = agent.getClassSource().get(className);
|
||||
if (cls != null && !cls.hasModifier(ElementModifier.ABSTRACT) &&
|
||||
!cls.hasModifier(ElementModifier.INTERFACE)) {
|
||||
|
@ -57,7 +70,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
Set<MethodReference> methodsToAchieve = achievedMethods.get(method.getReference());
|
||||
if (methodsToAchieve != null) {
|
||||
for (MethodReference methodToAchieve : methodsToAchieve) {
|
||||
|
@ -105,10 +118,6 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
|||
agent.linkMethod(JavaScriptConvGenerator.valueOfCharMethod, location).use();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency fieldDep, CallLocation location) {
|
||||
}
|
||||
|
||||
private static MethodReader findMethod(ClassReaderSource classSource, String clsName, MethodDescriptor desc) {
|
||||
while (clsName != null) {
|
||||
ClassReader cls = classSource.get(clsName);
|
||||
|
|
|
@ -19,19 +19,26 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyListener;
|
||||
import org.teavm.dependency.FieldDependency;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.jso.JSMethod;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.model.*;
|
||||
import org.teavm.model.AnnotationReader;
|
||||
import org.teavm.model.AnnotationValue;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.FieldReader;
|
||||
import org.teavm.model.FieldReference;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
import org.teavm.model.MethodReader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
class JSODependencyListener implements DependencyListener {
|
||||
class JSODependencyListener extends AbstractDependencyListener {
|
||||
private Map<String, ExposedClass> exposedClasses = new HashMap<>();
|
||||
private ClassReaderSource classSource;
|
||||
private DependencyAgent agent;
|
||||
|
@ -44,7 +51,7 @@ class JSODependencyListener implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
getExposedClass(className);
|
||||
}
|
||||
|
||||
|
@ -145,12 +152,4 @@ class JSODependencyListener implements DependencyListener {
|
|||
}
|
||||
return addInterfaces(exposedCls, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency methodDep, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,21 @@
|
|||
*/
|
||||
package org.teavm.maven;
|
||||
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.model.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.MethodReference;
|
||||
import org.teavm.model.ValueType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
class TestExceptionDependency implements DependencyListener {
|
||||
class TestExceptionDependency extends AbstractDependencyListener {
|
||||
private MethodReference getMessageRef = new MethodReference("java.lang.Throwable", "getMessage",
|
||||
ValueType.object("java.lang.String"));
|
||||
private DependencyNode allClasses;
|
||||
|
@ -33,7 +40,7 @@ class TestExceptionDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
if (isException(agent.getClassSource(), className)) {
|
||||
allClasses.propagate(agent.getType(className));
|
||||
}
|
||||
|
@ -54,13 +61,9 @@ class TestExceptionDependency implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
if (method.getReference().equals(getMessageRef)) {
|
||||
allClasses.connect(method.getVariable(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,11 @@
|
|||
package org.teavm.platform.plugin;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyConsumer;
|
||||
import org.teavm.dependency.DependencyListener;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.DependencyType;
|
||||
import org.teavm.dependency.FieldDependency;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.MethodReference;
|
||||
|
@ -32,7 +31,7 @@ import org.teavm.platform.Platform;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class AnnotationDependencySupport implements DependencyListener {
|
||||
public class AnnotationDependencySupport extends AbstractDependencyListener {
|
||||
private DependencyNode allClasses;
|
||||
|
||||
@Override
|
||||
|
@ -41,12 +40,12 @@ public class AnnotationDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
allClasses.propagate(agent.getType(className));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, final MethodDependency method,
|
||||
public void methodReached(final DependencyAgent agent, final MethodDependency method,
|
||||
final CallLocation location) {
|
||||
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
||||
method.getReference().getName().equals("getAnnotations")) {
|
||||
|
@ -61,8 +60,4 @@ public class AnnotationDependencySupport implements DependencyListener {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.teavm.platform.Platform;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class ClassLookupDependencySupport implements DependencyListener {
|
||||
public class ClassLookupDependencySupport extends AbstractDependencyListener {
|
||||
private DependencyNode allClasses;
|
||||
|
||||
@Override
|
||||
|
@ -32,12 +32,12 @@ public class ClassLookupDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
allClasses.propagate(agent.getType(className));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, MethodDependency method, final CallLocation location) {
|
||||
public void methodReached(final DependencyAgent agent, MethodDependency method, final CallLocation location) {
|
||||
MethodReference ref = method.getReference();
|
||||
if (ref.getClassName().equals(Platform.class.getName()) && ref.getName().equals("lookupClass")) {
|
||||
allClasses.addConsumer(new DependencyConsumer() {
|
||||
|
@ -54,8 +54,4 @@ public class ClassLookupDependencySupport implements DependencyListener {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent dependencyChecker, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,25 @@
|
|||
*/
|
||||
package org.teavm.platform.plugin;
|
||||
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.model.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyConsumer;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.DependencyType;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
import org.teavm.model.MethodReader;
|
||||
import org.teavm.model.MethodReference;
|
||||
import org.teavm.model.ValueType;
|
||||
import org.teavm.platform.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class EnumDependencySupport implements DependencyListener {
|
||||
public class EnumDependencySupport extends AbstractDependencyListener {
|
||||
private DependencyNode allEnums;
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +42,7 @@ public class EnumDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
ClassReader cls = agent.getClassSource().get(className);
|
||||
if (cls == null || cls.getParent() == null || !cls.getParent().equals("java.lang.Enum")) {
|
||||
return;
|
||||
|
@ -41,7 +51,7 @@ public class EnumDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
||||
method.getReference().getName().equals("getEnumConstants")) {
|
||||
allEnums.connect(method.getResult().getArrayItem());
|
||||
|
@ -58,12 +68,8 @@ public class EnumDependencySupport implements DependencyListener {
|
|||
});
|
||||
method.getResult().propagate(agent.getType("[java.lang.Enum"));
|
||||
for (String cls : agent.getAchievableClasses()) {
|
||||
classAchieved(agent, cls, location);
|
||||
classReached(agent, cls, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.teavm.platform.Platform;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class NewInstanceDependencySupport implements DependencyListener {
|
||||
public class NewInstanceDependencySupport extends AbstractDependencyListener {
|
||||
private DependencyNode allClassesNode;
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ public class NewInstanceDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
ClassReader cls = agent.getClassSource().get(className);
|
||||
if (cls == null) {
|
||||
return;
|
||||
|
@ -47,7 +47,7 @@ public class NewInstanceDependencySupport implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
MethodReader reader = method.getMethod();
|
||||
if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) {
|
||||
allClassesNode.connect(method.getResult());
|
||||
|
@ -66,8 +66,4 @@ public class NewInstanceDependencySupport implements DependencyListener {
|
|||
methodDep.getVariable(0).propagate(checker.getType(type));
|
||||
methodDep.use();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent dependencyAgent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
package org.teavm.platform.plugin;
|
||||
|
||||
import org.teavm.dependency.*;
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyNode;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.platform.Platform;
|
||||
|
||||
|
@ -23,7 +26,7 @@ import org.teavm.platform.Platform;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class PlatformDependencyListener implements DependencyListener {
|
||||
public class PlatformDependencyListener extends AbstractDependencyListener {
|
||||
private DependencyNode allClasses;
|
||||
|
||||
@Override
|
||||
|
@ -32,12 +35,12 @@ public class PlatformDependencyListener implements DependencyListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
public void classReached(DependencyAgent agent, String className, CallLocation location) {
|
||||
allClasses.propagate(agent.getType(className));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
if (!method.getReference().getClassName().equals(Platform.class.getName())) {
|
||||
return;
|
||||
}
|
||||
|
@ -47,8 +50,4 @@ public class PlatformDependencyListener implements DependencyListener {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,8 @@
|
|||
*/
|
||||
package org.teavm.platform.plugin;
|
||||
|
||||
import org.teavm.dependency.AbstractDependencyListener;
|
||||
import org.teavm.dependency.DependencyAgent;
|
||||
import org.teavm.dependency.DependencyListener;
|
||||
import org.teavm.dependency.FieldDependency;
|
||||
import org.teavm.dependency.MethodDependency;
|
||||
import org.teavm.model.CallLocation;
|
||||
|
||||
|
@ -25,17 +24,9 @@ import org.teavm.model.CallLocation;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
class ResourceAccessorDependencyListener implements DependencyListener {
|
||||
class ResourceAccessorDependencyListener extends AbstractDependencyListener {
|
||||
@Override
|
||||
public void started(DependencyAgent agent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void classAchieved(DependencyAgent agent, String className, CallLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||
if (!method.getReference().getClassName().equals(ResourceAccessor.class.getName())) {
|
||||
return;
|
||||
}
|
||||
|
@ -45,8 +36,4 @@ class ResourceAccessorDependencyListener implements DependencyListener {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldAchieved(DependencyAgent agent, FieldDependency field, CallLocation location) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user