Tabnine Logo
ClassTemplateSpec
Code IndexAdd Tabnine to your IDE (free)

How to use
ClassTemplateSpec
in
com.linkedin.pegasus.generator.spec

Best Java code snippets using com.linkedin.pegasus.generator.spec.ClassTemplateSpec (Showing top 20 results out of 315)

origin: org.coursera.courier/courier-generator-api

if (enclosingClass != null && classInfo.namespace.equals(enclosingClass.getFullName()))
 classTemplateSpec.setEnclosingClass(enclosingClass);
 classTemplateSpec.setClassName(classInfo.name);
 classTemplateSpec.setModifiers(ModifierSpec.PUBLIC, ModifierSpec.STATIC, ModifierSpec.FINAL);
 classTemplateSpec.setNamespace(classInfo.namespace);
 classTemplateSpec.setClassName(classInfo.name);
 classTemplateSpec.setModifiers(ModifierSpec.PUBLIC);
origin: org.coursera.courier/courier-android-generator

if (spec.getSchema() == null) { // custom type
 return spec.getClassName() + "Member";
Type schemaType = spec.getSchema().getType();
if (schemaType == Type.INT) {
 return "IntMember";
 return "FixedMember";
} else if (schemaType == Type.ENUM) {
 return spec.getClassName() + "Member";
} else if (schemaType == Type.RECORD) {
 return spec.getClassName() + "Member";
} else if (schemaType == Type.MAP) {
 return "MapMember";
origin: org.coursera.courier/courier-generator-api

private ClassTemplateSpec createFromDataSchema(DataSchema schema)
{
 if (schema instanceof MapDataSchema)
 {
  return new CourierMapTemplateSpec((MapDataSchema) schema);
 }
 return ClassTemplateSpec.createFromDataSchema(schema);
}
origin: org.coursera.courier/courier-android-generator

/**
 * Returns the escaped fully qualified name of a {@link ClassTemplateSpec}.
 *
 * @param spec to build a escaped fully qualified name for.
 *
 * @return the escaped fullname.
 */
public static String escapedFullname(ClassTemplateSpec spec) {
 return toFullname(spec.getNamespace(), escapeKeyword(spec.getClassName()));
}
origin: org.coursera.courier/courier-java-generator

@Override
public GeneratedCode generate(ClassTemplateSpec templateSpec) {
 if (predef.contains(templateSpec.getSchema())) {
  return null;
 }
 JavaDataTemplateGenerator.Config config = new JavaDataTemplateGenerator.Config();
 JavaDataTemplateGenerator generator = new JavaDataTemplateGenerator(config);
 JClass result = generator.generate(templateSpec);
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 String code;
 try {
  generator.getCodeModel().build(
   new CapturingCodeWriter(templateSpec.getNamespace(), templateSpec.getClassName(), out));
  out.flush();
  out.close();
  code = out.toString("UTF-8");
 } catch (IOException e) {
  throw new RuntimeException("Error generating code for " + templateSpec.getFullName(), e);
 }
 if (code.trim().equals("")) {
  throw new RuntimeException("Failed to generate code for " + templateSpec.getFullName());
 }
 return new GeneratedCode(
  new JavaCompilationUnit(
   result.name(), result._package().name()), code);
}
origin: org.coursera.courier/courier-swift-generator

if (customInfo != null) {
 DataSchema refSchema = customInfo.getCustomSchema().getDereferencedDataSchema();
 fieldType = ClassTemplateSpec.createFromDataSchema(refSchema);
 String coercer = customInfo.getCoercerClass().getClassName();
 String uncoerced = toLiteral(fieldType.getSchema(), field.getSchemaField().getDefault());
 if (uncoerced == null) {
  return null;
 return toLiteral(fieldType.getSchema(), field.getSchemaField().getDefault());
origin: org.coursera.courier/courier-typescript-lite-generator

 public TSProperties lookupTSProperties(ClassTemplateSpec templateSpec) {
  DataSchema schema = templateSpec.getSchema();
  if (templateSpec instanceof UnionTemplateSpec && templateSpec.getOriginalTyperefSchema() != null) {
   schema = templateSpec.getOriginalTyperefSchema();
  }

  if (schema == null) {
   return defaults;
  } else {
   Object typescript = schema.getProperties().get("typescript");
   if (typescript == null || !(typescript instanceof DataMap)) {
    return defaults;
   }
   DataMap properties = ((DataMap) typescript);

   String optionalityString = properties.getString("optionality");

   TSProperties.Optionality optionality =
     optionalityString == null ? defaults.optionality : TSProperties.Optionality.valueOf(optionalityString);

   Boolean maybeEquatable = properties.getBoolean("equatable");
   boolean equatable =  maybeEquatable == null ? defaults.equatable : maybeEquatable;

   Boolean maybeOmit = properties.getBoolean("omit");
   boolean omit = maybeOmit == null ? defaults.omit : maybeOmit;

   return new TSProperties(optionality, equatable, omit);
  }
 }
}
origin: org.coursera.courier/courier-generator-api

private static String enclosingClassAndMemberNameToString(ClassTemplateSpec enclosingClass, String memberName)
{
 final StringBuilder sb = new StringBuilder();
 if (memberName != null)
 {
  sb.append(" in ");
  sb.append(memberName);
 }
 if (enclosingClass != null)
 {
  sb.append(" in ");
  sb.append(enclosingClass.getFullName());
 }
 return sb.toString();
}
origin: org.coursera.courier/courier-android-generator

 public static AndroidProperties lookupAndroidProperties(ClassTemplateSpec templateSpec) {
  DataSchema schema = templateSpec.getSchema();
  if (schema == null) {
   return DEFAULT;
  } else {
   Object android = schema.getProperties().get("android");
   if (android == null || !(android instanceof DataMap)) {
    return DEFAULT;
   }
   DataMap properties = ((DataMap) android);

   String primitiveStyleStr = properties.getString("primitiveStyle");

   Optionality optionality =
     primitiveStyleStr == null ? DEFAULT.optionality : Optionality.valueOf(primitiveStyleStr);

   return new AndroidProperties(optionality);
  }
 }
}
origin: org.coursera.courier/courier-swift-generator

/**
 * See {@link org.coursera.courier.swift.SwiftProperties} for customization options.
 */
@Override
public GeneratedCode generate(ClassTemplateSpec templateSpec) {
 String code;
 SwiftProperties swiftProperties = globalConfig.lookupSwiftProperties(templateSpec);
 if (swiftProperties.omit) return null;
 SwiftSyntax syntax = new SwiftSyntax(templateSpec, swiftProperties, globalConfig);
 SwiftyJSON swifty = new SwiftyJSON(syntax);
 try {
  if (templateSpec instanceof RecordTemplateSpec) {
   code = engine.render("rythm-swift/record.txt", templateSpec, syntax, swifty);
  } else if (templateSpec instanceof EnumTemplateSpec) {
   code = engine.render("rythm-swift/enum.txt", templateSpec);
  } else if (templateSpec instanceof UnionTemplateSpec) {
   code = engine.render("rythm-swift/union.txt", templateSpec, syntax, swifty);
  } else {
   return null; // Indicates that we are declining to generate code for the type (e.g. map or array)
  }
 } catch (RythmException e) {
  throw new RuntimeException(
   "Internal error in generator while processing " + templateSpec.getFullName(), e);
 }
 SwiftCompilationUnit compilationUnit =
   new SwiftCompilationUnit(
     templateSpec.getClassName(), "");
 code = formatter.format(code);
 return new GeneratedCode(compilationUnit, code);
}
origin: org.coursera.courier/courier-generator-api

/**
 * Register a new class TemplateSpec.
 * <p/>
 * Registration is necessary to associate the {@link com.linkedin.pegasus.generator.spec.ClassTemplateSpec} with the source file for which it was generated. This may be used later to determine if generated class should be emitted
 * based on the location of the source file.
 * <p/>
 * Registration also associates the {@link com.linkedin.data.schema.DataSchema} to the generated {@link com.linkedin.pegasus.generator.spec.ClassTemplateSpec} and the generated class's full name to the the {@link com.linkedin.pegasus.generator.spec.ClassTemplateSpec}.
 *
 * @param schema            provides the {@link com.linkedin.data.schema.DataSchema} of the generated class.
 * @param classTemplateSpec provides the generated class.
 */
private void registerClassTemplateSpec(DataSchema schema, ClassTemplateSpec classTemplateSpec)
{
 classTemplateSpec.setLocation(currentLocation().toString());
 _schemaToClassMap.put(schema, classTemplateSpec);
 _classNameToSchemaMap.put(classTemplateSpec.getFullName(), schema);
 _classToDataSchemaLocationMap.put(classTemplateSpec, currentLocation());
 if (schema instanceof NamedDataSchema)
 {
  checkClassNameForSpecialSuffix(classTemplateSpec.getFullName());
 }
 _classTemplateSpecs.add(classTemplateSpec);
}
origin: org.coursera.courier/courier-swift-generator

/**
 * Returns the escaped fully qualified name of a {@link ClassTemplateSpec}.
 *
 * @param spec to build a escaped fully qualified name for.
 *
 * @return the escaped fullname.
 */
public static String escapedFullname(ClassTemplateSpec spec) {
 // TODO: Remove below null and introduce module namespacing
 return toFullname(null, escapeKeyword(spec.getClassName()));
}
origin: org.coursera.courier/courier-generator-api

customClasses.customClass = new ClassTemplateSpec();
customClasses.customClass.setFullName((String) custom);
if (!allowCustomClass(schema)) {
 throw new IllegalArgumentException(schema + " cannot have custom class binding");
customClasses.customCoercerClass = new ClassTemplateSpec();
customClasses.customCoercerClass.setFullName((String) coercerClass);
origin: org.coursera.courier/courier-swift-generator

 public SwiftProperties lookupSwiftProperties(ClassTemplateSpec templateSpec) {
  DataSchema schema = templateSpec.getSchema();
  if (templateSpec instanceof UnionTemplateSpec && templateSpec.getOriginalTyperefSchema() != null) {
   schema = templateSpec.getOriginalTyperefSchema();
  }

  if (schema == null) {
   return defaults;
  } else {
   Object swift = schema.getProperties().get("swift");
   if (swift == null || !(swift instanceof DataMap)) {
    return defaults;
   }
   DataMap properties = ((DataMap) swift);

   String optionalityString = properties.getString("optionality");

   SwiftProperties.Optionality optionality =
     optionalityString == null ? defaults.optionality : SwiftProperties.Optionality.valueOf(optionalityString);

   Boolean maybeEquatable = properties.getBoolean("equatable");
   boolean equatable =  maybeEquatable == null ? defaults.equatable : maybeEquatable;

   Boolean maybeOmit = properties.getBoolean("omit");
   boolean omit = maybeOmit == null ? defaults.omit : maybeOmit;

   return new SwiftProperties(optionality, equatable, omit);
  }
 }
}
origin: org.coursera.courier/courier-generator-api

/**
 * Instead of generate spec for the specify {@link com.linkedin.data.schema.DataSchema}, assume it is already defined in the system.
 */
public void registerDefinedSchema(DataSchema schema)
{
 final ClassTemplateSpec spec = createFromDataSchema(schema);
 _schemaToClassMap.put(schema, spec);
 _classNameToSchemaMap.put(spec.getFullName(), schema);
}
origin: org.coursera.courier/courier-swift-generator

private String toTypeString(ClassTemplateSpec spec) {
 if (spec.getSchema() == null) { // custom type
  return escapedFullname(spec);
 Type schemaType = spec.getSchema().getType();
 if (schemaType == Type.INT) {
  return "Int"; // TODO: just use Int32 here? (On a 32-bit platform, Int is the same size as Int32.)
origin: org.coursera.courier/courier-android-generator

    JavaSyntax.escapeKeyword(templateSpec.getClassName()), templateSpec.getNamespace());
code = formatter.format(code);
origin: org.coursera.courier/courier-swift-generator

/**
 * Given an expression that evaluates to a Swift data binding type, and it's pegasus type,
 * return an expression that evaluates to the corresponding SwiftyJson JSON type.
 *
 * @param expr provides the expression that evaluates to a SwiftyJson JSON type.
 * @param spec provides the pegasus type that the returned expression should toSwiftCode to.
 */
private Expr writeTypeExpr(Expr expr, ClassTemplateSpec spec, CustomInfoSpec customInfo) {
 if (customInfo != null) {
  Expr coercer = expr(customInfo.getCoercerClass().getClassName());
  return coercer.coercerOutput(writeTypeExpr(expr, spec));
 } else {
  return writeTypeExpr(expr, spec);
 }
}
origin: org.coursera.courier/courier-swift-generator

if (spec.getSchema() == null) { // custom type
 return spec.getClassName() + "Member";
Type schemaType = spec.getSchema().getType();
if (schemaType == Type.INT) {
 return "IntMember";
 return "FixedMember";
} else if (schemaType == Type.ENUM) {
 return spec.getClassName() + "Member";
} else if (schemaType == Type.RECORD) {
 return spec.getClassName() + "Member";
} else if (schemaType == Type.MAP) {
 return "MapMember";
origin: org.coursera.courier/courier-typescript-lite-generator

  "Internal error in generator while processing " + templateSpec.getFullName(), e);
    templateSpec.getFullName(), "");
code = formatter.format(code);
return new GeneratedCode(compilationUnit, code);
com.linkedin.pegasus.generator.specClassTemplateSpec

Most used methods

  • getFullName
  • getSchema
  • createFromDataSchema
  • getClassName
  • getNamespace
  • getOriginalTyperefSchema
  • <init>
  • getBindingName
  • getEnclosingClass
  • setClassName
  • setEnclosingClass
  • setFullName
  • setEnclosingClass,
  • setFullName,
  • setLocation,
  • setModifiers,
  • setNamespace,
  • setOriginalTyperefSchema

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now