com.squareup.javawriter.JavaWriter.emitJavadoc()方法的使用及代码示例

x33g5p2x  于9个月前 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(14)

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

JavaWriter.emitJavadoc介绍

[英]Emits some Javadoc comments with line separated by \n.
[中]发出一些Javadoc注释,行之间用\n分隔。

代码示例

代码示例来源:origin: fr.xebia.extras/selma-processor

@Override void writeNode(JavaWriter writer) throws IOException {
    writer.emitJavadoc("Throw UnsupportedOperationException because we failed to generate the mapping code:\n" + message);
    // new lines in message result in uncompilable code.
    writer.emitStatement("throw new UnsupportedOperationException(\"%s\")", message.replace("\n", " "));
  }
};

代码示例来源:origin: fr.xebia.extras/selma-processor

public void emitFields(JavaWriter writer) throws IOException {
  int i = 0;
  for (String classe : sources) {
    writer.emitEmptyLine();
    writer.emitJavadoc("This field is used as source akka given as parameter to the Pojos constructors");
    writer.emitField(classe.replace(".class", ""), "source" + i, EnumSet.of(PRIVATE, FINAL));
    i++;
  }
}

代码示例来源:origin: com.stanfy.helium/helium

private void emitJavaDoc(final Descriptionable subject) throws IOException {
 if (subject.getDescription() != null) {
  String javadoc = subject.getDescription().trim();
  if (javadoc.length() == 0) {
   return;
  }
  if (!javadoc.endsWith(".")) {
   javadoc = javadoc.concat(".");
  }
  writer.getOutput().emitJavadoc("%s", javadoc);
 }
}

代码示例来源:origin: com.stanfy.helium/helium

private void writeJavaDoc(final JavaWriter writer, final ServiceMethod m) throws IOException {
 StringBuilder javadoc = new StringBuilder();
 if (m.getName() != null) {
  javadoc.append(m.getName());
  if (javadoc.length() > 0 && javadoc.charAt(javadoc.length() - 1) != '.') {
   javadoc.append('.');
  }
 }
 if (m.getDescription() != null) {
  if (javadoc.length() > 0) {
   javadoc.append("\n");
  }
  javadoc.append(m.getDescription());
 }
 if (javadoc.length() > 0) {
  writer.emitJavadoc(javadoc.toString());
 }
}

代码示例来源:origin: mkarneim/pojobuilder

private void emitConstructor(TypeM builderType, Visibility visibility) throws IOException {
 String builderTypeName = writer.compressType(builderType.getName());
 Modifier modifier = visibility.asModifier();
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc("Creates a new {@link %s}.", builderTypeName).beginConstructor(modifier==null?EnumSet.noneOf(Modifier.class):EnumSet.of(modifier))
  .endConstructor();
 // @formatter:on
}

代码示例来源:origin: net.karneim/pojobuilder

private void emitConstructor(TypeM builderType, Visibility visibility) throws IOException {
 String builderTypeName = writer.compressType(builderType.getName());
 Modifier modifier = visibility.asModifier();
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc("Creates a new {@link %s}.", builderTypeName).beginConstructor(modifier==null?EnumSet.noneOf(Modifier.class):EnumSet.of(modifier))
  .endConstructor();
 // @formatter:on
}

代码示例来源:origin: net.karneim/pojobuilder

private void emitConstructor(TypeM builderType, TypeM selfType, Visibility visibility) throws IOException {
 String selfTypeStr = writer.compressType(selfType.getGenericType());
 String builderTypeName = writer.compressType(builderType.getName());
 Modifier modifier = visibility.asModifier();
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc("Creates a new {@link %s}.", builderTypeName).beginConstructor(modifier==null?EnumSet.noneOf(Modifier.class):EnumSet.of(modifier))
  .emitStatement("self = (%s)this", selfTypeStr).endConstructor();
 // @formatter:on
}

代码示例来源:origin: com.stanfy.helium/helium

public void write(final Type type, final EnumConstraint<String> constraint, final Writer output) throws IOException {
 JavaWriter jw = new JavaWriter(output);
 jw.emitPackage(options.getPackageName());
 if (type.getDescription() != null) {
  jw.emitJavadoc(type.getDescription());
 }
 String enumName = Names.capitalize(type.getCanonicalName());
 jw.beginType(enumName, "enum", EnumSet.of(PUBLIC));
 ArrayList<String> enumValues = new ArrayList<String>(constraint.getValues().size());
 for (String value: constraint.getValues()) {
  enumValues.add(Names.canonicalName(value).toUpperCase(Locale.US));
 }
 jw.emitEnumValues(enumValues);
 jw.endType();
}

代码示例来源:origin: mkarneim/pojobuilder

