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

x33g5p2x  于2022-01-22 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(103)

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

JFormatter介绍

[英]This is a utility class for managing indentation and other basic formatting for PrintWriter.
[中]这是一个实用程序类,用于管理PrintWriter的缩进和其他基本格式。

代码示例

代码示例来源:origin: com.sun.codemodel/codemodel

public void declare(JFormatter f) {
  if (jdoc != null)
    f.nl().g(jdoc);
  if (annotations != null){
    for (JAnnotationUse annotation : annotations)
      f.g(annotation).nl();
  }
  f.g(mods).p(classType.declarationToken).id(name).d(generifiable);
  if (superClass != null && superClass != owner().ref(Object.class))
    f.nl().i().p("extends").g(superClass).nl().o();
  if (!interfaces.isEmpty()) {
    if (superClass == null)
      f.nl();
    f.i().p(classType==ClassType.INTERFACE ? "extends" : "implements");
    f.g(interfaces);
    f.nl().o();
  }
  declareBody(f);
}

代码示例来源:origin: com.unquietcode.tools.jcodemodel/codemodel

public void declare(JFormatter f) {
  f.b(this).p(';').nl();
}

代码示例来源:origin: com.sun.codemodel/codemodel

public void generate(JFormatter f) {
    f.p('{').nl().i();

    boolean first = true;
    for (JAnnotationValue aValue : values) {
      if (!first)
        f.p(',').nl();
      f.g(aValue);
      first = false;
    }
    f.nl().o().p('}');
  }
}

代码示例来源:origin: com.sun.codemodel/codemodel

public void state(JFormatter f) {
  f.p("return ");
  if (expr != null) f.g(expr);
  f.p(';').nl();
}

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

public void state(JFormatter f) {
  f.p("for (");
  f.g(type).id(var).p(": ").g(collection);
  f.p(')');
  if (body != null)
    f.g(body).nl();
  else
    f.p(';').nl();
}

代码示例来源:origin: com.sun.codemodel/codemodel

private JFormatter createJavaSourceFileWriter(CodeWriter src, String className) throws IOException {
    Writer bw = new BufferedWriter(src.openSource(this,className+".java"));
    return new JFormatter(new PrintWriter(bw));
  }
}

代码示例来源:origin: org.apache.drill.exec/drill-java-exec

public DebugStringBuilder( Object obj ) {
 strWriter = new StringWriter( );
 writer = new PrintWriter( strWriter );
 writer.print( "[" );
 writer.print( obj.getClass().getSimpleName() );
 writer.print( ": " );
 fmt = new JFormatter( writer );
}

代码示例来源:origin: com.unquietcode.tools.jcodemodel/codemodel

void build( CodeWriter src, CodeWriter res ) throws IOException {
  // write classes
  for (JDefinedClass c : classes.values()) {
    if (c.isHidden())
      continue;   // don't generate this file
    JFormatter f = createJavaSourceFileWriter(src, c.name());
    f.write(c);
    f.close();
  }
  // write package annotations
  if(annotations!=null || jdoc!=null) {
    JFormatter f = createJavaSourceFileWriter(src,"package-info");
    if (jdoc != null)
      f.g(jdoc);
    // TODO: think about importing
    if (annotations != null){
      for (JAnnotationUse a : annotations)
        f.g(a).nl();
    }
    f.d(this);
    f.close();
  }
  // write resources
  for (JResourceFile rsrc : resources) {
    CodeWriter cw = rsrc.isResource() ? res : src;
    OutputStream os = new BufferedOutputStream(cw.openBinary(this, rsrc.name()));
    rsrc.build(os);
    os.close();
  }
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-xjc

@Override
  protected void onClass(final ClassOutline classOutline) {
    String namespace = null;
    for (final JAnnotationUse annot : classOutline.implClass.annotations()) {
      final String fullName = annot.getAnnotationClass().fullName();
      if (xmlTypeName.equals(fullName)) {
        final JAnnotationValue value = annot.getAnnotationMembers().get("namespace");
        if (value != null) {
          final StringWriter w = new StringWriter();
          value.generate(new JFormatter(w));
          namespace = w.toString();
          namespace = namespace.substring(1, namespace.length() - 1); // remove quotes
        }
      } else if (xmlRootEltName.equals(fullName)) {
        namespace = null;
        break;
      }
    }
    if (null == namespace) {
      return;
    }
    classOutline.implClass.annotate(XmlRootElement.class)
        .param("namespace", namespace)
        .param("name", toXml(classOutline.implClass.name()));
  }
}

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

