For IntelliJ IDEA and
Android Studio


private void myMethod () {FieldOutline f =
FieldRenderer fieldRenderer;fieldRenderer.generate(context, prop)
Constructor function Object() { [native code] };(FieldOutline) function Object() { [native code] }.newInstance(new Object[]{context, prop})
ClassOutlineImpl outline;new ConstField(outline, prop)
- AI code suggestions by Codota
}
@Override public void generateSetter(FieldOutline fieldOutline, JDefinedClass theClass, JMethod setter, JVar value) { final JFieldVar field = theClass.fields().get( fieldOutline.getPropertyInfo().getName(false)); if (field != null) { setter.body().assign(JExpr._this().ref(field), value); } else { // Fallback to the accessor Mode.accessor.generateSetter(fieldOutline, theClass, setter, value); } } };
public void toRawValue(JBlock block, JVar $var) { // [RESULT] // if([core.hasSetValue]) // $var = [core.toRawValue].getValue(); // else // $var = null; JConditional cond = block._if(acc.hasSetValue()); JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control acc.toRawValue(cond._then(),$v); cond._then().assign($var,$v.invoke("getValue")); cond._else().assign($var, JExpr._null()); }
@Override public void generateSetter(FieldOutline fieldOutline, JDefinedClass theClass, JMethod setter, JVar value) { final FieldAccessor accessor = fieldOutline.create(JExpr ._this()); accessor.unsetValues(setter.body()); accessor.fromRawValue(setter.body()._if(value.ne(JExpr._null()))._then(), "draft", value); } },
@Override public boolean accept(FieldOutline field){ CPropertyInfo propertyInfo = field.getPropertyInfo(); if(propertyInfo.isCollection()){ JType elementType = CodeModelUtil.getElementType(field.getRawType()); String name = elementType.name(); return ((this.name).equals(name + "s") || (this.name).equals(JJavaName.getPluralForm(name))); } return false; } };
private boolean isAbstract(Outline outline, FieldOutline field) { for (ClassOutline classOutline : outline.getClasses()) { if (classOutline.implClass == field.getRawType() && classOutline.implClass.isAbstract()) { return true; } } return false; }
protected void processFieldOutline(ClassOutline classOutline, FieldOutline fieldOutline, Options options, ErrorHandler errorHandler) { final CCustomizations customizations = CustomizationUtils .getCustomizations(fieldOutline); annotate(fieldOutline.parent().ref.owner(), fieldOutline, customizations, errorHandler); }
public static String getPropertyName(FieldOutline fieldOutline) { return NameConverter.standard.toVariableName(fieldOutline .getPropertyInfo().getName(true)); }
/** * Returns the <code>isSetProperty()</code> method for the given field * outline or <code>null</code> if no such method exists. * * @param fieldOutline * field outline. * @return The <code>isSetProperty()</code> method for the given field * outline or <code>null</code> if no such method exists. */ public static JMethod issetter(FieldOutline fieldOutline) { final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "isSet" + publicName; return theClass.getMethod(name, NONE); }
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) { if (constantField != null) { } else if (setter != null) { block.invoke(targetObject, setter).arg($var); } else { unsetValues(block); if (fieldOutline.getPropertyInfo().isCollection()) { fieldAccessor.fromRawValue(block ._if($var.ne(JExpr._null()))._then(), uniqueName, $var); } else { fieldAccessor.fromRawValue(block, uniqueName, $var); } } }
static public JFieldVar getFieldVar(FieldOutline field){ ClassOutline clazz = field.parent(); CPropertyInfo propertyInfo = field.getPropertyInfo(); return (clazz.implClass.fields()).get(propertyInfo.getName(false)); }
static private FieldOutline getIdField(ClassOutline clazz){ String name = "id"; FieldOutline[] fields = clazz.getDeclaredFields(); for(FieldOutline field : fields){ CPropertyInfo propertyInfo = field.getPropertyInfo(); String privateName = propertyInfo.getName(false); JType fieldType = field.getRawType(); if((name).equals(privateName) && ("java.lang.String").equals(fieldType.fullName())){ return field; } } return null; }
private void updateDurationGetter(ClassOutline co, FieldOutline fo, JDefinedClass dc, XmlString xmlDefaultValue, Outline outline) { String fieldName = fo.getPropertyInfo().getName(false); String getterName = "get" + fo.getPropertyInfo().getName(true); JMethod method = dc.getMethod(getterName, new JType[0]); JDocComment doc = method.javadoc(); int mods = method.mods().getValue(); JType mtype = method.type(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating getter: " + getterName); } // remove existing method and define new one dc.methods().remove(method); method = dc.method(mods, mtype, getterName); method.javadoc().append(doc); JFieldRef fr = JExpr.ref(fieldName); if (xmlDefaultValue != null) { JExpression test = JOp.eq(JExpr._null(), fr); JConditional jc = method.body()._if(test); JTryBlock b = jc._then()._try(); b.body()._return(outline.getCodeModel().ref(DatatypeFactory.class) .staticInvoke("newInstance").invoke("newDuration").arg(JExpr.lit(xmlDefaultValue.value))); b._catch(outline.getCodeModel().ref(DatatypeConfigurationException.class)); method.body()._return(fr); } else { method.body()._return(fr); } }
definedClazz._implements(hasIdInterface); definedClazz._implements(hasExtensionsInterface); CPropertyInfo propertyInfo = contentField.getPropertyInfo(); definedClazz._implements(iterableInterface.narrow(elementType)); JMethod iteratorMethod = definedClazz.method(JMod.PUBLIC, iteratorInterface.narrow(elementType), "iterator"); iteratorMethod.body()._return(JExpr.invoke("get" + propertyInfo.getName(true)).invoke("iterator"));
public static Set<JType> getPossibleTypes(FieldOutline fieldOutline, Aspect aspect) { Validate.notNull(fieldOutline); final ClassOutline classOutline = fieldOutline.parent(); final Outline outline = classOutline.parent(); final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); final Set<JType> types = new HashSet<JType>(); if (propertyInfo.getAdapter() != null) { types.add(propertyInfo.getAdapter().customType.toType(fieldOutline .parent().parent(), aspect)); } else if (propertyInfo.baseType != null) { types.add(propertyInfo.baseType); } else { Collection<? extends CTypeInfo> typeInfos = propertyInfo.ref(); for (CTypeInfo typeInfo : typeInfos) { types.addAll(getPossibleTypes(outline, aspect, typeInfo)); } } return types; }
buf.append(cls.name()); Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';');
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) { // add isSetXXX and unsetXXX. MethodWriter writer = outline.createMethodWriter(); JCodeModel codeModel = outline.parent().getCodeModel(); FieldAccessor acc = core.create(JExpr._this()); if( generateIsSetMethod ) { // [RESULT] boolean isSetXXX() JExpression hasSetValue = acc.hasSetValue(); if( hasSetValue==null ) { // this field renderer doesn't support the isSet/unset methods generation. // issue an error throw new UnsupportedOperationException(); } writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true)) .body()._return( hasSetValue ); } if( generateUnSetMethod ) { // [RESULT] void unsetXXX() acc.unsetValues( writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() ); } }
/** * Returns the <code>setProperty(...)</code> method for the given field * outline or <code>null</code> if no such method exists. * * @param fieldOutline * field outline. * @return The <code>setProperty(...)</code> method for the given field * outline or <code>null</code> if no such method exists. */ public static JMethod setter(FieldOutline fieldOutline) { final JMethod getter = getter(fieldOutline); final JType type = getter != null ? getter.type() : fieldOutline .getRawType(); final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "set" + publicName; return theClass.getMethod(name, new JType[] { type }); }
protected JMethod generateToString$appendFields(ClassOutline classOutline, final JDefinedClass theClass) { final JCodeModel codeModel = theClass.owner(); final JMethod toString$appendFields = theClass.method(JMod.PUBLIC, codeModel.ref(StringBuilder.class), "appendFields"); body.invoke(JExpr._super(), "appendFields").arg(locator) .arg(buffer).arg(toStringStrategy); } else { classOutline.getDeclaredFields(), getIgnoring()); final JBlock block = body.block(); final FieldAccessorEx fieldAccessor = getFieldAccessorFactory() .createFieldAccessor(fieldOutline, JExpr._this()); final JVar theValue = block.decl( fieldAccessor.getType(), "the" + fieldOutline.getPropertyInfo().getName( true)); block.invoke(toStringStrategy, "appendField") .arg(locator) .arg(JExpr._this()) .arg(JExpr.lit(fieldOutline.getPropertyInfo() .getName(false))).arg(buffer).arg(theValue) .arg(valueIsSet);
String fieldName = fo.getPropertyInfo().getName(false); JType type = fo.getRawType(); String typeName = type.fullName(); + fo.getPropertyInfo().getName(true); JMethod method = dc.getMethod(getterName, new JType[0]); JType mtype = method.type(); String setterName = "set" + fo.getPropertyInfo().getName(true); method = dc.getMethod(setterName, new JType[] {mtype}); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating setter: " + setterName); return; JDocComment doc = method.javadoc(); dc.methods().remove(method); JMethod oldMethod = dc.getMethod("unset" + fo.getPropertyInfo().getName(true), new JType[0]); if (oldMethod != null) { dc.methods().remove(oldMethod); method = dc.method(mods, method.type(), "unset" + fo.getPropertyInfo().getName(true)); method.body().assign(fr, JExpr._null()); method = dc.getMethod("isSet" + fo.getPropertyInfo().getName(true), new JType[0]); if (method != null) {