@Override public ClassReader get(String name) { return cache.computeIfAbsent(name, key -> { if (underlyingSource == null) { return Optional.empty(); } return Optional.ofNullable(underlyingSource.get(key)); }).orElse(null); }
private ClassHolder findClass(String name) { ClassReader cls = innerSource.get(name); if (cls != null) { return ModelUtils.copyClass(cls); } return generatedClasses.get(name); }
private static void getInterfaces(ClassReaderSource classSource, String className, Set<String> interfaces) { if (!interfaces.add(className)) { return; } ClassReader cls = classSource.get(className); if (cls == null) { return; } for (String iface : cls.getInterfaces()) { getInterfaces(classSource, iface, interfaces); } }
private boolean clinitNeeded(String className) { ClassReader cls = unprocessedClassSource.get(className); if (cls == null) { return true; } return cls.getMethod(new MethodDescriptor("<clinit>", void.class)) != null; }
public ReflectClassImpl<?> findClass(String name) { if (classSource.get(name) == null) { return null; } return getClass(ValueType.object(name)); }
public boolean hasClinit(String className) { if (isStructure(className) || className.equals(Address.class.getName())) { return false; } ClassReader cls = classSource.get(className); if (cls == null) { return false; } return cls.getMethod(new MethodDescriptor("<clinit>", ValueType.VOID)) != null; }
@Override public boolean isVirtual(VirtualMethodContributorContext context, MethodReference methodRef) { ClassReader cls = context.getClassSource().get(methodRef.getClassName()); if (cls == null || !cls.getInterfaces().contains(PlatformAnnotationProvider.class.getName())) { return false; } return methodRef.getName().equals("getAnnotations"); } }
private boolean isSplittingClassInitializer(String className) { ClassReader cls = classSource.get(className); if (cls == null) { return false; } MethodReader method = cls.getMethod(new MethodDescriptor("<clinit>", ValueType.VOID)); return method != null && asyncMethods.contains(method.getReference()); }
private void addPreservedMethods(String ifaceName, Set<MethodDescriptor> methods) { ClassReader iface = classSource.get(ifaceName); for (MethodReader method : iface.getMethods()) { methods.add(method.getDescriptor()); } for (String superIfaceName : iface.getInterfaces()) { addPreservedMethods(superIfaceName, methods); } }
public boolean isStaticInit(String className) { byte result = isStaticInit.getOrDefault(className, (byte) -1); if (result < 0) { ClassReader cls = classSource.get(className); result = cls != null && cls.getAnnotations().get(StaticInit.class.getName()) != null ? (byte) 1 : 0; isStaticInit.put(className, result); } return result != 0; }
private boolean examineIfJavaScriptClass(String className) { ClassReader cls = classSource.get(className); if (cls == null || !(cls.hasModifier(ElementModifier.INTERFACE) || cls.hasModifier(ElementModifier.ABSTRACT))) { return false; } if (cls.getParent() != null) { if (isJavaScriptClass(cls.getParent())) { return true; } } return cls.getInterfaces().stream().anyMatch(this::isJavaScriptClass); }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); if (cls == null || cls.getParent() == null || !cls.getParent().equals("java.lang.Enum")) { return; } allEnums.propagate(agent.getType(className)); }
private String getAnnotationImplementor(DependencyAgent agent, String annotationType) { String implementorName = annotationType + "$$_impl"; if (agent.getClassSource().get(implementorName) == null) { ClassHolder implementor = createImplementor(agent.getClassHierarchy(), annotationType, implementorName); agent.submitClass(implementor); } return implementorName; }
public ValueType getFieldType(FieldReference fieldReference) { ClassReader cls = classSource.get(fieldReference.getClassName()); FieldReader field = cls.getField(fieldReference.getFieldName()); return field.getType(); }
@Override public void classReached(DependencyAgent agent, String className) { for (MethodReader reader : agent.getClassSource().get(className).getMethods()) { AnnotationReader annotation = reader.getAnnotations().get(Export.class.getName()); if (annotation != null) { agent.linkMethod(reader.getReference()).use(); } } }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); if (cls != null && !cls.hasModifier(ElementModifier.ABSTRACT) && !cls.hasModifier(ElementModifier.INTERFACE)) { allClassesNode.propagate(agent.getType(className)); } }
private void reachFunctorMethods(DependencyAgent agent, String type) { ClassReader cls = agent.getClassSource().get(type); if (cls != null) { for (MethodReader method : cls.getMethods()) { if (!method.hasModifier(ElementModifier.STATIC)) { agent.linkMethod(method.getReference()).use(); } } } }
private void reachGetSuperclass(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.getParent() != null) { method.getResult().getClassValueNode().propagate(agent.getType(cls.getParent())); } }); }
private void renderRuntimeIntern() throws IOException { writer.append("function $rt_intern(str) {").indent().softNewLine(); ClassReader stringCls = classSource.get(STRING_CLASS); if (stringCls != null && stringCls.getMethod(STRING_INTERN_METHOD) != null) { writer.append("return ").appendMethodBody(new MethodReference(STRING_CLASS, STRING_INTERN_METHOD)) .append("(str);").softNewLine(); } else { writer.append("return str;").softNewLine(); } writer.outdent().append("}").newLine(); }
private void renderSetStackTrace() throws IOException { ClassReader cls = classSource.get(SET_STACK_TRACE_METHOD.getClassName()); boolean supported = cls != null && cls.getMethod(SET_STACK_TRACE_METHOD.getDescriptor()) != null; writer.append("function $rt_setStack(e,").ws().append("stack)").ws().append("{").indent().softNewLine(); if (supported) { writer.appendMethodBody(SET_STACK_TRACE_METHOD); writer.append("(e,").ws().append("stack);").softNewLine(); } writer.outdent().append("}").newLine(); } }