JCodeModel codeModel = new JCodeModel();
JDefinedClass myValueClass = codeModel._class(JMod.PUBLIC, "MyValue", ClassType.CLASS);
JDefinedClass containerClass = codeModel._class(JMod.PUBLIC, "Container", ClassType.CLASS);
JDefinedClass annotationClass = containerClass._annotationTypeDeclaration("MyAnnotation");
JMethod method = annotationClass.method(JMod.NONE, myValueClass.array(), "myValues");
method.declareDefaultValue(new JExpressionImpl(){
  @Override
  public void generate(JFormatter f) {
    f.p("{}");
  }
});

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

JDefinedClass definedClass = codeModel._class(JMod.PUBLIC, "org.test.Tester", ClassType.CLASS);
 JMethod method = definedClass.method(JMod.PUBLIC, codeModel.VOID, "test");
 final JType targetType = codeModel.ref(String.class);
 final JVar clazzVar = method.body().decl(codeModel.ref(Class.class), "clazz", JExpr.invoke("getClass"));
 method.body().add(new JStatement(){
   @Override
   public void state(JFormatter f) {
     f.g(clazzVar).p(".<").g(targetType).p(">").p("get").p("();").nl();
   }
 });

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

if(!f.isPrinting()) {
      f.g((JClass)o);
  return;
  f.p(indent);
      String line = s.substring(0,idx);
      if(line.length()>0)
        f.p(escape(line));
      s = s.substring(idx+1);
      f.nl().p(indent);
      f.p(escape(s));
  } else
  if(o instanceof JClass) {
    ((JClass)o).printLink(f);
  } else
  if(o instanceof JType) {
    f.g((JType)o);
  } else
    throw new IllegalStateException();
  f.nl();

代码示例来源:origin: com.unquietcode.tools.jcodemodel/codemodel

public void generate(JFormatter f) {
    if(bound._extends()==null)
      f.p("?");   // instead of "? extends Object"
    else
      f.p("? extends").g(bound);
  }
}

代码示例来源:origin: com.cedarsoft.commons/codegen

@Override
public void generate( JFormatter f ) {
 f.p( owner.name() );
 f.p( "." );
 f.p( ns.name() );
}

代码示例来源:origin: com.sap.cloud.yaas.service-generator/service-generator-model-raml

.namespace(annotation.getAnnotationClass()._package().name())
.name(annotation.getAnnotationClass().name());
try
  myPersonalFormatter = new JFormatter(new OutputStreamWriter(myStream, "UTF-8"));
  entry.getValue().generate(myPersonalFormatter);
    myPersonalFormatter.close();

代码示例来源:origin: com.sun.codemodel/codemodel

public void generate(JFormatter f) {
  if (isConstructor && type.isArray()) {
    // [RESULT] new T[]{arg1,arg2,arg3,...};
    f.p("new").g(type).p('{');
  } else {
    if (isConstructor)
      f.p("new").g(type).p('(');
    else {
      String name = this.name;
      if(name==null)  name=this.method.name();
      if (object != null)
        f.g(object).p('.').p(name).p('(');
      else
        f.id(name).p('(');
    }
  }
      
  f.g(args);
  if (isConstructor && type.isArray())
    f.p('}');
  else 
    f.p(')');
    
  if( type instanceof JDefinedClass && ((JDefinedClass)type).isAnonymous() ) {
    ((JAnonymousClass)type).declareBody(f);
  }
}

代码示例来源:origin: com.unquietcode.tools.jcodemodel/codemodel

public void generate(JFormatter f) {
  if (var == null)
    var = new JVar(JMods.forVar(JMod.NONE),
        exception, "_x", null);
  f.p("catch (").b(var).p(')').g(body);
}

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

public void state(JFormatter f) {
  f.p("for (");
  boolean first = true;
  for (Object o : inits) {
    if (!first) f.p(',');
    if (o instanceof JVar)
      f.b((JVar) o);
    else
      f.g((JExpression) o);
    first = false;
  }
  f.p(';').g(test).p(';').g(updates).p(')');
  if (body != null)
    f.g(body).nl();
  else
    f.p(';').nl();
}

代码示例来源:origin: com.sun.codemodel/codemodel

public void state(JFormatter f) {
  if (JOp.hasTopOp(test)) {
    f.p("switch ").g(test).p(" {").nl();
  } else {
    f.p("switch (").g(test).p(')').p(" {").nl();
  }
  for( JCase c : cases )
    f.s(c);
  if( defaultCase != null )
    f.s( defaultCase );
  f.p('}').nl();
}

代码示例来源:origin: com.sun.codemodel/codemodel

public void declare( JFormatter f ) {
  if(typeVariables!=null) {
    f.p('<');
    for (int i = 0; i < typeVariables.size(); i++) {
      if(i!=0)    f.p(',');
      f.d(typeVariables.get(i));
    }
    f.p('>');
  }
}

相关文章