private void emitConstructor(TypeM builderType, TypeM selfType, Visibility visibility) throws IOException {
 String selfTypeStr = writer.compressType(selfType.getGenericType());
 String builderTypeName = writer.compressType(builderType.getName());
 Modifier modifier = visibility.asModifier();
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc("Creates a new {@link %s}.", builderTypeName).beginConstructor(modifier==null?EnumSet.noneOf(Modifier.class):EnumSet.of(modifier))
  .emitStatement("self = (%s)this", selfTypeStr).endConstructor();
 // @formatter:on
}

代码示例来源:origin: com.android.tools.build/builder

private static void emitClassField(JavaWriter writer, ClassField field) throws IOException {
    String documentation = field.getDocumentation();
    if (!documentation.isEmpty()) {
      writer.emitJavadoc(documentation);
    }
    for (String annotation : field.getAnnotations()) {
      writer.emitAnnotation(annotation);
    }
    writer.emitField(
        field.getType(),
        field.getName(),
        PUBLIC_STATIC_FINAL,
        field.getValue());
  }
}

代码示例来源:origin: com.amazon.device.tools.build/builder

private static void emitClassField(JavaWriter writer, ClassField field) throws IOException {
    String documentation = field.getDocumentation();
    if (!documentation.isEmpty()) {
      writer.emitJavadoc(documentation);
    }
    for (String annotation : field.getAnnotations()) {
      writer.emitAnnotation(annotation);
    }
    writer.emitField(
        field.getType(),
        field.getName(),
        PUBLIC_STATIC_FINAL,
        field.getValue());
  }
}

代码示例来源:origin: sevenshal/oksharedprefs

public void writeSetter(JavaWriter writer) throws IOException {
  writer.emitEmptyLine().emitJavadoc("sets '%1$s' in the preferences.\n@param %2$s the new value for '%1$s'", mPreferenceId, VALUE)
      .beginMethod("void", "set" + mPreferenceName, setPublic, mType.getReturnType(), VALUE)
      .emitStatement("mPreferences.edit().put%1$s(%2$s, %3$s).apply()", mType.getFullName(), mpreferenceFieldName, VALUE)
      .endMethod();
}

代码示例来源:origin: sevenshal/oksharedprefs

public void writeChainSetter(JavaWriter writer, String editorType, String editor) throws IOException {
    writer.emitEmptyLine().emitJavadoc("sets '%1$s' in the preferences.\n@param %2$s the new value for '%1$s'", mPreferenceId, VALUE)
        .beginMethod(editorType, "set" + mPreferenceName, setPublic, mType.getReturnType(), VALUE)
        .emitStatement("%1$s.put%2$s(%3$s, %4$s)", editor, mType.getFullName(), mpreferenceFieldName, VALUE)
        .emitStatement("return this")
        .endMethod();
  }
}

代码示例来源:origin: sevenshal/oksharedprefs

public void writeGetter(JavaWriter writer) throws IOException {
  final String prefix = mType == PreferenceType.BOOLEAN ? mBooleanPrefix : "get";
  // Create getter() for default value
  if (hasDefaultValue) {
    writer.emitEmptyLine().emitJavadoc("gets '%s' from the preferences, <b>%s</b> by default if not yet set.", mPreferenceId, mDefaultValue)
        .beginMethod(mType.getReturnType(), prefix + mPreferenceName, setPublic)
        .emitStatement("return mPreferences.get%1$s(%2$s, %3$s)", mType.getFullName(), mpreferenceFieldName, mDefaultValue).endMethod();
  }
  if (!createDefaultGetter)
    return;
  writer.emitEmptyLine().emitJavadoc("gets '%s' from the preferences.\n@param %s the default value to use", mPreferenceId, PARAM_DEFAULT_VALUE)
      .beginMethod(mType.getReturnType(), prefix + mPreferenceName, setPublic, mType.getReturnType(), PARAM_DEFAULT_VALUE)
      .emitStatement("return mPreferences.get%1$s(%2$s, %3$s)", mType.getFullName(), mpreferenceFieldName, PARAM_DEFAULT_VALUE).endMethod();
}

代码示例来源:origin: mkarneim/pojobuilder

private void emitButMethod(TypeM selfType) throws IOException {
 String builderTypeStr = writer.compressType(selfType.getGenericType());
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc(
    "Returns a clone of this builder.\n\n"
   + "@return the clone");
 if ( selfType.isGeneric()) {
  writer
  .emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("unchecked"));
 }
 writer
  .emitAnnotation(GwtIncompatible.class)
  .beginMethod(builderTypeStr, "but", EnumSet.of(PUBLIC))
   .emitStatement("return (%s)clone()", builderTypeStr)
  .endMethod();
 // @formatter:on
}

代码示例来源:origin: net.karneim/pojobuilder

