List of usage examples for com.google.gwt.core.ext.typeinfo TypeOracle getJavaLangObject
public abstract JClassType getJavaLangObject();
java.lang.Object. From source file:org.jsonmaker.gwt.rebind.JsonizerGenerator.java
License:Apache License
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); if (!typeName.endsWith(Constants.JSONIZER_SUFFIX)) { logger.log(TreeLogger.ERROR, "Jsonizer named must be suffixed with '" + Constants.JSONIZER_SUFFIX + "'", null);/*from w w w .j av a 2 s . c om*/ throw new UnableToCompleteException(); } JClassType converterClass; try { converterClass = typeOracle.getType(typeName); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "Doesn't exists a Jsonizer for '" + typeName + "'", e); throw new UnableToCompleteException(); } if (converterClass.isClass() != null) { if (converterClass.isAbstract()) { logger.log(TreeLogger.ERROR, "Jsonizer class '" + typeName + "' cant be abstract", null); throw new UnableToCompleteException(); } return null; } String simpleBeanClassName = simpleBeanClassName(converterClass); String qualifiedBeanClassName = converterClass.getPackage().getName() + "." + simpleBeanClassName; // logger.log(TreeLogger.INFO, "buscando el bean '" + qualifiedBeanClassName + "'", null); JClassType beanClass = context.getTypeOracle().findType(qualifiedBeanClassName); String packageName = converterClass.getPackage().getName(); if (beanClass == null) { JsonizerBean beanClassAnnotation = converterClass.getAnnotation(JsonizerBean.class); if (beanClassAnnotation != null) { qualifiedBeanClassName = beanClassAnnotation.value(); beanClass = context.getTypeOracle().findType(qualifiedBeanClassName); packageName = beanClass.getPackage().getName(); } else { logger.log(TreeLogger.ERROR, "Class '" + qualifiedBeanClassName + "' not found but Jsonizer found. Please use Jsonizer bean annotation if both jsonizer and the bean are not in the same package", null); throw new UnableToCompleteException(); } } JClassType superBeanClass = beanClass.getSuperclass(); // Verificacion de que los conversores de superclase implementen BeanJ2BConverter // si el bean no es subclase de object if (!superBeanClass.equals(typeOracle.getJavaLangObject())) { String superConverterName = packageName + "." + RebindUtils.jsonizerSimpleName(superBeanClass); JClassType superConverter = typeOracle.findType(superConverterName); //si el superconverter esta definido if (superConverter != null) { // si el super converter es clase if (superConverter.isClass() != null) { if (superConverter.isAbstract()) { logger.log(TreeLogger.ERROR, "An user defined Jsonizer is abstract: '" + superConverter.getQualifiedSourceName() + "'", null); throw new UnableToCompleteException(); } JClassType beanConverterClass = typeOracle.findType(Constants.BEAN_JSONIZER_CLASS); if (beanConverterClass == null) { logger.log(TreeLogger.ERROR, "'" + Constants.BEAN_JSONIZER_CLASS + "' class not found", null); throw new UnableToCompleteException(); } if (!superConverter.isAssignableTo(beanConverterClass)) { logger.log(TreeLogger.ERROR, "Super Jsonizer for '" + beanClass.getQualifiedSourceName() + "' class doesn't extends '" + Constants.BEAN_JSONIZER_CLASS + "' class", null); throw new UnableToCompleteException(); } } } } String simpleStubClassName = RebindUtils.simpleStubClassName(converterClass); String qualifiedStubClassName = packageName + "." + simpleStubClassName; SourceWriter swBean = getSourceWriter(logger, context, packageName, simpleBeanClassName); SourceWriter sw = getSourceWriter(logger, context, packageName, simpleStubClassName, converterClass.getQualifiedSourceName()); if (sw == null) { return qualifiedStubClassName; } JsonizerWriter converterWriter = new JsonizerWriter(logger, context, sw, beanClass); converterWriter.writeMethods(); sw.commit(logger); return qualifiedStubClassName; }