List of usage examples for com.google.gwt.core.ext.typeinfo JField isProtected
boolean isProtected();
From source file:ch.unifr.pai.twice.module.rebind.TWICEModuleGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { // Build a new class, that implements a "paintScreen" method JClassType classType;/* w w w. j ava2s . c om*/ try { classType = context.getTypeOracle().getType(typeName); JClassType genericClass = getGenericClass(classType); SourceWriter src = getSourceWriter(classType, context, logger); if (src != null) { src.println("@Override"); src.println("public " + Map.class.getName() + "<" + String.class.getName() + ", " + Object.class.getName() + "> getConfigurableFields(" + genericClass.getQualifiedSourceName() + " instance){"); src.println(Map.class.getName() + "<" + String.class.getName() + ", " + Object.class.getName() + "> result = new " + HashMap.class.getName() + "<" + String.class.getName() + ", " + Object.class.getName() + ">();"); for (JField f : genericClass.getFields()) { Configurable c = f.getAnnotation(Configurable.class); if (c != null && !f.isFinal() && !f.isPrivate() && !f.isProtected()) { src.println("result.put(\"" + c.value() + "\", instance." + f.getName() + ");"); } } src.println("return result;"); src.println("}"); src.println("@Override"); src.println("public void configure(" + Map.class.getName() + "<" + String.class.getName() + ", " + String.class.getName() + "> properties, " + genericClass.getQualifiedSourceName() + " instance){"); src.println("for(" + String.class.getName() + " key : properties.keySet()){"); src.println("String value = properties.get(key);"); src.println("if(key==null){"); src.println("}"); for (JField f : genericClass.getFields()) { Configurable c = f.getAnnotation(Configurable.class); if (c != null && !f.isFinal() && !f.isPrivate() && !f.isProtected()) { JPrimitiveType t = f.getType().isPrimitive(); if (t != null) { src.println("else if(key.equals(\"" + c.value() + "\")){"); switch (t) { case INT: src.println("instance." + f.getName() + "=" + Integer.class.getName() + ".parseInt(value);"); break; case BOOLEAN: src.println("instance." + f.getName() + "=" + Boolean.class.getName() + ".parseBoolean(value);"); break; case DOUBLE: src.println("instance." + f.getName() + "=" + Double.class.getName() + ".parseDouble(value);"); break; case FLOAT: src.println("instance." + f.getName() + "=" + Float.class.getName() + ".parseFloat(value);"); break; case LONG: src.println("instance." + f.getName() + "=" + Long.class.getName() + ".parseLong(value);"); break; default: throw new RuntimeException("The primitive type \"" + t.name() + "\" is not supported for configuration"); } } else if (f.getType().getQualifiedSourceName().equals(String.class.getName())) { src.println("instance." + f.getName() + "=value"); } else { throw new RuntimeException("The type \"" + f.getType().getQualifiedSourceName() + "\" is not supported for configuration"); } src.println("}"); } } src.println("}"); src.println("}"); src.println("@Override"); src.println("public " + RunAsyncCallback.class.getName() + " instantiate(final " + AsyncCallback.class.getName() + "<" + genericClass.getQualifiedSourceName() + "> callback){"); src.println("return new " + RunAsyncCallback.class.getName() + "(){"); src.println("@Override"); src.println("public void onSuccess(){"); src.println(genericClass.getQualifiedSourceName() + " module = " + GWT.class.getName() + ".create(" + genericClass.getQualifiedSourceName() + ".class);"); src.println("//start(module);"); src.println("callback.onSuccess(module);"); src.println("}"); src.println("@Override"); src.println("public void onFailure(" + Throwable.class.getName() + " reason){"); src.println("callback.onFailure(reason);"); src.println("}"); src.println("};"); src.println("}"); src.commit(logger); } return typeName + "Impl"; } catch (NotFoundException e) { e.printStackTrace(); } return null; }
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private String createTypeGenerator(JType t) { buffer.setLength(0);/*from ww w .ja v a 2 s . c o m*/ String varName = "t"; if (t instanceof JPrimitiveType) varName = "p"; int id = nextId(); typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id); pb("Type " + varName + " = new Type();"); pb(varName + ".name = \"" + t.getErasedType().getQualifiedSourceName() + "\";"); pb(varName + ".id = " + id + ";"); pb(varName + ".clazz = " + t.getErasedType().getQualifiedSourceName() + ".class;"); if (t instanceof JClassType) { JClassType c = (JClassType) t; if (isVisible(c.getSuperclass())) pb(varName + ".superClass = " + c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class;"); if (c.getFlattenedSupertypeHierarchy() != null) { pb("Set<Class> " + varName + "Assignables = new HashSet<Class>();"); for (JType i : c.getFlattenedSupertypeHierarchy()) { if (!isVisible(i)) continue; pb(varName + "Assignables.add(" + i.getErasedType().getQualifiedSourceName() + ".class);"); } pb(varName + ".assignables = " + varName + "Assignables;"); } if (c.isInterface() != null) pb(varName + ".isInterface = true;"); if (c.isEnum() != null) pb(varName + ".isEnum = true;"); if (c.isArray() != null) pb(varName + ".isArray = true;"); if (c.isMemberType()) pb(varName + ".isMemberClass = true;"); pb(varName + ".isStatic = " + c.isStatic() + ";"); pb(varName + ".isAbstract = " + c.isAbstract() + ";"); if (c.getFields() != null) { pb(varName + ".fields = new Field[] {"); for (JField f : c.getFields()) { String enclosingType = getType(c); String fieldType = getType(f.getType()); int setter = nextId(); int getter = nextId(); String elementType = getElementTypes(f); String annotations = getAnnotations(f.getDeclaredAnnotations()); pb("new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", " + f.isFinal() + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", " + f.isProtected() + ", " + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient() + ", " + f.isVolatile() + ", " + getter + ", " + setter + ", " + elementType + ", " + annotations + "), "); SetterGetterStub stub = new SetterGetterStub(); stub.name = f.getName(); stub.enclosingType = enclosingType; stub.type = fieldType; stub.isStatic = f.isStatic(); stub.isFinal = f.isFinal(); if (enclosingType != null && fieldType != null) { stub.getter = getter; stub.setter = setter; } setterGetterStubs.add(stub); } pb("};"); } printMethods(c, varName, "Method", c.getMethods()); if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) { printMethods(c, varName, "Constructor", c.getConstructors()); } else { logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated"); } if (c.isArray() != null) { pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";"); } if (c.isEnum() != null) { JEnumConstant[] enumConstants = c.isEnum().getEnumConstants(); if (enumConstants != null) { pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];"); for (int i = 0; i < enumConstants.length; i++) { pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName() + "." + enumConstants[i].getName() + ";"); } } } Annotation[] annotations = c.getDeclaredAnnotations(); if (annotations != null && annotations.length > 0) { pb(varName + ".annotations = " + getAnnotations(annotations) + ";"); } } else if (t.isAnnotation() != null) { pb(varName + ".isAnnotation = true;"); } else { pb(varName + ".isPrimitive = true;"); } pb("types.put(\"" + t.getErasedType().getQualifiedSourceName() + "\", " + varName + ");"); return buffer.toString(); }
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private String createTypeGenerator(JType t) { buffer.setLength(0);//from ww w . j a va2s. c o m int id = nextTypeId++; typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id); JClassType c = t.isClass(); String name = t.getErasedType().getQualifiedSourceName(); String superClass = null; if (c != null && (isVisible(c.getSuperclass()))) superClass = c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class"; String assignables = null; String interfaces = null; if (c != null && c.getFlattenedSupertypeHierarchy() != null) { assignables = "new HashSet<Class>(Arrays.asList("; boolean used = false; for (JType i : c.getFlattenedSupertypeHierarchy()) { if (!isVisible(i) || i.equals(t) || "java.lang.Object".equals(i.getErasedType().getQualifiedSourceName())) continue; if (used) assignables += ", "; assignables += i.getErasedType().getQualifiedSourceName() + ".class"; used = true; } if (used) assignables += "))"; else assignables = null; } if (c == null) { // if it's not a class, it may be an interface instead c = t.isInterface(); } if (c != null && c.getImplementedInterfaces() != null) { interfaces = "new HashSet<Class>(Arrays.asList("; boolean used = false; for (JType i : c.getImplementedInterfaces()) { if (!isVisible(i) || i.equals(t)) continue; if (used) interfaces += ", "; interfaces += i.getErasedType().getQualifiedSourceName() + ".class"; used = true; } if (used) interfaces += "))"; else interfaces = null; } String varName = "c" + id; pb("private static Type " + varName + ";"); pb("private static Type " + varName + "() {"); pb("if(" + varName + "!=null) return " + varName + ";"); pb(varName + " = new Type(\"" + name + "\", " + id + ", " + name + ".class, " + superClass + ", " + assignables + ", " + interfaces + ");"); if (c != null) { if (c.isEnum() != null) pb(varName + ".isEnum = true;"); if (c.isArray() != null) pb(varName + ".isArray = true;"); if (c.isMemberType()) pb(varName + ".isMemberClass = true;"); if (c.isInterface() != null) { pb(varName + ".isInterface = true;"); } else { pb(varName + ".isStatic = " + c.isStatic() + ";"); pb(varName + ".isAbstract = " + c.isAbstract() + ";"); } if (c.getFields() != null && c.getFields().length > 0) { pb(varName + ".fields = new Field[] {"); for (JField f : c.getFields()) { String enclosingType = getType(c); String fieldType = getType(f.getType()); int setterGetter = nextSetterGetterId++; String elementType = getElementTypes(f); String annotations = getAnnotations(f.getDeclaredAnnotations()); pb(" new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", " + f.isFinal() + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", " + f.isProtected() + ", " + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient() + ", " + f.isVolatile() + ", " + setterGetter + ", " + setterGetter + ", " + elementType + ", " + annotations + "), "); SetterGetterStub stub = new SetterGetterStub(); stub.name = f.getName(); stub.enclosingType = enclosingType; stub.type = fieldType; stub.isStatic = f.isStatic(); stub.isFinal = f.isFinal(); if (enclosingType != null && fieldType != null) { stub.getter = setterGetter; stub.setter = setterGetter; } setterGetterStubs.add(stub); } pb("};"); } createTypeInvokables(c, varName, "Method", c.getMethods()); if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) { createTypeInvokables(c, varName, "Constructor", c.getConstructors()); } else { logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated"); } if (c.isArray() != null) { pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";"); } if (c.isEnum() != null) { JEnumConstant[] enumConstants = c.isEnum().getEnumConstants(); if (enumConstants != null) { pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];"); for (int i = 0; i < enumConstants.length; i++) { pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName() + "." + enumConstants[i].getName() + ";"); } } } Annotation[] annotations = c.getDeclaredAnnotations(); if (annotations != null && annotations.length > 0) { pb(varName + ".annotations = " + getAnnotations(annotations) + ";"); } } else if (t.isAnnotation() != null) { pb(varName + ".isAnnotation = true;"); } else { pb(varName + ".isPrimitive = true;"); } pb("return " + varName + ";"); pb("}"); return buffer.toString(); }
From source file:com.github.nmorel.gwtjackson.rebind.property.PropertyProcessor.java
License:Apache License
private static boolean isFieldAutoDetected(RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info) { if (!propertyAccessors.getField().isPresent()) { return false; }/*ww w . j a v a 2 s.c o m*/ for (Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS) { if (propertyAccessors.isAnnotationPresentOnField(annotation)) { return true; } } JField field = propertyAccessors.getField().get(); JsonAutoDetect.Visibility visibility = info.getFieldVisibility(); if (Visibility.DEFAULT == visibility) { visibility = configuration.getDefaultFieldVisibility(); } return isAutoDetected(visibility, field.isPrivate(), field.isProtected(), field.isPublic(), field.isDefaultAccess()); }
From source file:com.hiramchirino.restygwt.rebind.JsonEncoderDecoderClassCreator.java
License:Apache License
public void generate() throws UnableToCompleteException { locator = new JsonEncoderDecoderInstanceLocator(context, logger); JClassType soruceClazz = source.isClass(); if (soruceClazz == null) { error("Type is not a class"); }/*from ww w. j a v a 2 s .c om*/ if (!soruceClazz.isDefaultInstantiable()) { error("No default constuctor"); } Json jsonAnnotation = source.getAnnotation(Json.class); final Style classStyle = jsonAnnotation != null ? jsonAnnotation.style() : Style.DEFAULT; p(); p("public static final " + shortName + " INSTANCE = new " + shortName + "();"); p(); p("public " + JSON_VALUE_CLASS + " encode(" + source.getParameterizedQualifiedSourceName() + " value) {") .i(1); { p(JSON_OBJECT_CLASS + " rc = new " + JSON_OBJECT_CLASS + "();"); for (final JField field : getFields(source)) { final String getterName = getGetterName(field); // If can ignore some fields right off the back.. if (getterName == null && (field.isStatic() || field.isFinal() || field.isTransient())) { continue; } branch("Processing field: " + field.getName(), new Branch<Void>() { public Void execute() throws UnableToCompleteException { // TODO: try to get the field with a setter or JSNI if (getterName != null || field.isDefaultAccess() || field.isProtected() || field.isPublic()) { String name = field.getName(); String fieldExpr = "value." + name; if (getterName != null) { fieldExpr = "value." + getterName + "()"; } Json jsonAnnotation = field.getAnnotation(Json.class); Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle; String expression = locator.encodeExpression(field.getType(), fieldExpr, style); p("{").i(1); { p(JSON_VALUE_CLASS + " v=" + expression + ";"); p("if( v!=null ) {").i(1); { if (field.isAnnotationPresent(ExcludeNull.class)) p("if (v != " + JSONNull.class.getCanonicalName() + ".getInstance())"); p("rc.put(" + wrap(name) + ", v);"); } i(-1).p("}"); } i(-1).p("}"); } else { error("field must not be private: " + field.getEnclosingType().getQualifiedSourceName() + "." + field.getName()); } return null; } }); } p("return rc;"); } i(-1).p("}"); p(); p("public " + source.getName() + " decode(" + JSON_VALUE_CLASS + " value) {").i(1); { p(JSON_OBJECT_CLASS + " object = toObject(value);"); p("" + source.getParameterizedQualifiedSourceName() + " rc = new " + source.getParameterizedQualifiedSourceName() + "();"); for (final JField field : getFields(source)) { final String setterName = getSetterName(field); // If can ignore some fields right off the back.. if (setterName == null && (field.isStatic() || field.isFinal() || field.isTransient())) { continue; } branch("Processing field: " + field.getName(), new Branch<Void>() { public Void execute() throws UnableToCompleteException { // TODO: try to set the field with a setter or JSNI if (setterName != null || field.isDefaultAccess() || field.isProtected() || field.isPublic()) { Json jsonAnnotation = field.getAnnotation(Json.class); Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle; String name = field.getName(); String expression = locator.decodeExpression(field.getType(), "object.get(" + wrap(name) + ")", style); if (setterName != null) { p("rc." + setterName + "(" + expression + ");"); } else { p("rc." + name + "=" + expression + ";"); } } else { error("field must not be private."); } return null; } }); } p("return rc;"); } i(-1).p("}"); p(); }
From source file:fr.onevu.gwt.uibinder.rebind.UiBinderParser.java
License:Apache License
/** * Process <code><ui:import field="com.example.Blah.CONSTANT"></code>. *///from www .j av a2s . c o m private void createImport(XMLElement elem) throws UnableToCompleteException { String rawFieldName = elem.consumeRequiredRawAttribute(FIELD_ATTRIBUTE); if (elem.getAttributeCount() > 0) { writer.die(elem, "Should only find attribute \"%s\"", FIELD_ATTRIBUTE); } int idx = rawFieldName.lastIndexOf('.'); if (idx < 1) { writer.die(elem, "Attribute %s does not look like a static import " + "reference", FIELD_ATTRIBUTE); } String enclosingName = rawFieldName.substring(0, idx); String constantName = rawFieldName.substring(idx + 1); JClassType enclosingType = oracle.findType(enclosingName); if (enclosingType == null) { writer.die(elem, "Unable to locate type %s", enclosingName); } if ("*".equals(constantName)) { for (JField field : enclosingType.getFields()) { if (!field.isStatic()) { continue; } else if (field.isPublic()) { // OK } else if (field.isProtected() || field.isPrivate()) { continue; } else if (!enclosingType.getPackage().equals(writer.getOwnerClass().getOwnerType().getPackage())) { // package-protected in another package continue; } createSingleImport(elem, enclosingType, enclosingName + "." + field.getName(), field.getName()); } } else { createSingleImport(elem, enclosingType, rawFieldName, constantName); } }
From source file:it.appify.generator.WebAppGenerator.java
License:Open Source License
protected MethodSpec initializeControllers(TypeOracle typeOracle) throws ClassNotFoundException { Builder initializeControllerBuilder = MethodSpec.methodBuilder("initializeControllers") .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addAnnotation(Override.class); JClassType[] types = typeOracle.getTypes(); List<MethodSpec> handlers = new ArrayList<MethodSpec>(); for (JClassType jClassType : types) { Controller controllerAnnotation = jClassType.findAnnotationInTypeHierarchy(Controller.class); if (controllerAnnotation == null) { continue; }/* w w w. j a v a 2 s . c om*/ String pageId = controllerAnnotation.page(); Class<?> controllerClass = Class .forName(jClassType.getPackage().getName() + "." + jClassType.getSimpleSourceName()); initializeControllerBuilder.addStatement( "final $T controller" + jClassType.getSimpleSourceName() + " = new $T(this)", controllerClass, controllerClass); JMethod[] methods = jClassType.getMethods(); // scan fields JField[] fields = jClassType.getFields(); for (JField jField : fields) { ViewElement el = jField.getAnnotation(ViewElement.class); if (jField.isPublic()) { if (el != null) { String elId = el.value(); // collect all elements to inject in the controller initializeControllerBuilder.addStatement("this.bindElementToPage($S,$S)", pageId, elId); TypeSpec.Builder innerControllerBuilder = createControllerHolderBuilder(controllerClass, pageId, elId, jField.getName(), "controller" + jClassType.getSimpleSourceName(), false); controllerHolderSpecs.put("controller" + jClassType.getSimpleSourceName() + "##" + pageId, innerControllerBuilder); initializeControllerBuilders.put("controller" + jClassType.getSimpleSourceName(), initializeControllerBuilder); // initializeControllerBuilder.addStatement( // "this.bindControllerToPage($S,$L)", pageId, // innerControllerHandler); } } else if (jField.isPrivate() || jField.isProtected()) { if (el != null) { String elId = el.value(); // collect all elements to inject in the controller initializeControllerBuilder.addStatement("this.bindElementToPage($S,$S)", pageId, elId); TypeSpec.Builder innerControllerBuilder = createControllerHolderBuilder(controllerClass, pageId, elId, jField.getName(), "controller" + jClassType.getSimpleSourceName(), true); controllerHolderSpecs.put("controller" + jClassType.getSimpleSourceName() + "##" + pageId, innerControllerBuilder); initializeControllerBuilders.put("controller" + jClassType.getSimpleSourceName(), initializeControllerBuilder); // initializeControllerBuilder.addStatement( // "this.bindControllerToPage($S,$L)", pageId, // innerControllerHandler); } } } TypeSpec.Builder chb = controllerHolderSpecs .get("controller" + jClassType.getSimpleSourceName() + "##" + pageId); if (chb != null) { chb = addInjectViewElementsMethod(fields, chb); controllerHolderSpecs.put("controller" + jClassType.getSimpleSourceName() + "##" + pageId, chb); } // scan handlers boolean pageReadyAdd = false; for (JMethod jMethod : methods) { ViewHandler vhAnnotation = jMethod.getAnnotation(ViewHandler.class); ViewModelHandler vhModelAnnotation = jMethod.getAnnotation(ViewModelHandler.class); OnPageReady onPageReady = jMethod.getAnnotation(OnPageReady.class); // if (vhAnnotation == null && vhModelAnnotation == null) { // continue; // } if (vhAnnotation != null) { // initialize the view handler to be invoked when an event // occurs String eventType = vhAnnotation.eventType(); String viewId = vhAnnotation.viewId(); TypeSpec innerViewHandler = createViewHandler("controller" + jClassType.getSimpleSourceName(), jMethod.getName()); initializeControllerBuilder.addStatement( "$T holder" + pageId + "_" + viewId + " = this.createViewHandler(\"$L\",\"$L\",\"$L\",$L)", ViewHandlerHolder.class, pageId, viewId, eventType, innerViewHandler); initializeControllerBuilder.addStatement( "this.bindHandlerToPage(\"$L\", holder" + pageId + "_" + viewId + ")", pageId); } if (onPageReady != null) { if (!pageReadyAdd) { TypeSpec.Builder controllerHolderBuilder = controllerHolderSpecs .get("controller" + jClassType.getSimpleSourceName() + "##" + pageId); if (controllerHolderBuilder == null) { TypeSpec.Builder innerControllerBuilder = createControllerHolderBuilder(controllerClass, pageId, null, null, "controller" + jClassType.getSimpleSourceName(), false); controllerHolderSpecs.put( "controller" + jClassType.getSimpleSourceName() + "##" + pageId, innerControllerBuilder); // initializeControllerBuilders.put("controller" // + jClassType.getSimpleSourceName(), // initializeControllerBuilder); addInjectViewElementsMethod(null, innerControllerBuilder); controllerHolderBuilder = innerControllerBuilder; } controllerHolderBuilder = callPageReadyMethod(controllerHolderBuilder, jMethod.getName()); controllerHolderSpecs.put("controller" + jClassType.getSimpleSourceName() + "##" + pageId, controllerHolderBuilder); pageReadyAdd = true; } } else { // TypeSpec.Builder controllerHolderBuilder = // controllerHolderSpecs // .get("controller" // + jClassType.getSimpleSourceName() + "##" // + pageId); // if (controllerHolderBuilder != null) { // controllerHolderBuilder = callPageReadyMethod( // controllerHolderBuilder, ""); // controllerHolderSpecs.put( // "controller" + jClassType.getSimpleSourceName() // + "##" + pageId, // controllerHolderBuilder); // } } if (vhModelAnnotation != null) { // initialize the view model handler to be invoked when an // event on model occurs Class<?> modelType = vhModelAnnotation.modelType(); String viewId = vhModelAnnotation.viewId(); if (objectMappersInterfaces.get(modelType) == null) { TypeSpec objectMapperInterface = createObjectMapperInterface( "ObjectMapper" + modelType.getSimpleName(), modelType); objectMappersInterfaces.put(modelType, objectMapperInterface); } TypeSpec vmHandler = createViewModelHandler(jMethod, modelType, "controller" + jClassType.getSimpleSourceName()); TypeSpec vmh = createViewHandlerHolder(modelType, vmHandler); initializeControllerBuilder.addStatement("this.modelView.addViewModelHandler($S,$S,$L)", pageId, viewId, vmh); } } if (!pageReadyAdd) { TypeSpec.Builder controllerHolderBuilder = controllerHolderSpecs .get("controller" + jClassType.getSimpleSourceName() + "##" + pageId); if (controllerHolderBuilder != null) { controllerHolderBuilder = callPageReadyMethod(controllerHolderBuilder, ""); controllerHolderSpecs.put("controller" + jClassType.getSimpleSourceName() + "##" + pageId, controllerHolderBuilder); } } } Set<String> keys = controllerHolderSpecs.keySet(); for (String s : keys) { String[] splitted = s.split("##"); TypeSpec.Builder controllerHolderBuilder = controllerHolderSpecs.get(s); if (controllerHolderBuilder != null) { initializeControllerBuilder.addStatement("this.bindControllerToPage($S,$L)", splitted[1], controllerHolderBuilder.build()); } } return initializeControllerBuilder.build(); }
From source file:it.appify.generator.WebAppGenerator.java
License:Open Source License
private TypeSpec.Builder addInjectViewElementsMethod(JField[] jFields, TypeSpec.Builder controllerHolderSpec) { MethodSpec.Builder injectViewElementsBuilder = MethodSpec.methodBuilder("injectViewElements") .addAnnotation(Override.class).addModifiers(Modifier.PUBLIC); if (jFields == null || jFields.length == 0) { controllerHolderSpec.addMethod(injectViewElementsBuilder.build()); return controllerHolderSpec; }/*from w w w .java 2s.com*/ for (JField jField : jFields) { ViewElement el = jField.getAnnotation(ViewElement.class); if (jField.isPublic()) { if (el != null) { String elId = el.value(); injectViewElementsBuilder.addStatement("this.controller.$L = ($T) getViewFragment($S)", jField.getName(), Element.class, elId); } } else if (jField.isPrivate() || jField.isProtected()) { if (el != null) { String elId = el.value(); injectViewElementsBuilder.addStatement("this.controller.set$L(($T)getViewFragment($S))", StringUtils.capitalize(jField.getName()), Element.class, elId); } } } controllerHolderSpec.addMethod(injectViewElementsBuilder.build()); return controllerHolderSpec; }
From source file:org.cruxframework.crux.core.utils.JClassUtils.java
License:Apache License
/** * Verify if the given field is a visible property * @param voClass/*from w ww . j av a2s.c om*/ * @param field * @param allowProtected * @return */ public static boolean isPropertyVisibleToRead(JClassType voClass, JField field, boolean allowProtected) { if (field.isPublic() || (allowProtected && field.isProtected())) { return true; } else { return hasGetMethod(field, voClass); } }
From source file:org.cruxframework.crux.core.utils.JClassUtils.java
License:Apache License
/** * Verify if the given field is a visible property * @param voClass/*from w ww. j a v a 2 s .com*/ * @param field * @param allowProtected * @return */ public static boolean isPropertyVisibleToWrite(JClassType voClass, JField field, boolean allowProtected) { if ((field.isPublic() || (allowProtected && field.isProtected())) && !field.isFinal()) { return true; } else { return hasSetMethod(field, voClass); } }