private static boolean isArray(ValueType type) { if (type == null || type.isObject("java.lang.Object")) { return true; } return type instanceof ValueType.Array; }
public boolean isObject(Class<?> cls) { return isObject(cls.getName()); }
DependencyNode createNode(ValueType typeFilter) { if (typeFilter != null && typeFilter.isObject("java.lang.Object")) { typeFilter = null; } DependencyNode node = new DependencyNode(this, typeFilter); allNodes.add(node); return node; }
private MethodReference singleDimensionArrayUnwrapper(ValueType itemType) { if (itemType instanceof ValueType.Primitive) { switch (((ValueType.Primitive) itemType).getKind()) { case BOOLEAN: return JSMethods.UNWRAP_BOOLEAN_ARRAY; case BYTE: return JSMethods.UNWRAP_BYTE_ARRAY; case SHORT: return JSMethods.UNWRAP_SHORT_ARRAY; case CHARACTER: return JSMethods.UNWRAP_CHAR_ARRAY; case INTEGER: return JSMethods.UNWRAP_INT_ARRAY; case FLOAT: return JSMethods.UNWRAP_FLOAT_ARRAY; case DOUBLE: return JSMethods.UNWRAP_DOUBLE_ARRAY; default: break; } } else if (itemType.isObject(String.class)) { return JSMethods.UNWRAP_STRING_ARRAY; } return JSMethods.UNWRAP_ARRAY; }
private MethodReference multipleDimensionArrayUnwrapper(ValueType itemType) { if (itemType instanceof ValueType.Primitive) { switch (((ValueType.Primitive) itemType).getKind()) { case BOOLEAN: return JSMethods.BOOLEAN_ARRAY_UNWRAPPER; case BYTE: return JSMethods.BYTE_ARRAY_UNWRAPPER; case SHORT: return JSMethods.SHORT_ARRAY_UNWRAPPER; case CHARACTER: return JSMethods.CHAR_ARRAY_UNWRAPPER; case INTEGER: return JSMethods.INT_ARRAY_UNWRAPPER; case FLOAT: return JSMethods.FLOAT_ARRAY_UNWRAPPER; case DOUBLE: return JSMethods.DOUBLE_ARRAY_UNWRAPPER; default: break; } } else if (itemType.isObject(String.class)) { return JSMethods.STRING_ARRAY_UNWRAPPER; } return JSMethods.ARRAY_UNWRAPPER; }
private MethodReference getWrapperFunction(ValueType type) { if (type instanceof ValueType.Primitive) { switch (((ValueType.Primitive) type).getKind()) { case BOOLEAN: return JSMethods.BOOLEAN_ARRAY_WRAPPER; case BYTE: return JSMethods.BYTE_ARRAY_WRAPPER; case SHORT: return JSMethods.SHORT_ARRAY_WRAPPER; case CHARACTER: return JSMethods.CHAR_ARRAY_WRAPPER; case INTEGER: return JSMethods.INT_ARRAY_WRAPPER; case FLOAT: return JSMethods.FLOAT_ARRAY_WRAPPER; case DOUBLE: return JSMethods.DOUBLE_ARRAY_WRAPPER; default: break; } } else if (type.isObject(String.class)) { return JSMethods.STRING_ARRAY_WRAPPER; } return JSMethods.ARRAY_WRAPPER; }
private boolean isWrappedNativeCall(MethodReader method) { if (!method.hasModifier(ElementModifier.NATIVE)) { return false; } for (ValueType type : method.getParameterTypes()) { if (type.isObject(String.class)) { return true; } } return false; }
private ValueType getWrappedType(ValueType type) { if (type instanceof ValueType.Array) { ValueType itemType = ((ValueType.Array) type).getItemType(); if (itemType instanceof ValueType.Array) { return ValueType.parse(Object[].class); } else { return ValueType.arrayOf(getWrappedType(itemType)); } } else if (type instanceof ValueType.Object) { if (type.isObject(String.class)) { return type; } else { return JSMethods.JS_OBJECT; } } else { return type; } }
private String extractPropertyName(Expr propertyName) { if (!(propertyName instanceof InvocationExpr)) { return null; } InvocationExpr invoke = (InvocationExpr) propertyName; if (!invoke.getMethod().getClassName().equals(JS.class.getName())) { return null; } if (!invoke.getMethod().getName().equals("wrap") || !invoke.getMethod().getDescriptor().parameterType(0).isObject("java.lang.String")) { return null; } Expr arg = invoke.getArguments().get(0); if (!(arg instanceof ConstantExpr)) { return null; } ConstantExpr constant = (ConstantExpr) arg; return constant.getValue() instanceof String ? (String) constant.getValue() : null; }
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { int index = 0; for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { AnnotationReader providerAnnot = method.getAnnotations().get(MetadataProvider.class.getName()); if (providerAnnot != null) { transformMetadataMethod(cls, method, context.getDiagnostics(), context.getHierarchy(), index++); } providerAnnot = method.getAnnotations().get(ClassScopedMetadataProvider.class.getName()); if (providerAnnot != null) { ValueType[] params = method.getParameterTypes(); if (params.length != 1 && params[0].isObject(PlatformClass.class.getName())) { context.getDiagnostics().error(new CallLocation(method.getReference()), "Method {{m0}} marked with {{c1}} must take exactly one parameter of type {{c2}}", method.getReference(), ClassScopedMetadataProvider.class.getName(), PlatformClass.class.getName()); } AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( ClassScopedMetadataProviderNativeGenerator.class.getName()))); method.getAnnotations().add(genAnnot); } } }
private Variable unwrap(Variable var, String methodName, ValueType argType, ValueType resultType, TextLocation location) { if (!argType.isObject(JSObject.class.getName())) { Variable castValue = program.createVariable(); CastInstruction castInsn = new CastInstruction(); castInsn.setValue(var); castInsn.setReceiver(castValue); castInsn.setLocation(location); castInsn.setTargetType(argType); replacement.add(castInsn); var = castValue; } Variable result = program.createVariable(); InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(referenceCache.getCached(referenceCache.getCached(new MethodReference( JS.class.getName(), methodName, argType, resultType)))); insn.setArguments(var); insn.setReceiver(result); insn.setType(InvocationType.SPECIAL); insn.setLocation(location); replacement.add(insn); return result; }
if (meta.parameterCount() == 0 || meta.parameterType(0).isObject(Value.class)) { return null; for (int i = 0; i < method.parameterCount(); ++i) { ValueType proxyParam = meta.parameterType(i + paramOffset); if (proxyParam.isObject(ReflectClass.class)) { if (classParamIndex == -1) { classParamIndex = i; return null; } else if (!proxyParam.isObject(Value.class)) { return null;
@Override public void invoke(VariableReader receiver, VariableReader instance, MethodReference method, List<? extends VariableReader> arguments, InvocationType type) { if (instance == null) { invokeSpecial(receiver, null, method, arguments); } else { switch (type) { case SPECIAL: invokeSpecial(receiver, instance, method, arguments); break; case VIRTUAL: invokeVirtual(receiver, instance, method, arguments); break; } if (method.getName().equals("getClass") && method.parameterCount() == 0 && method.getReturnType().isObject(Class.class) && receiver != null) { getNode(instance).connect(getNode(receiver).getClassValueNode()); } } }
public boolean isSuperType(ValueType superType, ValueType subType, boolean defaultValue) { if (superType.equals(subType)) { return true; } if (superType instanceof ValueType.Primitive || subType instanceof ValueType.Primitive) { return false; } if (superType.isObject("java.lang.Object")) { return true; } if (superType instanceof ValueType.Object && subType instanceof ValueType.Object) { return isSuperType(((ValueType.Object) superType).getClassName(), ((ValueType.Object) subType).getClassName(), defaultValue); } else if (superType instanceof ValueType.Array & subType instanceof ValueType.Array) { return isSuperType(((ValueType.Array) superType).getItemType(), ((ValueType.Array) subType).getItemType(), defaultValue); } else { return false; } }
public StringBuilderEmitter append(ValueEmitter value) { if (value.getType() instanceof ValueType.Primitive) { switch (((ValueType.Primitive) value.getType()).getKind()) { case BYTE: value = value.castToInteger(IntegerSubtype.BYTE); break; case SHORT: value = value.castToInteger(IntegerSubtype.SHORT); break; default: break; } } else { if (!value.getType().isObject("java.lang.String")) { value = value.cast(Object.class); } } sb = sb.invokeVirtual("append", StringBuilder.class, value); return this; }
? method.parameterType(i) : i == 0 ? ValueType.object(method.getOwnerName()) : method.parameterType(i - 1); if (type.isObject(String.class)) { writer.print("teavm_stringToC("); expr.getArguments().get(i).acceptVisitor(this);
String owningClass = method.getClassName(); if (hierarchy.isSuperType(Resource.class.getName(), owningClass, false)) { if (method.getReturnType().isObject(String.class)) { Variable var = program.createVariable(); InvokeInstruction amplifyInstruction = new InvokeInstruction();
Variable unbox(Variable var, ValueType type) { if (type instanceof ValueType.Primitive) { switch (((ValueType.Primitive) type).getKind()) { case BOOLEAN: return unbox(var, boolean.class, Boolean.class); case BYTE: return unbox(var, byte.class, Byte.class); case SHORT: return unbox(var, short.class, Short.class); case CHARACTER: return unbox(var, char.class, Character.class); case INTEGER: return unbox(var, int.class, Integer.class); case LONG: return unbox(var, long.class, Long.class); case FLOAT: return unbox(var, float.class, Float.class); case DOUBLE: return unbox(var, double.class, Double.class); } } else if (!type.isObject(Object.class)) { CastInstruction castInsn = new CastInstruction(); castInsn.setValue(var); castInsn.setReceiver(program.createVariable()); castInsn.setTargetType(type); var = castInsn.getReceiver(); add(castInsn); } return var; }
if (methodRef.getDescriptor().parameterType(0).isObject("java.lang.String")) { if (context.getArgument(0) instanceof ConstantExpr) { ConstantExpr constant = (ConstantExpr) context.getArgument(0);