/** * Create a primitive type reference (for code generation) using the given * primitive type name. * * @param name * the name of a primitive Java type * @param owner * the current code model for type generation * @return a type reference created by the given owner */ public static JPrimitiveType primitiveType(String name, JCodeModel owner) { try { return (JPrimitiveType) owner.parseType(name); } catch (ClassNotFoundException e) { throw new GenerationException( "Given name does not refer to a primitive type, this type can't be found: " + name, e); } }
public final JType parseType( final String s ) throws ClassNotFoundException { return (JClass) codeModel.parseType( s ); }
static private JClass parseType(Map<String, JClass> typeCache, JCodeModel codeModel, String name){ JClass type = typeCache.get(name); if(type == null){ try { type = (JClass)codeModel.parseType(name); } catch(ClassNotFoundException cnfe){ throw new RuntimeException(cnfe); } typeCache.put(name, type); } return type; }
static private JType toType(JCodeModel codeModel, TypeMirror typeMirror){ String name = typeMirror.toString(); if(name.endsWith("Value<?>")){ name = name.substring(0, name.length() - "Value<?>".length()) + "Value<? extends java.lang.Number>"; } try { return codeModel.parseType(name); } catch(ClassNotFoundException cnfe){ throw new RuntimeException(cnfe); } }
private JType getType(TypeMirror typeMirror) { String type = typeMirror.toString(); try { // System.out.println("typeName: "+typeName); return cm.parseType(type); // System.out.println("type: "+type); } catch (ClassNotFoundException e) { return cm.ref(type); } }
private JType getType(TypeMirror typeMirror) { String type = typeMirror.toString(); try { // System.out.println("typeName: "+typeName); return cm.parseType(type); // System.out.println("type: "+type); } catch (ClassNotFoundException e) { return cm.ref(type); } }
public JType toType(Outline o, Aspect aspect) { try { return o.getCodeModel().parseType(t.toString()); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } }
public JType toType(Outline o, Aspect aspect) { try { return o.getCodeModel().parseType(t.toString()); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } }
private JType getType(TypeMirror typeMirror) { String type = typeMirror.toString(); try { // System.out.println("typeName: "+typeName); return cm.parseType(type); // System.out.println("type: "+type); } catch (ClassNotFoundException e) { return cm.ref(type); } }
public JType toType(Outline o, Aspect aspect) { try { return o.getCodeModel().parseType(t.toString()); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } }
public JType toType(Outline o, Aspect aspect) { try { return o.getCodeModel().parseType(t.toString()); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } }
public JType toType(Outline o, Aspect aspect) { try { return o.getCodeModel().parseType(t.toString()); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } }
private JType getType(TypeMirror typeMirror) { String type = typeMirror.toString(); try { // System.out.println("typeName: "+typeName); return cm.parseType(type); // System.out.println("type: "+type); } catch (ClassNotFoundException e) { return cm.ref(type); } }
/** * Obtains a {@link JType} object for the string representation * of a type. */ public static JType getType( JCodeModel codeModel, String typeName, ErrorReceiver errorHandler, Locator errorSource ) { try { return codeModel.parseType(typeName); } catch( ClassNotFoundException ee ) { // make it a warning errorHandler.warning( new SAXParseException( Messages.ERR_CLASS_NOT_FOUND.format(typeName) ,errorSource)); // recover by assuming that it's a class that derives from Object return codeModel.directClass(typeName); } }
/** * Obtains a {@link JType} object for the string representation * of a type. */ public static JType getType( JCodeModel codeModel, String typeName, ErrorReceiver errorHandler, Locator errorSource ) { try { return codeModel.parseType(typeName); } catch( ClassNotFoundException ee ) { // make it a warning errorHandler.warning( new SAXParseException( Messages.ERR_CLASS_NOT_FOUND.format(typeName) ,errorSource)); // recover by assuming that it's a class that derives from Object return codeModel.directClass(typeName); } }
/** * Obtains a {@link JType} object for the string representation * of a type. */ public static JType getType( JCodeModel codeModel, String typeName, ErrorReceiver errorHandler, Locator errorSource ) { try { return codeModel.parseType(typeName); } catch( ClassNotFoundException ee ) { // make it a warning errorHandler.warning( new SAXParseException( Messages.ERR_CLASS_NOT_FOUND.format(typeName) ,errorSource)); // recover by assuming that it's a class that derives from Object return codeModel.directClass(typeName); } }
/** * Obtains a {@link JType} object for the string representation * of a type. */ public static JType getType( JCodeModel codeModel, String typeName, ErrorReceiver errorHandler, Locator errorSource ) { try { return codeModel.parseType(typeName); } catch( ClassNotFoundException ee ) { // make it a warning errorHandler.warning( new SAXParseException( Messages.ERR_CLASS_NOT_FOUND.format(typeName) ,errorSource)); // recover by assuming that it's a class that derives from Object return codeModel.directClass(typeName); } }
private void renderFutureElementsField(JDefinedClass classModel) throws Exception { JType collectionType = codeModel.parseType("java.util.Collection<org.w3c.dom.Element>"); JFieldVar field = classModel.field(JMod.PRIVATE | JMod.FINAL, collectionType, "_futureElements"); field.init(JExpr._null()); JAnnotationUse annotation = field.annotate(SuppressWarnings.class); annotation.param("value", "unused"); field.annotate(XmlAnyElement.class); }
protected JType _type(final String type, final String... generics) { ensureThatArgument(type, notNull()); if (generics.length == 0) { try { return this.codeModel.parseType(type); } catch (final ClassNotFoundException exception) { return this.codeModel.ref(type); } } final JClass[] classes = ArrayUtilities.convert(new IConverter<String, JClass, RuntimeException>() { @Override public JClass convert(final String input) throws RuntimeException { return AbstractSourceFactory.this.codeModel.ref(input); } }, generics, JClass.class); return this.codeModel.ref(type).narrow(classes); }
public JType type(ASTType astType){ try { return codeModel.parseType(astType.getName()); } catch (ClassNotFoundException e) { validator.error("Unable to parse type " + astType.getName()).element(astType).build(); throw new TransfuseAnalysisException("Unable to parse type " + astType.getName(), e); } catch (ExceptionInInitializerError e){ // Tried to initialize an Android class return codeModel.directClass(astType.getName()); } catch (NoClassDefFoundError e){ return codeModel.directClass(astType.getName()); } }