public void setMethod(JMethod method) { toReturn.method = method; TypeOracle oracle = method.getEnclosingType().getOracle(); JType returnType = method.getReturnType(); toReturn.isValueType = ModelUtils.isValueType(oracle, returnType); if (!toReturn.isValueType) { // See if it's a collection or a map JClassType returnClass = returnType.isClassOrInterface(); JClassType collectionInterface = oracle.findType(Collection.class.getCanonicalName()); JClassType mapInterface = oracle.findType(Map.class.getCanonicalName()); if (collectionInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( collectionInterface, returnClass); toReturn.elementType = parameterizations[0]; maybeProcessEnumType(toReturn.elementType); } else if (mapInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( mapInterface, returnClass); toReturn.keyType = parameterizations[0]; toReturn.valueType = parameterizations[1]; maybeProcessEnumType(toReturn.keyType); maybeProcessEnumType(toReturn.valueType); } } else { maybeProcessEnumType(returnType); } }
public AutoBeanType getPeer(JClassType beanType) { beanType = ModelUtils.ensureBaseType(beanType); return peers.get(beanType); }
private String getBaseMethodDeclaration(JMethod jmethod) { // Foo foo, Bar bar, Baz baz StringBuilder parameters = new StringBuilder(); for (JParameter param : jmethod.getParameters()) { parameters.append(",").append(ModelUtils.getQualifiedBaseSourceName(param.getType())).append( " ").append(param.getName()); } if (parameters.length() > 0) { parameters = parameters.deleteCharAt(0); } StringBuilder throwsDeclaration = new StringBuilder(); if (jmethod.getThrows().length > 0) { for (JType thrown : jmethod.getThrows()) { throwsDeclaration.append(". ").append(ModelUtils.getQualifiedBaseSourceName(thrown)); } throwsDeclaration.deleteCharAt(0); throwsDeclaration.insert(0, "throws "); } String returnName = ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType()); assert !returnName.contains("extends"); return String.format("%s %s(%s) %s", returnName, jmethod.getName(), parameters, throwsDeclaration); }
/** * Given type assignable to <code>IsEditor<Foo, FooEditor></code>, return * <code>FooEditor</code>. It is an error to call this method with a type not * assignable to {@link IsEditor}. */ static JClassType calculateIsEditedType(TreeLogger logger, JClassType editorType) throws UnableToCompleteException { JClassType editorIntf = editorType.getOracle().findType( IsEditor.class.getName()); JClassType[] parameterization = ModelUtils.findParameterizationOf( editorIntf, editorType); if (parameterization != null) { return parameterization[0]; } logger.log(TreeLogger.ERROR, noEditorParameterizationMessage(editorIntf, editorType)); throw new UnableToCompleteException(); }
private EntityProxyModel getEntityProxyType(JClassType entityProxyType) throws UnableToCompleteException { entityProxyType = ModelUtils.ensureBaseType(entityProxyType); EntityProxyModel toReturn = peers.get(entityProxyType); if (toReturn == null) { builder.setQualifiedBinaryName(ModelUtils.getQualifiedBaseBinaryName(entityProxyType)); builder.setQualifiedSourceName(ModelUtils.getQualifiedBaseSourceName(entityProxyType)); if (entityProxyInterface.isAssignableFrom(entityProxyType)) { builder.setType(Type.ENTITY);
.getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); } else { sw.println("%s toReturn = %s.this.getWrapped().%s(%s);", ModelUtils.ensureBaseType( jmethod.getReturnType()).getQualifiedSourceName(), type.getSimpleSourceName(), methodName, arguments);
/** * Enqueue a type in {@link #toCalculate} if {@link #peers} does not already * contain an entry. */ private void maybeCalculate(JClassType type) { if (type.isInterface() == null || ModelUtils.isValueType(oracle, type)) { return; } if (!peers.containsKey(type)) { toCalculate.add(type); } }
/** * Given type assignable to <code>IsEditor<Foo, FooEditor></code>, return * <code>FooEditor</code>. It is an error to call this method with a type not * assignable to {@link IsEditor}. */ static JClassType calculateIsEditedType(TreeLogger logger, JClassType editorType) throws UnableToCompleteException { JClassType editorIntf = editorType.getOracle().findType( IsEditor.class.getName()); JClassType[] parameterization = ModelUtils.findParameterizationOf( editorIntf, editorType); if (parameterization != null) { return parameterization[0]; } logger.log(TreeLogger.ERROR, noEditorParameterizationMessage(editorIntf, editorType)); throw new UnableToCompleteException(); }
private EntityProxyModel getEntityProxyType(JClassType entityProxyType) throws UnableToCompleteException { entityProxyType = ModelUtils.ensureBaseType(entityProxyType); EntityProxyModel toReturn = peers.get(entityProxyType); if (toReturn == null) { builder.setQualifiedBinaryName(ModelUtils.getQualifiedBaseBinaryName(entityProxyType)); builder.setQualifiedSourceName(ModelUtils.getQualifiedBaseSourceName(entityProxyType)); if (entityProxyInterface.isAssignableFrom(entityProxyType)) { builder.setType(Type.ENTITY);
.getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); } else { sw.println("%s toReturn = %s.this.getWrapped().%s(%s);", ModelUtils.ensureBaseType( jmethod.getReturnType()).getQualifiedSourceName(), type.getSimpleSourceName(), methodName, arguments);
/** * Enqueue a type in {@link #toCalculate} if {@link #peers} does not already * contain an entry. */ private void maybeCalculate(JClassType type) { if (type.isInterface() == null || ModelUtils.isValueType(oracle, type)) { return; } if (!peers.containsKey(type)) { toCalculate.add(type); } }
public AutoBeanType getPeer(JClassType beanType) { beanType = ModelUtils.ensureBaseType(beanType); return peers.get(beanType); }
public void setMethod(JMethod method) { toReturn.method = method; TypeOracle oracle = method.getEnclosingType().getOracle(); JType returnType = method.getReturnType(); toReturn.isValueType = ModelUtils.isValueType(oracle, returnType); if (!toReturn.isValueType) { // See if it's a collection or a map JClassType returnClass = returnType.isClassOrInterface(); JClassType collectionInterface = oracle.findType(Collection.class.getCanonicalName()); JClassType mapInterface = oracle.findType(Map.class.getCanonicalName()); if (collectionInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( collectionInterface, returnClass); toReturn.elementType = parameterizations[0]; maybeProcessEnumType(toReturn.elementType); } else if (mapInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( mapInterface, returnClass); toReturn.keyType = parameterizations[0]; toReturn.valueType = parameterizations[1]; maybeProcessEnumType(toReturn.keyType); maybeProcessEnumType(toReturn.valueType); } } else { maybeProcessEnumType(returnType); } }
/** * Given type assignable to <code>Editor<Foo></code>, return * <code>Foo</code>. It is an error to call this method with a type not * assignable to {@link Editor}. */ static JClassType calculateEditedType(TreeLogger logger, JClassType editorType) throws UnableToCompleteException { JClassType editorIntf = editorType.getOracle().findType( Editor.class.getName()); JClassType parameterization[] = ModelUtils.findParameterizationOf( editorIntf, editorType); if (parameterization != null) { return parameterization[0]; } logger.log(TreeLogger.ERROR, noEditorParameterizationMessage(editorIntf, editorType)); throw new UnableToCompleteException(); }
.getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); } else { sw.println("%s toReturn = %s.this.getWrapped().%s(%s);", ModelUtils.ensureBaseType( jmethod.getReturnType()).getQualifiedSourceName(), type.getSimpleSourceName(), methodName, arguments);
private String getBaseMethodDeclaration(JMethod jmethod) { // Foo foo, Bar bar, Baz baz StringBuilder parameters = new StringBuilder(); for (JParameter param : jmethod.getParameters()) { parameters.append(",").append(ModelUtils.getQualifiedBaseSourceName(param.getType())).append( " ").append(param.getName()); } if (parameters.length() > 0) { parameters = parameters.deleteCharAt(0); } StringBuilder throwsDeclaration = new StringBuilder(); if (jmethod.getThrows().length > 0) { for (JType thrown : jmethod.getThrows()) { throwsDeclaration.append(". ").append(ModelUtils.getQualifiedBaseSourceName(thrown)); } throwsDeclaration.deleteCharAt(0); throwsDeclaration.insert(0, "throws "); } String returnName = ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType()); assert !returnName.contains("extends"); return String.format("%s %s(%s) %s", returnName, jmethod.getName(), parameters, throwsDeclaration); }
/** * Enqueue a type in {@link #toCalculate} if {@link #peers} does not already * contain an entry. */ private void maybeCalculate(JClassType type) { if (type.isInterface() == null || ModelUtils.isValueType(oracle, type)) { return; } if (!peers.containsKey(type)) { toCalculate.add(type); } }
public AutoBeanType getPeer(JClassType beanType) { beanType = ModelUtils.ensureBaseType(beanType); return peers.get(beanType); }
public void setMethod(JMethod method) { toReturn.method = method; TypeOracle oracle = method.getEnclosingType().getOracle(); JType returnType = method.getReturnType(); toReturn.isValueType = ModelUtils.isValueType(oracle, returnType); if (!toReturn.isValueType) { // See if it's a collection or a map JClassType returnClass = returnType.isClassOrInterface(); JClassType collectionInterface = oracle.findType(Collection.class.getCanonicalName()); JClassType mapInterface = oracle.findType(Map.class.getCanonicalName()); if (collectionInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( collectionInterface, returnClass); toReturn.elementType = parameterizations[0]; maybeProcessEnumType(toReturn.elementType); } else if (mapInterface.isAssignableFrom(returnClass)) { JClassType[] parameterizations = ModelUtils.findParameterizationOf( mapInterface, returnClass); toReturn.keyType = parameterizations[0]; toReturn.valueType = parameterizations[1]; maybeProcessEnumType(toReturn.keyType); maybeProcessEnumType(toReturn.valueType); } } else { maybeProcessEnumType(returnType); } }
/** * Given type assignable to <code>Editor<Foo></code>, return * <code>Foo</code>. It is an error to call this method with a type not * assignable to {@link Editor}. */ static JClassType calculateEditedType(TreeLogger logger, JClassType editorType) throws UnableToCompleteException { JClassType editorIntf = editorType.getOracle().findType( Editor.class.getName()); JClassType parameterization[] = ModelUtils.findParameterizationOf( editorIntf, editorType); if (parameterization != null) { return parameterization[0]; } logger.log(TreeLogger.ERROR, noEditorParameterizationMessage(editorIntf, editorType)); throw new UnableToCompleteException(); }