private void emitButMethod(TypeM selfType) throws IOException {
 String builderTypeStr = writer.compressType(selfType.getGenericType());
 // @formatter:off
 writer
  .emitEmptyLine()
  .emitJavadoc(
    "Returns a clone of this builder.\n\n"
   + "@return the clone");
 if ( selfType.isGeneric()) {
  writer
  .emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("unchecked"));
 }
 writer
  .emitAnnotation(GwtIncompatible.class)
  .beginMethod(builderTypeStr, "but", EnumSet.of(PUBLIC))
   .emitStatement("return (%s)clone()", builderTypeStr)
  .endMethod();
 // @formatter:on
}

代码示例来源:origin: fr.xebia.extras/selma-processor

private void buildConstructor(JavaWriter writer, String adapterName) throws IOException {
  mapper.emitSourceFields(writer);
  mapper.emitCustomMappersFields(writer, false);
  mapper.emitFactoryFields(writer, false);
  
  // First build default constructor
  writer.emitEmptyLine();
  writer.emitJavadoc("Single constructor");
  writer.beginMethod(null, adapterName, EnumSet.of(PUBLIC), mapper.sourceConstructorArgs());
  
  // assign source in parameters to instance fields
  mapper.emitSourceAssigns(writer);
  
  // Add customMapper instantiation
  mapper.emitCustomMappersFields(writer, true);
  mapper.emitFactoryFields(writer, true);
  
  writer.endMethod();
  writer.emitEmptyLine();
}

代码示例来源:origin: mkarneim/pojobuilder

private void emitWithMethodUsingBuilderInterface(TypeM builderType, TypeM selfType, TypeM interfaceType,
  TypeM pojoType, PropertyM prop, OptionalM optional) throws IOException {
 String withMethodName = prop.getWithMethodName();
 String pojoTypeStr = writer.compressType(pojoType.getName());
 String parameterTypeStr = prop.getParameterizedBuilderInterfaceType(interfaceType, optional).getGenericType();
 String propertyLink = prop.isAccessibleViaFieldAccess()
   ? String.format("{@link %s#%s}", pojoTypeStr, prop.getPropertyName())
   : prop.getPropertyName();
 writer.emitEmptyLine();
 writer.emitJavadoc("Sets the default builder for the %s property.\n\n"//
   + "@param builder the default builder\n"//
   + "@return this builder"//
   , propertyLink);
 writer.beginMethod(selfType.getGenericType(), withMethodName, EnumSet.of(PUBLIC), parameterTypeStr, "builder");
 writer.emitStatement("this.%s = builder", prop.getBuilderFieldName());
 if (optional == null) {
  writer.emitStatement("this.%s = false", prop.getIsSetFieldName());
 } else {
  writer.emitStatement("this.%s = %s", prop.getValueFieldName(), optional.absent());
 }
 writer.emitStatement("return self").endMethod();
}

代码示例来源:origin: mkarneim/pojobuilder

static void emitStaticFactoryMethod(TypeM selfType, StaticFactoryMethodM method, JavaWriter writer)
  throws IOException {
 String builderTypeDeclaration = writer.compressType(selfType.getGenericType());
 String returnTypeDecl;
 if (selfType.isGeneric()) {
  String typeParameters = "<" + writer.compressType(selfType.getTypeParameters().toParameterString()) + ">";
  returnTypeDecl = typeParameters + " " + builderTypeDeclaration;
 } else {
  returnTypeDecl = builderTypeDeclaration;
 }
 // @formatter:off
 writer
   .emitEmptyLine()
   .emitJavadoc(
     "Factory Method to construct a %s\n\n@return a new %s", builderTypeDeclaration, builderTypeDeclaration
   )
   .beginMethod(returnTypeDecl, method.getName(), method.getModifiers())
    .emitStatement("return new %s()", builderTypeDeclaration)
   .endMethod();
 // @formatter:on
}

代码示例来源:origin: net.karneim/pojobuilder

static void emitStaticFactoryMethod(TypeM selfType, StaticFactoryMethodM method, JavaWriter writer)
  throws IOException {
 String builderTypeDeclaration = writer.compressType(selfType.getGenericType());
 String returnTypeDecl;
 if (selfType.isGeneric()) {
  String typeParameters = "<" + writer.compressType(selfType.getTypeParameters().toParameterString()) + ">";
  returnTypeDecl = typeParameters + " " + builderTypeDeclaration;
 } else {
  returnTypeDecl = builderTypeDeclaration;
 }
 // @formatter:off
 writer
   .emitEmptyLine()
   .emitJavadoc(
     "Factory Method to construct a %s\n\n@return a new %s", builderTypeDeclaration, builderTypeDeclaration
   )
   .beginMethod(returnTypeDecl, method.getName(), method.getModifiers())
    .emitStatement("return new %s()", builderTypeDeclaration)
   .endMethod();
 // @formatter:on
}

相关文章