Refine search
private JDefinedClass createEnum(JsonNode node, String nodeName, JClassContainer container) throws ClassAlreadyExistsException { try { if (node.has("javaType")) { String fqn = node.get("javaType").asText(); if (isPrimitive(fqn, container.owner())) { throw new GenerationException("Primitive type '" + fqn + "' cannot be used as an enum."); } try { Class<?> existingClass = Thread.currentThread().getContextClassLoader().loadClass(fqn); throw new ClassAlreadyExistsException(container.owner().ref(existingClass)); } catch (ClassNotFoundException e) { return container.owner()._class(fqn, ClassType.ENUM); } } else { try { return container._class(JMod.PUBLIC, getEnumName(nodeName, node, container), ClassType.ENUM); } catch (JClassAlreadyExistsException e) { throw new GenerationException(e); } } } catch (JClassAlreadyExistsException e) { throw new ClassAlreadyExistsException(e.getExistingClass()); } }
@Override public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray("value"); clazz.annotate(JsonDeserialize.class) .param("using", JsonDeserializer.None.class); clazz.annotate(ToString.class); clazz.annotate(EqualsAndHashCode.class); try { .param("builderPackage", "io.fabric8.kubernetes.api.builder") .annotationParam("inline", Inline.class) .param("type", new JCodeModel()._class("io.fabric8.kubernetes.api.model.Doneable")) .param("prefix", "Doneable") .param("value", "done"); e.printStackTrace();
public TypeUse getTypeUse(XSSimpleType owner) { if(typeUse!=null) return typeUse; JCodeModel cm = getCodeModel(); JDefinedClass a; try { a = cm._class(adapter); a.hide(); // we assume this is given by the user a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow( cm.ref(type))); } catch (JClassAlreadyExistsException e) { a = e.getExistingClass(); } // TODO: it's not correct to say that it adapts from String, // but OTOH I don't think we can compute that. typeUse = TypeUseFactory.adapt( CBuiltinLeafInfo.STRING, new CAdapter(a)); return typeUse; } }
JDefinedClass jc = codeModel.rootPackage()._class("JAXBDebug"); JMethod m = jc.method(JMod.PUBLIC|JMod.STATIC,JAXBContext.class,"createContext"); JVar $classLoader = m.param(ClassLoader.class,"classLoader"); m._throws(JAXBException.class); JInvocation inv = codeModel.ref(JAXBContext.class).staticInvoke("newInstance"); m.body()._return(inv); inv.arg(cc.implRef.dotclass()); for( PackageOutlineImpl po : packageContexts.values() ) inv.arg(po.objectFactory().dotclass()); break; default: e.printStackTrace();
while (!(owningClass.parentContainer() instanceof JPackage)) { owningClass = (JDefinedClass) owningClass.parentContainer(); JDefinedClass $exception = owningClass._class(JMod.PRIVATE | JMod.STATIC, "WebApplicationExceptionMessage"); $exception._extends(codeModel.ref(WebApplicationException.class)); $exception.javadoc().append("Workaround for JAX_RS_SPEC-312"); JClass $responseClass = codeModel.ref(Response.class); JMethod $toString = $exception.method(JMod.PUBLIC, String.class, "toString"); JBlock $body = $toString.body(); JVar $s = $body.decl(codeModel.ref(String.class), "s", JExpr.lit(WebApplicationException.class.getName())); return ex.getExistingClass();
JCodeModel codeModel = new JCodeModel(); router = codeModel._class(packagePrefix + ".routes"); } catch (JClassAlreadyExistsException e) { e.printStackTrace(); System.exit(-1); radioRouter = codeModel._class(packagePrefix + ".Radio"); } catch (JClassAlreadyExistsException e) { e.printStackTrace(); System.exit(-1); radioRouterGenerator.build(radioRouteClassList); JMethod radioMethod = router.method(JMod.PUBLIC | JMod.STATIC, radioRouter, "radio"); radioMethod.body().directStatement("return new " + radioRouter.name() + "();");
JDefinedClass getClazz(ClassType t) { if (clazz != null) return clazz; try { JCodeModel codeModel = Ring.get(JCodeModel.class); clazz = codeModel._class(name, t); clazz.hide(); return clazz; } catch (JClassAlreadyExistsException e) { return e.getExistingClass(); } } }
enumUserTypeClass = enumClass._class(JMod.PUBLIC + JMod.STATIC, "Type"); } catch (JClassAlreadyExistsException ex) { return ex.getExistingClass(); Aspect.EXPOSED).boxify(); enumUserTypeClass._extends(codeModel.ref(EnumUserType.class).narrow( new JClass[] { enumClass, identifierClass })); final JMethod getIdentifierClass = enumUserTypeClass.method( JMod.PUBLIC, Class.class, "getIdentifierClass"); getIdentifierClass.body()._return(identifierClass.staticRef("class"));
private void annotateMetatadataValidator(JDefinedClass clazz) { if (clazz.name().equals("PodTemplateSpec")) { return; } for (Map.Entry<String, JFieldVar> f : clazz.fields().entrySet()) { if (f.getKey().equals("metadata") && f.getValue().type().name().equals("ObjectMeta")) { try { JAnnotationUse annotation = f.getValue().annotate(new JCodeModel()._class("io.fabric8.kubernetes.api.model.validators.CheckObjectMeta")); if (isMinimal(clazz)) { annotation.param("minimal", true); } else { annotation .param("regexp", "^" + getObjectNamePattern(clazz) + "$") .param("max", getObjectNameMaxLength(clazz)); } } catch (JClassAlreadyExistsException e) { e.printStackTrace(); } return; } } }
JDefinedClass $enum; try { $enum = parentClass._package()._enum(makeClassName(param.getName())); javaDoc.generateEnumDoc(param, $enum); for (Option o: param.getOption()) { JEnumConstant c = $enum.enumConstant(makeConstantName(o.getValue())); c.arg(JExpr.lit(o.getValue())); javaDoc.generateEnumConstantDoc(o, c); JFieldVar $stringVal = $enum.field(JMod.PRIVATE, String.class, "stringVal"); JMethod $ctor = $enum.constructor(JMod.PRIVATE); JVar $val = $ctor.param(String.class, "v"); $toString.body()._return($stringVal); } catch (JClassAlreadyExistsException ex) { $enum = ex.getExistingClass(); type = QName.class; return (JClass)model._ref(type);
} catch( JClassAlreadyExistsException e ) { JDefinedClass cls = e.getExistingClass(); Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ), (Locator)cls.metadata )); errorReceiver.error( new SAXParseException( source )); if( !name.equals(cls.name()) ) { name, cls.name() ), null ) );
public void execute() throws MojoExecutionException, MojoFailureException { try { JCodeModel codeModel = new JCodeModel(); for (Resource res: project.getBuild().getResources()) { walk(new File(res.getDirectory()),codeModel.rootPackage(),""); codeModel.build(w); project.getCompileSourceRoots().add(outputDirectory.getAbsolutePath()); } catch (IOException e) { throw new MojoExecutionException("Failed to generate taglib type interface",e); } catch (JClassAlreadyExistsException e) { throw new MojoExecutionException("Duplicate class: "+e.getExistingClass().fullName(),e);
public JDefinedClass generate(RouteClass routeClass) { JDefinedClass definedClass; try { definedClass = codeModel._class(packagePrefix + "." + routeClass.getKlazz().getSimpleName()); } catch (JClassAlreadyExistsException e) { System.out.println("Class " + routeClass.getKlazz().getSimpleName() + " already exists"); e.printStackTrace(); return null; } for (Route route : routeClass.getRoutes()) { JMethod method = definedClass.method(JMod.PUBLIC, PathMethod.class, route.getMethod().getName()); String path = route.getPath(); for (Map.Entry<PathParam, Class<?>> entry : route.getPathParams().entrySet()) { String fieldName = entry.getKey().value(); method.param(entry.getValue(), fieldName); path = path.replaceAll("\\{" + fieldName + "(:?[^}]*)\\}", "\"+com.google.common.net.UrlEscapers.urlPathSegmentEscaper().escape(" + fieldName + ")+\""); } JBlock block = method.body(); block.directStatement("return new PathMethod(\"" + route.getHttpMethod() + "\", \"" + path + "\");"); } return definedClass; } }
public JDefinedClass generate(ResourceSchema resource, File sourceFile, String rootPath) { _currentSourceFile = sourceFile; try { return generateResourceFacade(resource, sourceFile, new HashMap<String, JClass>(), new HashMap<String, JClass>(), new HashMap<String, List<String>>(), rootPath); } catch (JClassAlreadyExistsException e) { // should never occur throw new IllegalStateException("Unexpected exception parsing " + sourceFile + ", " + e.getExistingClass().fullName() + " exists", e); } catch (JsonParseException e) { throw new IllegalArgumentException("Error parsing json file [" + sourceFile.getAbsolutePath() + "] [" + e.getMessage() + ']', e); } catch (IOException e) { throw new RuntimeException("Error processing file [" + sourceFile.getAbsolutePath() + ']' + e.getMessage(), e); } }
newType = _package.owner()._class(JMod.PUBLIC, fqn, ClassType.CLASS); } else { newType = _package.owner()._class(fqn); throw new ClassAlreadyExistsException(e.getExistingClass());
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException { String NAME; if (JCodeModel.isCaseSensitiveFileSystem) NAME = name.toUpperCase(); else NAME = name; if (getClasses().containsKey(NAME)) throw new JClassAlreadyExistsException(getClasses().get(NAME)); else { // XXX problems caught in the NC constructor JDefinedClass c = new JDefinedClass(this, mods, name, classTypeVal); getClasses().put(NAME,c); return c; } }
/** * Creates or returnes existing object validator factory class for given package. * * @param thePackage the package. * @return Object validator factory. */ public static JDefinedClass generateObjectValidatorFactoryClass(final JPackage thePackage) { try { final JDefinedClass objectValidatorFactory = thePackage._class( JMod.PUBLIC, "ObjectValidatorFactory"); objectValidatorFactory ._extends(org.jvnet.jaxbvalidation.validator.AbstractObjectValidatorFactory.class); return objectValidatorFactory; } catch (JClassAlreadyExistsException jcaeex) { return jcaeex.getExistingClass(); } }
public static JDefinedClass getOrCreateClass(JClassContainer container, int flags, String name) { try { return container._class(flags, name); } catch (JClassAlreadyExistsException jcaeex) { return jcaeex.getExistingClass(); } }
@NotNull private JDefinedClass createAnonListClass(JFieldVar field, ClassOutline classOutline) { JDefinedClass anonymous; try { CPropertyInfo propertyInfo = classOutline.target.getProperty(field.name()); anonymous = classOutline.implClass._class(JMod.PRIVATE | JMod.STATIC, "Anon" + propertyInfo.getName(true)); JDocComment comment = anonymous.javadoc(); comment.append("TODO Can't be anonymous because of NPE bug in CodeModel generator, will be fixed later."); } catch (JClassAlreadyExistsException ex) { throw new RuntimeException(ex.getMessage(), ex); } return anonymous; }