本文整理匯總了Java中com.sun.codemodel.JPackage類的典型用法代碼示例。如果您正苦於以下問題:Java JPackage類的具體用法?Java JPackage怎麽用?Java JPackage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JPackage類屬於com.sun.codemodel包,在下文中一共展示了JPackage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getObjectRule
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Override
public org.jsonschema2pojo.rules.Rule<JPackage, JType> getObjectRule() {
final org.jsonschema2pojo.rules.Rule<JPackage, JType> workingRule = super.getObjectRule();
return new org.jsonschema2pojo.rules.Rule<JPackage, JType>() {
@Override
public JType apply(String nodeName, JsonNode node, JPackage generatableType, Schema currentSchema) {
JType objectType = workingRule.apply(nodeName, node, generatableType, currentSchema);
if( objectType instanceof JDefinedClass ) {
JDefinedClass jclass = (JDefinedClass)objectType;
jclass.method(JMod.PUBLIC, jclass.owner().BOOLEAN, "brokenMethod").body();
}
return objectType;
}
};
}
示例2: openBinary
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Override
public OutputStream openBinary(final JPackage pkg, String fileName) throws IOException {
final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();
final String scalaFileName = fileName.replaceAll("\\.java$", ".scala");
return new FilterOutputStream(javaSourceStream) {
@Override
public void close() throws IOException {
super.close();
final String javaSource = new String(javaSourceStream.toByteArray(), "utf-8");
final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));
OutputStream parentStream = ScalaZipCodeWriter.super.openBinary(pkg, scalaFileName);
parentStream.write(scalaSource.getBytes("utf-8"));
}
};
}
示例3: openSource
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Override
public Writer openSource(JPackage pkg, String fileName) throws IOException {
final Writer bw = new OutputStreamWriter(openBinary(pkg, fileName), encoding);
return new UnicodeEscapeWriter(bw) {
private final CharsetEncoder encoder = Charset.forName(encoding).newEncoder();
@Override
protected boolean requireEscaping(int ch) {
// control characters
if (ch < 0x20 && " \t\r\n".indexOf(ch) == -1) {
return true;
}
// ASCII chars
if (ch < 0x80) {
return false;
}
return !encoder.canEncode((char) ch);
}
};
}
示例4: openBinary
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Override
public OutputStream openBinary(final JPackage pkg, String fileName) throws IOException {
final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();
final String scalaFileName = fileName.replaceAll("\\.java$", ".scala");
return new FilterOutputStream(javaSourceStream) {
@Override
public void close() throws IOException {
super.close();
final String javaSource = new String(javaSourceStream.toByteArray(), "utf-8");
final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));
OutputStream parentStream = ScalaSingleStreamCodeWriter.super.openBinary(pkg, scalaFileName);
parentStream.write(scalaSource.getBytes("utf-8"));
}
};
}
示例5: openBinary
import com.sun.codemodel.JPackage; //導入依賴的package包/類
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();
final String javaFileName = getFile(pkg, fileName).getAbsolutePath();
final String scalaFileName = javaFileName.replaceAll("\\.java$", ".scala");
return new FilterOutputStream(javaSourceStream) {
public void close() throws IOException {
super.close();
final String javaSource = new String(javaSourceStream.toByteArray(), encoding);
final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));
FileUtils.writeStringToFile(new File(scalaFileName), scalaSource, encoding);
}
};
}
示例6: applyGeneratesDate
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void applyGeneratesDate() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "string");
TextNode formatNode = TextNode.valueOf("date-time");
objectNode.set("format", formatNode);
JType mockDateType = mock(JType.class);
FormatRule mockFormatRule = mock(FormatRule.class);
when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class))).thenReturn(mockDateType);
when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, equalTo(mockDateType));
}
示例7: applyGeneratesArray
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void applyGeneratesArray() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "array");
JClass mockArrayType = mock(JClass.class);
ArrayRule mockArrayRule = mock(ArrayRule.class);
when(mockArrayRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockArrayType);
when(ruleFactory.getArrayRule()).thenReturn(mockArrayRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, is((JType) mockArrayType));
}
示例8: applyGeneratesCustomObject
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void applyGeneratesCustomObject() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "object");
JDefinedClass mockObjectType = mock(JDefinedClass.class);
ObjectRule mockObjectRule = mock(ObjectRule.class);
when(mockObjectRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockObjectType);
when(ruleFactory.getObjectRule()).thenReturn(mockObjectRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, is((JType) mockObjectType));
}
示例9: arrayWithUniqueItemsProducesSet
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void arrayWithUniqueItemsProducesSet() {
JCodeModel codeModel = new JCodeModel();
JPackage jpackage = codeModel._package(getClass().getPackage().getName());
ObjectMapper mapper = new ObjectMapper();
ObjectNode itemsNode = mapper.createObjectNode();
itemsNode.put("type", "integer");
ObjectNode propertyNode = mapper.createObjectNode();
propertyNode.set("uniqueItems", BooleanNode.TRUE);
propertyNode.set("items", itemsNode);
JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, mock(Schema.class));
assertThat(propertyType, notNullValue());
assertThat(propertyType.erasure(), is(codeModel.ref(Set.class)));
assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Integer.class.getName()));
}
示例10: arrayWithNonUniqueItemsProducesList
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void arrayWithNonUniqueItemsProducesList() {
JCodeModel codeModel = new JCodeModel();
JPackage jpackage = codeModel._package(getClass().getPackage().getName());
ObjectMapper mapper = new ObjectMapper();
ObjectNode itemsNode = mapper.createObjectNode();
itemsNode.put("type", "number");
ObjectNode propertyNode = mapper.createObjectNode();
propertyNode.set("uniqueItems", BooleanNode.FALSE);
propertyNode.set("items", itemsNode);
Schema schema = mock(Schema.class);
when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray"));
when(config.isUseDoubleNumbers()).thenReturn(true);
JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
assertThat(propertyType, notNullValue());
assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName()));
}
示例11: arrayOfPrimitivesProducesCollectionOfWrapperTypes
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void arrayOfPrimitivesProducesCollectionOfWrapperTypes() {
JCodeModel codeModel = new JCodeModel();
JPackage jpackage = codeModel._package(getClass().getPackage().getName());
ObjectMapper mapper = new ObjectMapper();
ObjectNode itemsNode = mapper.createObjectNode();
itemsNode.put("type", "number");
ObjectNode propertyNode = mapper.createObjectNode();
propertyNode.set("uniqueItems", BooleanNode.FALSE);
propertyNode.set("items", itemsNode);
Schema schema = mock(Schema.class);
when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray"));
when(config.isUsePrimitives()).thenReturn(true);
when(config.isUseDoubleNumbers()).thenReturn(true);
JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
assertThat(propertyType, notNullValue());
assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName()));
}
示例12: arrayDefaultsToNonUnique
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@Test
public void arrayDefaultsToNonUnique() {
JCodeModel codeModel = new JCodeModel();
JPackage jpackage = codeModel._package(getClass().getPackage().getName());
ObjectMapper mapper = new ObjectMapper();
ObjectNode itemsNode = mapper.createObjectNode();
itemsNode.put("type", "boolean");
ObjectNode propertyNode = mapper.createObjectNode();
propertyNode.set("uniqueItems", BooleanNode.FALSE);
propertyNode.set("items", itemsNode);
Schema schema = mock(Schema.class);
when(schema.getId()).thenReturn(URI.create("http://example/defaultArray"));
JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
}
示例13: preview
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@RequestMapping(value = "/generator/preview", method = RequestMethod.POST)
public String preview(@RequestParam(value = "schema") String schema,
@RequestParam(value = "targetpackage") String targetpackage,
@RequestParam(value = "sourcetype", required = false) final String sourcetype,
@RequestParam(value = "annotationstyle", required = false) final String annotationstyle,
@RequestParam(value = "usedoublenumbers", required = false) final boolean usedoublenumbers,
@RequestParam(value = "includeaccessors", required = false) final boolean includeaccessors,
@RequestParam(value = "includeadditionalproperties", required = false) final boolean includeadditionalproperties,
@RequestParam(value = "propertyworddelimiters", required = false) final String propertyworddelimiters,
@RequestParam(value = "classname") String classname) throws IOException {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JCodeModel codegenModel = getCodegenModel(schema, targetpackage, sourcetype, annotationstyle, usedoublenumbers, includeaccessors, includeadditionalproperties, propertyworddelimiters, classname);
codegenModel.build(new CodeWriter() {
@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
return byteArrayOutputStream;
}
@Override
public void close() throws IOException {
byteArrayOutputStream.close();
}
});
return byteArrayOutputStream.toString("utf-8");
}
示例14: createResourceInterface
import com.sun.codemodel.JPackage; //導入依賴的package包/類
/**
* <p>createResourceInterface.</p>
*
* @param name a {@link java.lang.String} object.
* @return a {@link com.sun.codemodel.JDefinedClass} object.
* @throws java.lang.Exception if any.
*/
public JDefinedClass createResourceInterface(final String name) throws Exception
{
String actualName;
int i = -1;
while (true)
{
actualName = name + (++i == 0 ? "" : Integer.toString(i));
if (!resourcesMethods.containsKey(actualName))
{
resourcesMethods.put(actualName, new HashSet<String>());
break;
}
}
final JPackage pkg = codeModel._package(configuration.getBasePackageName() + "." +configuration.getRestIFPackageName());
return pkg._interface(actualName);
}
示例15: getOrAddXmlSchemaAnnotation
import com.sun.codemodel.JPackage; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static JAnnotationUse getOrAddXmlSchemaAnnotation(JPackage p, JClass xmlSchemaClass) {
JAnnotationUse xmlAnn = null;
final List<JAnnotationUse> annotations = getAnnotations(p);
if (annotations != null) {
for (JAnnotationUse annotation : annotations) {
final JClass clazz = getAnnotationJClass(annotation);
if (clazz == xmlSchemaClass) {
xmlAnn = annotation;
break;
}
}
}
if (xmlAnn == null) {
// XmlSchema annotation not found, let's add one
xmlAnn = p.annotate(xmlSchemaClass);
}
return xmlAnn;
}