List of usage examples for com.google.gwt.core.ext.typeinfo JClassType getOracle
TypeOracle getOracle();
From source file:com.eleven.rebind.SkinBundleGenerator.java
License:Apache License
/** * Generates the image bundle implementation class, checking each method for * validity as it is encountered.// w ww . j a v a2s .c o m */ private String generateImplClass(final TreeLogger logger, final GeneratorContext context, final JClassType userType, final JMethod[] imageMethods) throws UnableToCompleteException { // Lookup the type info for AbstractImagePrototype so that we can check // for // the proper return type // on image bundle methods. final JClassType abstractImagePrototype; try { abstractImagePrototype = userType.getOracle().getType(ABSTRACTIMAGEPROTOTYPE_QNAME); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "GWT " + ABSTRACTIMAGEPROTOTYPE_QNAME + " class is not available", e); throw new UnableToCompleteException(); } // Compute the package and class names of the generated class. String pkgName = userType.getPackage().getName(); String subName = computeSubclassName(userType); // 11pc String pkgPrefix = pkgName.replace('.', '/'); if (pkgPrefix.length() > 0) pkgPrefix += "/"; // Begin writing the generated source. ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(pkgName, subName); f.addImport(ABSTRACTIMAGEPROTOTYPE_QNAME); f.addImport(CLIPPEDIMAGEPROTOTYPE_QNAME); f.addImport(GWT_QNAME); f.addImport(HASHMAP_QNAME); f.addImport(IMAGE_QNAME); f.addImplementedInterface(userType.getQualifiedSourceName()); PrintWriter pw = context.tryCreate(logger, pkgName, subName); if (pw != null) { SourceWriter sw = f.createSourceWriter(context, pw); // Build a compound image from each individual image. SkinBundleBuilder bulder = new SkinBundleBuilder(); // Store the computed image names so that we don't have to lookup // them up again. // 11pc List<String> imageResNames = getSkinImages(logger); for (String imageName : imageResNames) bulder.assimilate(logger, imageName); /* for (JMethod method : imageMethods) { String branchMsg = "Analyzing method '" + method.getName() + "' in type " + userType.getQualifiedSourceName(); TreeLogger branch = logger.branch(TreeLogger.DEBUG, branchMsg, null); // Verify that this method is valid on an image bundle. if (method.getReturnType() != abstractImagePrototype) { branch.log(TreeLogger.ERROR, "Return type must be " + ABSTRACTIMAGEPROTOTYPE_QNAME, null); throw new UnableToCompleteException(); } if (method.getParameters().length > 0) { branch.log(TreeLogger.ERROR, "Method must have zero parameters", null); throw new UnableToCompleteException(); } // Find the associated imaged resource. String imageResName = getImageResourceName(branch, new JMethodOracleImpl(method)); assert (imageResName != null); imageResNames.add(imageResName); bulder.assimilate(logger, imageResName); } */ // Write the compound image into the output directory. // String bundledImageUrl = bulder.writeBundledImage(logger, context); String bundledImageUrl = "yeayeaa"; // Emit a constant for the composite URL. Note that we prepend the // module's base URL so that the module can reference its own // resources // independently of the host HTML page. sw.print("private static final String IMAGE_BUNDLE_URL = GWT.getModuleBaseURL() + \""); sw.print(escape(bundledImageUrl)); sw.println("\";"); /* // Generate an implementation of each method. int imageResNameIndex = 0; for (JMethod method : imageMethods) { generateImageMethod(bulder, sw, method, imageResNames .get(imageResNameIndex++)); } */ generateImageDef(bulder, sw, imageResNames); sw.println("@Override"); sw.println("public AbstractImagePrototype get(String image) {"); sw.indent(); sw.println("return imageMap.get(image);"); sw.outdent(); sw.print("}"); sw.println("@Override"); sw.println("public HashMap<String, HashMap<String, String>> getProperties() {"); sw.indent(); sw.println("return null;"); sw.outdent(); sw.print("}"); // Finish. sw.commit(logger); } return f.getCreatedClassName(); }
From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java
License:Apache License
public AutoBeanFactoryModel(TreeLogger logger, JClassType factoryType) throws UnableToCompleteException { this.logger = logger; oracle = factoryType.getOracle(); autoBeanInterface = oracle.findType(AutoBean.class.getCanonicalName()).isGenericType(); autoBeanFactoryInterface = oracle.findType(AutoBeanFactory.class.getCanonicalName()).isInterface(); /*/*from www .ja v a 2s . c o m*/ * We want to allow the user to override some of the useful Object methods, * so we'll extract them here. */ JClassType objectType = oracle.getJavaLangObject(); objectMethods = Arrays.asList(objectType.findMethod("equals", new JType[] { objectType }), objectType.findMethod("hashCode", EMPTY_JTYPE), objectType.findMethod("toString", EMPTY_JTYPE)); // Process annotations { Category categoryAnnotation = factoryType.getAnnotation(Category.class); if (categoryAnnotation != null) { categoryTypes = new ArrayList<JClassType>(categoryAnnotation.value().length); processClassArrayAnnotation(categoryAnnotation.value(), categoryTypes); } else { categoryTypes = null; } noWrapTypes = new ArrayList<JClassType>(); noWrapTypes.add(oracle.findType(AutoBean.class.getCanonicalName())); NoWrap noWrapAnnotation = factoryType.getAnnotation(NoWrap.class); if (noWrapAnnotation != null) { processClassArrayAnnotation(noWrapAnnotation.value(), noWrapTypes); } ExtraEnums extraEnumsAnnotation = factoryType.getAnnotation(ExtraEnums.class); if (extraEnumsAnnotation != null) { for (Class<?> clazz : extraEnumsAnnotation.value()) { JEnumType asEnum = oracle.findType(clazz.getCanonicalName()).isEnum(); assert asEnum != null; for (JEnumConstant value : asEnum.getEnumConstants()) { allEnumConstants.put(value, AutoBeanMethod.getEnumName(value)); } } } } for (JMethod method : factoryType.getOverridableMethods()) { if (method.getEnclosingType().equals(autoBeanFactoryInterface)) { // Ignore methods in AutoBeanFactory continue; } JClassType returnType = method.getReturnType().isInterface(); if (returnType == null) { poison("The return type of method %s is a primitive type", method.getName()); continue; } // AutoBean<FooIntf> blah() --> beanType = FooIntf JClassType beanType = ModelUtils.findParameterizationOf(autoBeanInterface, returnType)[0]; if (beanType.isInterface() == null) { poison("The %s parameterization is not an interface", beanType.getQualifiedSourceName()); continue; } // AutoBean<FooIntf> blah(FooIntfSub foo) --> toWrap = FooIntfSub JClassType toWrap; if (method.getParameters().length == 0) { toWrap = null; } else if (method.getParameters().length == 1) { toWrap = method.getParameters()[0].getType().isClassOrInterface(); if (!beanType.isAssignableFrom(toWrap)) { poison("The %s parameterization %s is not assignable from the delegate" + " type %s", autoBeanInterface.getSimpleSourceName(), toWrap.getQualifiedSourceName()); continue; } } else { poison("Unexpecetd parameters in method %s", method.getName()); continue; } AutoBeanType autoBeanType = getAutoBeanType(beanType); // Must wrap things that aren't simple interfaces if (!autoBeanType.isSimpleBean() && toWrap == null) { if (categoryTypes != null) { poison("The %s parameterization is not simple and the following" + " methods did not have static implementations:", beanType.getQualifiedSourceName()); for (AutoBeanMethod missing : autoBeanType.getMethods()) { if (missing.getAction().equals(JBeanMethod.CALL) && missing.getStaticImpl() == null) { poison(missing.getMethod().getReadableDeclaration()); } } } else { poison("The %s parameterization is not simple, but the %s method" + " does not provide a delegate", beanType.getQualifiedSourceName(), method.getName()); } continue; } AutoBeanFactoryMethod.Builder builder = new AutoBeanFactoryMethod.Builder(); builder.setAutoBeanType(autoBeanType); builder.setMethod(method); methods.add(builder.build()); } while (!toCalculate.isEmpty()) { Set<JClassType> examine = toCalculate; toCalculate = new LinkedHashSet<JClassType>(); for (JClassType beanType : examine) { getAutoBeanType(beanType); } } if (poisoned) { die("Unable to complete due to previous errors"); } }
From source file:com.google.web.bindery.requestfactory.gwt.rebind.model.RequestFactoryModel.java
License:Apache License
public RequestFactoryModel(TreeLogger logger, JClassType factoryType) throws UnableToCompleteException { this.logger = logger; this.factoryType = factoryType; this.oracle = factoryType.getOracle(); collectionInterface = oracle.findType(Collection.class.getCanonicalName()); entityProxyInterface = oracle.findType(EntityProxy.class.getCanonicalName()); instanceRequestInterface = oracle.findType(InstanceRequest.class.getCanonicalName()); listInterface = oracle.findType(List.class.getCanonicalName()); mapInterface = oracle.findType(Map.class.getCanonicalName()); requestContextInterface = oracle.findType(RequestContext.class.getCanonicalName()); requestFactoryInterface = oracle.findType(RequestFactory.class.getCanonicalName()); requestInterface = oracle.findType(Request.class.getCanonicalName()); setInterface = oracle.findType(Set.class.getCanonicalName()); splittableType = oracle.findType(Splittable.class.getCanonicalName()); valueProxyInterface = oracle.findType(ValueProxy.class.getCanonicalName()); extraTypes = checkExtraTypes(factoryType, false); for (JMethod method : factoryType.getOverridableMethods()) { if (method.getEnclosingType().equals(requestFactoryInterface)) { // Ignore methods defined an RequestFactory itself continue; }//from w w w .j ava2 s. c o m if (method.getParameters().length > 0) { poison("Unexpected parameter on method %s", method.getName()); continue; } JClassType contextType = method.getReturnType().isInterface(); if (contextType == null || !requestContextInterface.isAssignableFrom(contextType)) { poison("Unexpected return type %s on method %s is not" + " an interface assignable to %s", method.getReturnType().getQualifiedSourceName(), method.getName(), requestContextInterface.getSimpleSourceName()); continue; } ContextMethod.Builder builder = new ContextMethod.Builder(); builder.setDeclaredMethod(method); buildContextMethod(builder, contextType); contextMethods.add(builder.build()); } if (poisoned) { die(poisonedMessage()); } }
From source file:com.seanchenxi.gwt.storage.rebind.StorageKeyProviderModel.java
License:Apache License
public StorageKeyProviderModel(TreeLogger logger, JClassType providerType) { this.providerType = providerType; this.storageKeyGenericType = providerType.getOracle().findType(StorageKey.class.getCanonicalName()) .isGenericType();/*from w w w .ja v a2s.co m*/ this.serializableIntf = providerType.getOracle().findType(Serializable.class.getCanonicalName()) .isInterface(); this.isSerializableIntf = providerType.getOracle().findType(IsSerializable.class.getCanonicalName()) .isInterface(); this.methods = new ArrayList<>(); this.logger = logger; }
From source file:com.smartgwt.rebind.BeanClass.java
License:Open Source License
public BeanClass(JClassType beanClassType) { this.beanClassType = beanClassType; this.typeOracle = beanClassType.getOracle(); final JClassType baseWidgetType = typeOracle.findType(BaseWidget.class.getCanonicalName()); final JClassType dataClassType = typeOracle.findType(DataClass.class.getCanonicalName()); if (beanClassType.isAssignableTo(baseWidgetType)) { this.factoryClass = typeOracle.findType(BeanFactoryForBaseWidget.class.getCanonicalName()); } else if (beanClassType.isAssignableTo(dataClassType)) { this.factoryClass = typeOracle.findType(BeanFactoryForDataClass.class.getCanonicalName()); }/* w w w. j a v a 2 s .com*/ // We'll look for superclasses up to BaseWidget or DataClass, and make sure that we // generate factories for them as well. That way, we can keep track of // just our own properties. if (beanClassType != baseWidgetType && beanClassType != dataClassType) { JClassType beanSuperclassType = this.beanClassType.getSuperclass(); if (beanSuperclassType != null) { this.superclass = new BeanClass(beanSuperclassType); } } // We use a TreeMap to sort the properties ... not really necessary, // but it's nice for debugging! properties = new TreeMap<String, BeanProperty>(); methods = new LinkedList<BeanMethod>(); // Iterate through our methods, and create properties from them for (JMethod method : beanClassType.getMethods()) { BeanMethod beanMethod = new BeanMethod(method, typeOracle); String propertyName = beanMethod.getName(); if (beanMethod.isStaticInitMethod()) hasStaticInitMethod = true; if (!excludedPropertyNames.contains(propertyName)) { if (beanMethod.isGetter() || beanMethod.isSetter()) { BeanProperty property = properties.get(propertyName); if (property == null) { property = new BeanProperty(propertyName, this); properties.put(propertyName, property); } // This will call back to add the method to our global list as well property.addMethod(beanMethod); } } } // Now that we have our properties, iterate through them and make a few // adjustments We create a list for new properties, since we can't // modify the properties HashMap while iterating through it. LinkedList<BeanProperty> additionalProperties = new LinkedList<BeanProperty>(); for (BeanProperty property : properties.values()) { // Check if a superclass has the same property. If so, copy its // methods here if they are not overridden. This simplifies the // run-time logic -- if the property is here, we can just use it, // and if it's not, we check the superclasses. But we don't have to // consolidate methods at run-time. // // Essentially, this deals with the case where a subclass overrides // one overloaded method but not others. BeanProperty superProperty = findPropertyInSuperclass(property.getName()); if (superProperty != null) property.mergeProperty(superProperty); // If the name might be overloaded (e.g. getWidthAsString), then // check whether we have the unoverloaded property, or a superclass // does. If so, merge the overloaded property into the main // property. Note that we don't delete the overloaded property, so // it still can be used separately (though with limited types -- we // don't merge the main property into the overloaded property). if (property.getMaybeOverloadedGetter()) { BeanProperty mainProperty = properties.get(property.getNameWithoutOverload()); if (mainProperty == null) { // If no main property, check superclasses as well. superProperty = findPropertyInSuperclass(property.getNameWithoutOverload()); if (superProperty != null) { // If there is a superclass property, then create a new // property here for the overload and then merge the // superProperty. If there is no superclass property // either, then we just leave things alone. mainProperty = new BeanProperty(property.getNameWithoutOverload(), this); // We need to add the first getter of the super property first, // because that will be the default getter. mainProperty.addMethod(superProperty.firstGetter()); // For the rest, merge the overloaded property first, // so it has priority over the superProperty mainProperty.mergeProperty(property); mainProperty.mergeProperty(superProperty); // Add it to the list of additional properties, since we can't modify the // properties HashMap while we're iterating over it. additionalProperties.add(mainProperty); } } else { // If there already was a mainProperty, then just merge the // overloaded methods mainProperty.mergeProperty(property); } } } // If we created any additionalProperties, add them now that iteration is done for (BeanProperty additionalProperty : additionalProperties) { properties.put(additionalProperty.getName(), additionalProperty); } }
From source file:com.vaadin.server.widgetsetutils.metadata.ConnectorBundle.java
License:Apache License
private void checkSerializable(TreeLogger logger, JClassType type) throws UnableToCompleteException { JClassType javaSerializable = type.getOracle().findType(Serializable.class.getName()); boolean serializable = type.isAssignableTo(javaSerializable); if (!serializable) { boolean abortCompile = "true".equals(System.getProperty(FAIL_IF_NOT_SERIALIZABLE)); logger.log(abortCompile ? Type.ERROR : Type.WARN, type + " is used in RPC or shared state but does not implement " + Serializable.class.getName() + ". Communication will work but the Application on server side cannot be serialized if it refers to objects of this type. " + "If the system property " + FAIL_IF_NOT_SERIALIZABLE + " is set to \"true\", this causes the compilation to fail instead of just emitting a warning."); if (abortCompile) { throw new UnableToCompleteException(); }/*from ww w .ja v a2s .c o m*/ } }
From source file:com.vaadin.server.widgetsetutils.metadata.ConnectorBundle.java
License:Apache License
private static boolean isType(JClassType type, Class<?> class1) { try {/*from w w w . j a v a2 s.c o m*/ return type.getOracle().getType(class1.getName()).isAssignableFrom(type); } catch (NotFoundException e) { throw new RuntimeException("Could not find " + class1.getName(), e); } }
From source file:de.csenk.gwt.commons.bean.rebind.observe.ObservableBeanFactoryModel.java
License:Apache License
/** * @param logger//from w ww .j a va 2s . c om * @param sourceType * @return * @throws UnableToCompleteException */ public static ObservableBeanFactoryModel create(TreeLogger logger, JClassType sourceType) throws UnableToCompleteException { final TypeOracle oracle = sourceType.getOracle(); final JGenericType beanBaseInterface = oracle.findType(ObservableBean.class.getCanonicalName()) .isGenericType(); final JClassType beanFactoryBaseInterface = oracle.findType(ObservableBeanFactory.class.getCanonicalName()) .isInterface(); final Set<ObservableBeanFactoryMethodModel> beanFactoryMethods = modelBeanFactoryMethods(logger, beanBaseInterface, beanFactoryBaseInterface, sourceType); final Map<JClassType, ObservableBeanModel> beans = modelBeans(beanFactoryMethods); return new ObservableBeanFactoryModel(beanBaseInterface, beanFactoryBaseInterface, beanFactoryMethods, beans); }
From source file:de.csenk.gwt.commons.bean.rebind.observe.ObservableBeanModel.java
License:Apache License
/** * @param logger /*from w ww. j a va 2s .com*/ * @param type * @return * @throws UnableToCompleteException */ public static ObservableBeanModel create(TreeLogger logger, JClassType type) throws UnableToCompleteException { final String topLevelTypeName = type.getName().replace('.', '_'); final String simpleImplementationTypeName = topLevelTypeName + "ObservableBean"; final String packageName = type.getPackage().getName(); final String qualifiedImplementationTypeName = packageName + "." + simpleImplementationTypeName; final Set<ObservableBeanMethodModel> methods = modelMethods(type); final Map<String, ObservableBeanPropertyModel> properties = modelProperties(logger, methods, type.getOracle()); return new ObservableBeanModel(type, topLevelTypeName, simpleImplementationTypeName, qualifiedImplementationTypeName, methods, properties); }
From source file:org.cruxframework.crux.core.rebind.screen.binder.ViewBinderProxyCreator.java
License:Apache License
/** * Constructor// w w w . j a v a 2 s .c om * @param logger * @param context */ public ViewBinderProxyCreator(TreeLogger logger, GeneratorContext context, JClassType invokerIntf) { super(logger, context, invokerIntf); try { viewBinderType = invokerIntf.getOracle().getType(ViewBinder.class.getCanonicalName()); stringType = invokerIntf.getOracle().getType(String.class.getCanonicalName()); } catch (NotFoundException e) { throw new CruxGeneratorException(e.getMessage(), e); } }