@Override public boolean equals(final Object o) { return o instanceof MetaConstructor && GenUtil.equals(this, (MetaConstructor) o); } }
@Override public synchronized MetaClass asBoxed() { if (_boxedCache != null) return _boxedCache; return _boxedCache = GenUtil.getPrimitiveWrapper(this); }
@Override public String generate(final Context context) { final Statement internedStatement = context.intern(this); if (internedStatement != null) { boolean permissiveMode = GenUtil.isPermissiveMode(); GenUtil.setPermissiveMode(true); String s = internedStatement.generate(context); GenUtil.setPermissiveMode(permissiveMode); return s; } else { return getCanonicalString(context); } }
private void generateInitialization(Context context, StringBuilder buf, Object values) { buf.append("{ "); int length = Array.getLength(values); for (int i = 0; i < length; i++) { Object element = Array.get(values, i); if (element.getClass().isArray()) { generateInitialization(context, buf, element); } else { Statement statement = GenUtil.generate(context, element); String statementExpr = statement.generate(context); GenUtil.assertAssignableTypes(context, statement.getType(), componentType); buf.append(statementExpr); } if (i + 1 < length) { buf.append(", "); } } buf.append(" }"); } }
for (final Method method : type.getDeclaredMethods()) { final JavaReflectionMethod metaMethod = new JavaReflectionMethod(this, method); final String readableMethodDecl = GenUtil.getMethodString(metaMethod); if (!metaMethod.isPrivate() && !method.isBridge() && !processedMethods.contains(readableMethodDecl)) { meths.add(metaMethod); final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) { meths.add(ifaceMethod);
@Override public boolean isAssignableFrom(final MetaClass clazz) { Boolean assignable = ASSIGNABLE_CACHE.get(clazz); if (assignable != null) { return assignable; } // XXX not sure if this is uncached on purpose. // FIXME there are no tests or documentation for this case if (!isPrimitive() && NULL_TYPE.equals(clazz)) return true; if (isArray() && clazz.isArray()) { return getOuterComponentType().isAssignableFrom(clazz.getOuterComponentType()) && getArrayDimensions(this) == getArrayDimensions(clazz); } final MetaClass sup; if (getFullyQualifiedName().equals(Object.class.getName())) { assignable = true; } else if (this.getFullyQualifiedName().equals(clazz.getFullyQualifiedName())) { assignable = true; } else if (isInterface() && _hasInterface(clazz.getInterfaces(), this.getErased())) { assignable = true; } else assignable = (sup = clazz.getSuperClass()) != null && isAssignableFrom(sup); ASSIGNABLE_CACHE.put(clazz, assignable); return assignable; }
@Before public void onBefore() { GenUtil.setPermissiveMode(false); }
private Variable createForEachLoopVar(Statement collection, String loopVarName, MetaClass providedLoopVarType, Context context) { // infer the loop variable type MetaClass loopVarType = MetaClassFactory.get(Object.class); final MetaParameterizedType parameterizedType = collection.getType().getParameterizedType(); if (parameterizedType != null && parameterizedType.getTypeParameters().length != 0 && parameterizedType.getTypeParameters()[0] instanceof MetaClass) { loopVarType = (MetaClass) parameterizedType.getTypeParameters()[0]; } else if (collection.getType().getComponentType() != null) { loopVarType = collection.getType().getComponentType(); } // try to use the provided loop variable type if possible (assignable from the inferred type) if (providedLoopVarType != null) { GenUtil.assertAssignableTypes(context, loopVarType, providedLoopVarType); loopVarType = providedLoopVarType; } final Variable loopVar = Variable.create(loopVarName, loopVarType); context.addVariable(loopVar); return loopVar; }
for (final Method method : type.getDeclaredMethods()) { final JavaReflectionMethod metaMethod = new JavaReflectionMethod(this, method); final String readableMethodDecl = GenUtil.getMethodString(metaMethod); if (!metaMethod.isPrivate() && !method.isBridge() && !processedMethods.contains(readableMethodDecl)) { meths.add(metaMethod); final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) { meths.add(ifaceMethod);
@Override public boolean isAssignableFrom(final MetaClass clazz) { Boolean assignable = ASSIGNABLE_CACHE.get(clazz); if (assignable != null) { return assignable; } // XXX not sure if this is uncached on purpose. // FIXME there are no tests or documentation for this case if (!isPrimitive() && NULL_TYPE.equals(clazz)) return true; if (isArray() && clazz.isArray()) { return getOuterComponentType().isAssignableFrom(clazz.getOuterComponentType()) && getArrayDimensions(this) == getArrayDimensions(clazz); } final MetaClass sup; if (getFullyQualifiedName().equals(Object.class.getName())) { assignable = true; } else if (this.getFullyQualifiedName().equals(clazz.getFullyQualifiedName())) { assignable = true; } else if (isInterface() && _hasInterface(clazz.getInterfaces(), this.getErased())) { assignable = true; } else assignable = (sup = clazz.getSuperClass()) != null && isAssignableFrom(sup); ASSIGNABLE_CACHE.put(clazz, assignable); return assignable; }
private void generateInitialization(Context context, StringBuilder buf, Object values) { buf.append("{ "); int length = Array.getLength(values); for (int i = 0; i < length; i++) { Object element = Array.get(values, i); if (element.getClass().isArray()) { generateInitialization(context, buf, element); } else { Statement statement = GenUtil.generate(context, element); String statementExpr = statement.generate(context); GenUtil.assertAssignableTypes(context, statement.getType(), componentType); buf.append(statementExpr); } if (i + 1 < length) { buf.append(", "); } } buf.append(" }"); } }
private Variable createForEachLoopVar(Statement collection, String loopVarName, MetaClass providedLoopVarType, Context context) { // infer the loop variable type MetaClass loopVarType = MetaClassFactory.get(Object.class); final MetaParameterizedType parameterizedType = collection.getType().getParameterizedType(); if (parameterizedType != null && parameterizedType.getTypeParameters().length != 0 && parameterizedType.getTypeParameters()[0] instanceof MetaClass) { loopVarType = (MetaClass) parameterizedType.getTypeParameters()[0]; } else if (collection.getType().getComponentType() != null) { loopVarType = collection.getType().getComponentType(); } // try to use the provided loop variable type if possible (assignable from the inferred type) if (providedLoopVarType != null) { GenUtil.assertAssignableTypes(context, loopVarType, providedLoopVarType); loopVarType = providedLoopVarType; } final Variable loopVar = Variable.create(loopVarName, loopVarType); context.addVariable(loopVar); return loopVar; }
private MetaMethod validateExceptionHandlingMethod(final Decorable decorable) { // Ensure that method has exactly one parameter of type Throwable final MetaMethod method = decorable.getAsMethod(); final MetaParameter[] parms = method.getParameters(); if (!(parms.length == 1 && parms[0].getType().equals(MetaClassFactory.get(Throwable.class)))) { throw new GenerationException("Methods annotated with " + UncaughtExceptionHandler.class.getName() + " must have exactly one parameter of type " + Throwable.class.getName() + ". Invalid parameters in method: " + GenUtil.getMethodString(method) + " of type " + method.getDeclaringClass() + "."); } return method; }
@Override public boolean equals(final Object o) { return o instanceof MetaConstructor && GenUtil.equals(this, (MetaConstructor) o); } }
public static void assertAssignableTypes(final Context context, final MetaClass from, final MetaClass to) { if (!to.asBoxed().isAssignableFrom(from.asBoxed())) { if (to.isArray() && from.isArray() && GenUtil.getArrayDimensions(to) == GenUtil.getArrayDimensions(from) && to.getOuterComponentType().isAssignableFrom(from.getOuterComponentType())) { return; } if (!context.isPermissiveMode()) { if (classAliases.contains(from.getFullyQualifiedName()) && classAliases.contains(to.getFullyQualifiedName())) { // handle convertibility between MetaClass API and java Class reference. return; } throw new InvalidTypeException(to.getFullyQualifiedName() + " is not assignable from " + from.getFullyQualifiedName()); } } }
@Override public String generate(final Context context) { final Statement internedStatement = context.intern(this); if (internedStatement != null) { boolean permissiveMode = GenUtil.isPermissiveMode(); GenUtil.setPermissiveMode(true); String s = internedStatement.generate(context); GenUtil.setPermissiveMode(permissiveMode); return s; } else { return getCanonicalString(context); } }
@Override public synchronized MetaClass asBoxed() { if (_boxedCache != null) return _boxedCache; return _boxedCache = GenUtil.getPrimitiveWrapper(this); }
assertAssignableTypes(context, ((Statement) input).getType(), targetType); return (Statement) input; return generate(context, input); return generate(context, input); return generate(context, input); return generate(context, DataConversion.convert(input, targetClass)); return generate(context, input);
for (final JMethod jMethod : type.getMethods()) { final GWTMethod gwtMethod = new GWTMethod(oracle, jMethod); final String readableMethodDecl = GenUtil.getMethodString(gwtMethod); if (!jMethod.isPrivate() && !processedMethods.contains(readableMethodDecl)) { meths.add(gwtMethod); final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) { meths.add(ifaceMethod);
@Override public boolean equals(final Object o) { return o instanceof MetaConstructor && GenUtil.equals(this, (MetaConstructor) o); } }