本文整理匯總了Java中com.sun.codemodel.JCodeModel._package方法的典型用法代碼示例。如果您正苦於以下問題:Java JCodeModel._package方法的具體用法?Java JCodeModel._package怎麽用?Java JCodeModel._package使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JCodeModel
的用法示例。
在下文中一共展示了JCodeModel._package方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: arrayWithUniqueItemsProducesSet
import com.sun.codemodel.JCodeModel; //導入方法依賴的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()));
}
示例2: arrayWithNonUniqueItemsProducesList
import com.sun.codemodel.JCodeModel; //導入方法依賴的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()));
}
示例3: arrayOfPrimitivesProducesCollectionOfWrapperTypes
import com.sun.codemodel.JCodeModel; //導入方法依賴的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()));
}
示例4: arrayDefaultsToNonUnique
import com.sun.codemodel.JCodeModel; //導入方法依賴的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)));
}
示例5: testAnnotationImplements
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public void testAnnotationImplements() throws Exception{
JCodeModel jmod = new JCodeModel();
// adding a test package
JPackage pack = jmod._package("testAnnotationImplements");
// building an interface
JDefinedClass interface1 = pack._interface("Interface1");
// adding annotations
JDefinedClass annotation1 = pack._annotationTypeDeclaration("Annot1");
try{
//this is perfectly legal in CodeModel:
annotation1._implements(interface1);
fail("No Exception was thrown for Illegal behavior");
} catch ( IllegalArgumentException ie){
}
jmod.build(new SingleStreamCodeWriter(System.out));
}
示例6: generate
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public JType generate(JCodeModel codeModel, String className, String packageName, String json) throws IOException {
JPackage jpackage = codeModel._package(packageName);
JsonNode schemaNode = null;
if (ruleFactory.getGenerationConfig().getSourceType() == SourceType.JSON) {
JsonNode jsonNode = objectMapper().readTree(json);
schemaNode = schemaGenerator.schemaFromExample(jsonNode);
} else {
schemaNode = objectMapper().readTree(json);
}
return ruleFactory.getSchemaRule().apply(className, schemaNode, jpackage, new Schema(null, schemaNode, schemaNode));
}
示例7: selfRefWithoutParentFile
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
@Test
public void selfRefWithoutParentFile() throws IOException {
JCodeModel codeModel = new JCodeModel();
JsonNode schema = new ObjectMapper().readTree("{\"type\":\"object\", \"properties\":{\"a\":{\"$ref\":\"#/b\"}}, \"b\":\"string\"}");
JPackage p = codeModel._package("com.example");
new RuleFactory().getSchemaRule().apply("Example", schema, p, new Schema(null, schema, schema));
}
示例8: refToInnerFragmentThatHasRefToOuterFragmentWithoutParentFile
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
@Test
public void refToInnerFragmentThatHasRefToOuterFragmentWithoutParentFile() throws IOException, ClassNotFoundException {
JCodeModel codeModel = new JCodeModel();
JsonNode schema = new ObjectMapper().readTree("{\n" +
" \"type\": \"object\",\n" +
" \"definitions\": {\n" +
" \"location\": {\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"cat\": {\n" +
" \"$ref\": \"#/definitions/cat\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"cat\": {\n" +
" \"type\": \"number\"\n" +
" }\n" +
" },\n" +
" \"properties\": {\n" +
" \"location\": {\n" +
" \"$ref\": \"#/definitions/location\"\n" +
" }\n" +
" }\n" +
"}");
JPackage p = codeModel._package("com.example");
new RuleFactory().getSchemaRule().apply("Example", schema, p, new Schema(null, schema, schema));
}
示例9: apply
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
@Override
public JPackage apply(ApiResourceMetadata controllerMetadata, JCodeModel generatableType) {
if(StringUtils.hasText(controllerMetadata.getBasePackage())) {
return generatableType._package(controllerMetadata.getBasePackage());
}
return generatableType.rootPackage();
}
示例10: getOrCreateClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public static JDefinedClass getOrCreateClass(JCodeModel codeModel,
int flags, String fullClassName) {
final String packageName;
final String className;
final int lastDotIndex = fullClassName.lastIndexOf('.');
if (lastDotIndex >= 0) {
packageName = fullClassName.substring(0, lastDotIndex);
className = fullClassName.substring(lastDotIndex + 1);
} else {
packageName = "";
className = fullClassName;
}
final JPackage thePackage = codeModel._package(packageName);
return getOrCreateClass(thePackage, flags, className);
}
示例11: testNestedAnnotations
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
* Adding nested Annotations in JModel
* @throws Exception
*/
// unused
//@Test
public void testNestedAnnotations() throws Exception{
JCodeModel jmod = new JCodeModel();
// adding a test package
JPackage pack = jmod._package("testNestedAnnotations");
// building an interface
JDefinedClass interface1 = pack._interface("Interface1");
// adding annotations
JDefinedClass annotation1 = pack._annotationTypeDeclaration("Annot1");
JDefinedClass annotation2 = pack._annotationTypeDeclaration("Annot2");
// adding a method for annotation2
annotation1.method(JMod.NONE, String.class, "value");
//adding a method which has an annotation as type to annotation1
annotation2.method(JMod.NONE, annotation1.array(), "value");
// add an annotation to the Interface
JAnnotationArrayMember paramarray = interface1.annotate(annotation2).paramArray("value");
paramarray.annotate(annotation1).param("value", "a");
//paramarray.annotate(annotation1).param("value", "b");
//paramarray.annotate(annotation1).param("value", "c");
jmod.build(new SingleStreamCodeWriter(System.out));
}
示例12: generateClusterSource
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
* Generates the cluster sourcecode for appliances
*
* @param object
* @throws Exception
*/
private void generateClusterSource(JCodeModel jModel, ZclClusterDescriptor zclClusterDescriptor) throws Exception {
/* Define package */
String packageName = getInterfaceClassesPackageName(zclClusterDescriptor);
JPackage jPackage = jModel._package(packageName);
generateClusterAssets(jModel, jPackage, zclClusterDescriptor, false);
generateClusterAssets(jModel, jPackage, zclClusterDescriptor, true);
}
示例13: generateZclClusterSource
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
* Generates the cluster sourcecode for ZigBee appliances
*
* @param object
* @throws Exception
*/
private void generateZclClusterSource(JCodeModel jModel, ZclClusterDescriptor zclClusterDescriptor) throws Exception {
/* Define package */
String packageName = getZclClassesPackageName(zclClusterDescriptor);
JPackage jPackage = jModel._package(packageName);
generateZclClusterAssets(jModel, jPackage, zclClusterDescriptor, true);
generateZclClusterAssets(jModel, jPackage, zclClusterDescriptor, false);
}
示例14: Framework
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public Framework(JCodeModel model, String pckg){
JPackage pack = model._package(pckg == null ? "" : pckg+".framework");
errorRepair = toStaticJClass(pack, ErrorRepair.class);
excErrorRepair = toStaticJClass(pack, ExceptionErrorRepair.class);
burkeFischerRepair = toStaticJClass(pack, BurkeFischerErrorRepair.class);
lexer = toStaticJClass(pack, Lexer.class);
node = toStaticJClass(pack, Node.class);
parser = toStaticJClass(pack, Parser.class);
parsingEng = toStaticJClass(pack, ParsingEngine.class);
stack = toStaticJClass(pack, Stack.class);
status = toStaticJClass(pack, Status.class);
symbol = toStaticJClass(pack, Symbol.class);
token = toStaticJClass(pack, Token.class);
tokenFac = toStaticJClass(pack, TokenFactory.class);
}
示例15: generateIFDSClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
* This function is responsible for generating the stub for IFDS/IDE analysis based on user input.
* @param input The wizard object from the Visuflow wizard.
* @throws JClassAlreadyExistsException
* @throws IOException
*/
public static void generateIFDSClass(WizardInput input) throws JClassAlreadyExistsException, IOException {
JCodeModel codeModel = new JCodeModel();
JPackage jp = codeModel._package(input.getPackageName());
JDefinedClass classToBeCreated = jp._class(input.getAnalysisType());
JClass flowAbstraction = null;
try {
if(!input.getFlowType().equals("Select")){
flowAbstraction = codeModel.ref(Class.forName("java.util." + input.getFlowType()));
if (input.getFlowType1() != null && !input.getFlowType1().equals("Custom")) {
flowAbstraction = flowAbstraction.narrow(Class.forName("java.lang." + input.getFlowType1()));
} else if (input.getCustomClassFirst() != null) {
JDefinedClass firstClass = jp._class(input.getCustomClassFirst());
flowAbstraction = flowAbstraction.narrow(firstClass);
}
if (input.getFlowtype2() != null && !input.getFlowtype2().equals("Custom")) {
flowAbstraction = flowAbstraction.narrow(Class.forName("java.lang." + input.getFlowtype2()));
} else if (input.getCustomClassSecond() != null) {
JDefinedClass secondClass = jp._class(input.getCustomClassSecond());
flowAbstraction = flowAbstraction.narrow(secondClass);
}
}
else{
if (input.getFlowType1() != null && !input.getFlowType1().equals("Custom")) {
flowAbstraction = codeModel.ref(Class.forName("java.lang." + input.getFlowType1()));
} else if (input.getCustomClassFirst() != null) {
flowAbstraction = jp._class(input.getCustomClassFirst());
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JClass interproceduralCFG = codeModel.ref(heros.InterproceduralCFG.class);
interproceduralCFG = interproceduralCFG.narrow(soot.Unit.class);
interproceduralCFG = interproceduralCFG.narrow(soot.SootMethod.class);
JClass extendsClass = codeModel.ref(soot.jimple.toolkits.ide.DefaultJimpleIFDSTabulationProblem.class);
extendsClass = extendsClass.narrow(flowAbstraction);
extendsClass = extendsClass.narrow(interproceduralCFG);
classToBeCreated._extends(extendsClass);
JMethod ctor = classToBeCreated.constructor(JMod.PUBLIC);
ctor.param(interproceduralCFG, "icfg");
JBlock ctorBlock = ctor.body();
ctorBlock.invoke("super").arg(JExpr.ref("icfg"));
JClass mapParam = codeModel.ref(Map.class);
mapParam = mapParam.narrow(soot.Unit.class);
JClass setParam = codeModel.ref(Set.class).narrow(flowAbstraction);
mapParam = mapParam.narrow(setParam);
JMethod initialSeeds = classToBeCreated.method(JMod.PUBLIC, mapParam, "initialSeeds");
initialSeeds.annotate(codeModel.ref(Override.class));
initialSeeds.body()._return(JExpr._null());
JClass flowFunctions = codeModel.ref(FlowFunctions.class);
flowFunctions = flowFunctions.narrow(soot.Unit.class);
flowFunctions = flowFunctions.narrow(flowAbstraction);
flowFunctions = flowFunctions.narrow(soot.SootMethod.class);
JMethod createFlowFunctionsFactory = classToBeCreated.method(JMod.PROTECTED, flowFunctions, "createFlowFunctionsFactory");
createFlowFunctionsFactory.annotate(codeModel.ref(Override.class));
createFlowFunctionsFactory.body()._return(JExpr._null());
JMethod createZeroValue = classToBeCreated.method(JMod.PROTECTED, flowAbstraction, "createZeroValue");
createZeroValue.annotate(codeModel.ref(Override.class));
createZeroValue.body()._return(JExpr._null());
codeModel.build(input.getFile());
}