com.sun.codemodel.JPackage类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中com.sun.codemodel.JPackage类的一些代码示例,展示了JPackage类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPackage类的具体详情如下:
包路径:com.sun.codemodel.JPackage
类名称:JPackage

JPackage介绍

[英]A Java package.
[中]Java包。

代码示例

代码示例来源:origin: javaee/glassfish

public Writer openSource(JPackage pkg, String fileName) throws IOException {
  String name;
  if(pkg.isUnnamed())
    name = fileName;
  else
    name = pkg.name()+'.'+fileName;
  name = name.substring(0,name.length()-5);   // strip ".java"
  return filer.createSourceFile(name).openWriter();
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

String fqn = substringBefore(node.get("existingJavaType").asText(), "<");
if (isPrimitive(fqn, _package.owner())) {
  throw new ClassAlreadyExistsException(primitiveType(fqn, _package.owner()));
String fqn = node.path("javaType").asText();
if (isPrimitive(fqn, _package.owner())) {
  throw new GenerationException("javaType cannot refer to a primitive type (" + fqn + "), did you mean to use existingJavaType?");
  newType = _package.owner()._class(JMod.PUBLIC, fqn, ClassType.CLASS);
} else {
  newType = _package.owner()._class(fqn);
  newType = _package._class(JMod.PUBLIC, getClassName(nodeName, node, _package), ClassType.CLASS);
} else {
  newType = _package._class(getClassName(nodeName, node, _package));

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private static JDefinedClass definedClassOrNullFromType(JType type)
{
  if (type == null || type.isPrimitive())
  {
    return null;
  }
  JClass fieldClass = type.boxify();
  JPackage jPackage = fieldClass._package();
  return jPackage._getClass(fieldClass.name());
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private String makeUnique(String className, JPackage _package) {
  try {
    JDefinedClass _class = _package._class(className);
    _package.remove(_class);
    return className;
  } catch (JClassAlreadyExistsException e) {
    return makeUnique(MakeUniqueClassName.makeUnique(className), _package);
  }
}

代码示例来源:origin: org.andromda.thirdparty.jaxb2_commons/jaxb-xjc

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);
    for( PackageOutlineImpl po : packageContexts.values() ) {
      if(buf.length()>0)  buf.append(':');
      buf.append(po._package().name());
    inv.arg(cc.implRef.dotclass());
  for( PackageOutlineImpl po : packageContexts.values() )
    inv.arg(po.objectFactory().dotclass());
  break;
default:

代码示例来源:origin: org.glassfish.metro/webservices-tools

try {
    JPackage pkg = owner.getTargetPackage();
    adapter = pkg._class("Adapter"+id);
  } catch (JClassAlreadyExistsException ex) {
adapter._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(inMemoryType));
JMethod unmarshal = adapter.method(JMod.PUBLIC, inMemoryType, "unmarshal");
JVar $value = unmarshal.param(String.class, "value");
    inv = inMemoryType.staticInvoke(parseMethod).arg($value);
  } else {
    inv = JExpr.direct(parseMethod+"(value)");
unmarshal.body()._return(inv);
JMethod marshal = adapter.method(JMod.PUBLIC, String.class, "marshal");
$value = marshal.param(inMemoryType,"value");

代码示例来源:origin: org.jvnet.ws.wadl/wadl-core

/**
 * Try to create a new exception class that is relevant for the platform
 * @throws JClassAlreadyExistsException should it already exists
 */
protected JDefinedClass generateExceptionClassInternal(String exName, FaultNode f) throws JClassAlreadyExistsException {
  JDefinedClass $exCls = pkg._class( JMod.PUBLIC, exName);
  $exCls._extends(WebApplicationException.class);
  JType rawType = getTypeFromElement(f.getElement());
  JType detailType = rawType==null ? codeModel._ref(Object.class) : rawType;
  JVar $detailField = $exCls.field(JMod.PRIVATE, detailType, "m_faultInfo");
  // Build a constructor
  JMethod $ctor = $exCls.constructor(JMod.PUBLIC);
  JVar $response = $ctor.param(clientResponseClientType(), "response");
  JVar $detail = $ctor.param(detailType, "faultInfo");
  JBlock $ctorBody = $ctor.body();
  // In RS 2.0 the client API is harmonised so we can reuse this
  //
  $ctorBody.directStatement("super(response);");
  $ctorBody.assign($detailField, $detail);
  // Add getter for the body payload
  JMethod $faultInfoGetter = $exCls.method(JMod.PUBLIC, detailType, "getFaultInfo");
  $faultInfoGetter.body()._return($detailField);
  
  // Override getMessage
  overrideMessageOnException($exCls);
  return $exCls;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

this.model = model;
this.codeModel = this.model.codeModel;
this.classRef = codeModel.ref(Class.class);
objectFactory.annotate2(XmlRegistryWriter.class);
JMethod m1 = objectFactory.constructor(JMod.PUBLIC);
m1.javadoc().append("Create a new ObjectFactory that can be used to " +
         "create new instances of schema derived classes " +
         "for package: " + targetPackage.name());
objectFactory.javadoc().append(
  "This object contains factory methods for each \n" +
  "Java content interface and Java element interface \n" +
  "generated in the " + targetPackage.name() + " package. \n" +
  "<p>An ObjectFactory allows you to programatically \n" +
  "construct new instances of the Java representation \n" +

代码示例来源:origin: io.konig/konig-schemagen

private JClass buildDataSinkClass() {
  
  try {
    JDefinedClass dc = writerPackage._class("DataSink");
    
    JVar jsonVar = dc.field(JMod.PRIVATE, JsonGenerator.class, "json");
    
    JMethod ctor = dc.constructor(JMod.PUBLIC);
    JVar outVar = ctor.param(OutputStream.class, "out");
    
    JBlock body = ctor.body();
    JClass jsonFactoryClass = model.ref(JsonFactory.class);
    JVar factoryVar = body.decl(jsonFactoryClass, "jsonFactory", JExpr._new(jsonFactoryClass));
    body.assign(jsonVar, factoryVar.invoke("createGenerator").arg(outVar));
    body.invoke(jsonVar, "useDefaultPrettyPrinter");
    
    
    dc.method(JMod.PUBLIC, JsonGenerator.class, "getJsonGenerator")
      .body()._return(jsonVar);
    
    
    
    return dc;
  } catch (JClassAlreadyExistsException e) {
    throw new SchemaGeneratorException(e);
  }
}

代码示例来源:origin: stackoverflow.com

String className = "class name";
   /* package name */
   JPackage jp = jCodeModel._package("package name ");
    /*  class name  */
   JDefinedClass jclass = jp._class(className);
   /* add comment */
   JDocComment jDocComment = jclass.javadoc();
   jDocComment.add("By AUTOMAT D.I.T tools : " + new Date() +" => " + className);
   // génération des getter & setter & attribues
     // create attribue 
      this.generatedField = jclass.field(JMod.PRIVATE, Integer.class) 
          , "attribue name ");
      // getter
      JMethod getter = jclass.method(JMod.PUBLIC, Integer.class) 
          , "attribue name ");
      getter.body()._return(this.generatedField);
      // setter
      JMethod setter = jclass.method(JMod.PUBLIC, Integer.class) 
          ,"attribue name ");
      // create setter paramétre 
      JVar setParam = setter.param(getTypeDetailsForCodeModel(Integer.class,"param name");
      // affectation  ( this.param = setParam ) 
      setter.body().assign(JExpr._this().ref(this.generatedField), setParam);
   jCodeModel.build(new File("path c://javaSrc//"));

代码示例来源:origin: javaee/jaxb-v2

/**
 * Gets the fully qualified name of this class.
 */
public String fullName() {
  if (outer instanceof JDefinedClass)
    return ((JDefinedClass) outer).fullName() + '.' + name();
  JPackage p = _package();
  if (p.isUnnamed())
    return name();
  else
    return p.name() + '.' + name();
}

代码示例来源:origin: dremio/dremio-oss

CodeGenerator(CodeCompiler compiler, MappingSet mappingSet, TemplateClassDefinition<T> definition, FunctionContext functionContext) {
 Preconditions.checkNotNull(definition.getSignature(),
   "The signature for defintion %s was incorrectly initialized.", definition);
 this.definition = definition;
 this.compiler = compiler;
 this.className = definition.getExternalInterface().getSimpleName() + "Gen" + definition.getNextClassNumber();
 this.fqcn = PACKAGE_NAME + "." + className;
 try {
  this.model = new JCodeModel();
  JDefinedClass clazz = model._package(PACKAGE_NAME)._class(className);
  clazz = clazz._extends(model.directClass(definition.getTemplateClassName()));
  clazz.constructor(JMod.PUBLIC).body().invoke(SignatureHolder.INIT_METHOD);
  rootGenerator = new ClassGenerator<>(this, mappingSet, definition.getSignature(), new EvaluationVisitor(functionContext), clazz, model);
 } catch (JClassAlreadyExistsException e) {
  throw new IllegalStateException(e);
 }
}

代码示例来源:origin: com.sap.cloud.yaas.rammler/rammler-core

packageProcreator.procreate(Collections.<String>emptyList(), builderForParent.owner().rootPackage(), context);
try
  client = targetPackage._class(JMod.PUBLIC, clientName);
final JClass abstractResourceBuilder = builderForParent.owner().ref(AbstractResourceBuilder.class);
client._extends(abstractResourceBuilder.narrow(client));

代码示例来源:origin: me.tatarka.socket/compile

public void generate(String layoutName, Collection<Ref> refs, Writer writer) throws IOException {
  JCodeModel m = new JCodeModel();
  JPackage pkg = m._package(packageName + ".sockets");
  try {
    Refs r = new Refs(m, packageName, layoutName);
    // public class MyLayoutViewModel {
    JDefinedClass clazz = pkg._class(PUBLIC, getClassName(layoutName))._extends(r.viewHolder);
    // public static final int LAYOUT = R.id.my_layout;
    JFieldVar layoutVar = clazz.field(PUBLIC | STATIC | FINAL, m.INT, "LAYOUT", r.layoutRef);
    Map<Ref, JFieldVar> fieldVarMap = genFields(r, clazz, refs);
    genConstructor(r, clazz, refs, fieldVarMap);
    m.build(new WriterCodeWriter(writer));
  } catch (JClassAlreadyExistsException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: fabric8io/kubernetes-client

@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");
   resourceListClass.annotate(ApiGroup.class).param("value", apiGroup);
   if (resourceClass.getPackage().name().startsWith("io.fabric8.kubernetes")) {
    JAnnotationArrayMember arrayMember = resourceClass.annotate(VelocityTransformations.class)
     .paramArray("value");
    arrayMember.annotate(VelocityTransformation.class).param("value", "/manifest.vm")
     .param("outputPath", "kubernetes.properties").param("gather", true);
   } else if (resourceClass.getPackage().name().startsWith("io.fabric8.openshift")) {
    JAnnotationArrayMember arrayMember = resourceClass.annotate(VelocityTransformations.class)
     .paramArray("value");

代码示例来源:origin: io.konig/konig-schemagen

private JClass buildValidationExceptionClass() {
  try {
    JDefinedClass dc = writerPackage._class("ValidationException");
    dc._extends(RuntimeException.class);
    
    JMethod ctor = dc.constructor(JMod.PUBLIC);
    JVar messageVar = ctor.param(String.class, "message");
    JVar causeVar = ctor.param(Throwable.class, "cause");
    
    JBlock block = ctor.body();
    block.invoke("super").arg(messageVar).arg(causeVar);
    
    
    ctor = dc.constructor(JMod.PUBLIC);
    messageVar = ctor.param(String.class, "message");
    block = ctor.body();
    block.invoke("super").arg(messageVar);
    
    return dc;
  } catch (JClassAlreadyExistsException e) {
    throw new SchemaGeneratorException(e);
  }
}

代码示例来源:origin: nz.co.senanque/madura-rules

public void generate(String packageName, File destDir, PrintStream status) throws Exception {
    JCodeModel cm = new JCodeModel();
    JPackage jpackage = cm._package(packageName);
    JDefinedClass maduraResourceComponent = jpackage._class("MaduraResourceComponent");
    JAnnotationUse annotationUse = maduraResourceComponent.annotate(org.springframework.stereotype.Component.class);
    annotationUse.param("value", maduraResourceComponent.fullName());
    annotationUse = maduraResourceComponent.annotate(MessageResource.class);
    annotationUse.param("value", "messages");
//        JFieldVar serialVersionUIDField = maduraResourceComponent.field(JMod.FINAL|JMod.PRIVATE|JMod.STATIC, long.class, "serialVersionUID");
//        serialVersionUIDField.init(JExpr.lit(1L));
    cm.build(destDir, status);
  }

代码示例来源:origin: org.glassfish.metro/webservices-tools

@Override
public boolean run(Model model, WsimportOptions wo, ErrorReceiver er) throws SAXException {
  JCodeModel cm = wo.getCodeModel();
  // we want this to work without requiring JSR-250 jar.
  annotation = cm.ref("javax.annotation.Generated");
  for (Iterator<JPackage> i = cm.packages(); i.hasNext();) {
    for (Iterator<JDefinedClass> j = i.next().classes(); j.hasNext();) {
      annotate(j.next());
    }
  }
  
  return true;
}

代码示例来源:origin: sun-jaxb/jaxb-xjc

/**
 * Returns true if the symbol represented by the short name
 * is "importable".
 */
public boolean collisions(JDefinedClass enclosingClass) {
  // special case where a generated type collides with a type in package java
  // more than one type with the same name
  if(classes.size() > 1)
    return true;
  // an id and (at least one) type with the same name
  if(id && classes.size() != 0)
    return true;
  for(JClass c : classes) {
    if(c._package()==javaLang) {
      // make sure that there's no other class with this name within the same package
      Iterator itr = enclosingClass._package().classes();
      while(itr.hasNext()) {
        // even if this is the only "String" class we use,
        // if the class called "String" is in the same package,
        // we still need to import it.
        JDefinedClass n = (JDefinedClass)itr.next();
        if(n.name().equals(c.name()))
          return true;    //collision
      }
    }
    if(c.outer()!=null)
      return true; // avoid importing inner class to work around 6431987. Also see jaxb issue 166
  }
  return false;
}

代码示例来源:origin: mklemm/jaxb2-rich-contract-plugin

public ReferencedInterfaceOutline(final JClass implClass, final String supportInterfaceNameSuffix) {
  this.implClass = implClass;
  this.supportInterface = supportInterfaceNameSuffix == null ? null : implClass.owner().ref(implClass._package().name() + "." + implClass.name() + supportInterfaceNameSuffix);
}

相关文章