本文整理匯總了Java中com.sun.codemodel.JDefinedClass._extends方法的典型用法代碼示例。如果您正苦於以下問題:Java JDefinedClass._extends方法的具體用法?Java JDefinedClass._extends怎麽用?Java JDefinedClass._extends使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JDefinedClass
的用法示例。
在下文中一共展示了JDefinedClass._extends方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: CodeGenerator
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
CodeGenerator(CodeCompiler compiler, MappingSet mappingSet, TemplateClassDefinition<T> definition) {
Preconditions.checkNotNull(definition.getSignature(),
"The signature for defintion %s was incorrectly initialized.", definition);
this.definition = definition;
this.compiler = compiler;
this.className = definition.getExternalInterface().getSimpleName() + "Gen" + definition.getNextClassNumber();
this.fqcn = PACKAGE_NAME + "." + className;
try {
this.model = new JCodeModel();
JDefinedClass clazz = model._package(PACKAGE_NAME)._class(className);
clazz = clazz._extends(model.directClass(definition.getTemplateClassName()));
clazz.constructor(JMod.PUBLIC).body().invoke(SignatureHolder.INIT_METHOD);
rootGenerator = new ClassGenerator<>(this, mappingSet, definition.getSignature(), new EvaluationVisitor(), clazz, model);
} catch (JClassAlreadyExistsException e) {
throw new IllegalStateException(e);
}
}
示例2: addInternalGetMethodJava7
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
JBlock body = method.body();
JSwitch propertySwitch = body._switch(nameParam);
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node);
}
}
JClass extendsType = jclass._extends();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
propertySwitch._default().body()
._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
} else {
propertySwitch._default().body()
._return(notFoundParam);
}
return method;
}
示例3: addInternalGetMethodJava6
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JMethod addInternalGetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
JBlock body = method.body();
JConditional propertyConditional = null;
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
if (propertyConditional == null) {
propertyConditional = body._if(condition);
} else {
propertyConditional = propertyConditional._elseif(condition);
}
JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {});
propertyConditional._then()._return(invoke(propertyGetter));
}
}
JClass extendsType = jclass._extends();
JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
} else {
lastBlock._return(notFoundParam);
}
return method;
}
示例4: addInternalSetMethodJava7
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JSwitch propertySwitch = body._switch(nameParam);
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node);
}
}
JBlock defaultBlock = propertySwitch._default().body();
JClass extendsType = jclass._extends();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
} else {
defaultBlock._return(FALSE);
}
return method;
}
示例5: addInternalSetMethodJava6
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JMethod addInternalSetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JConditional propertyConditional = null;
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
propertyConditional = propertyConditional == null ? propertyConditional = body._if(condition)
: propertyConditional._elseif(condition);
JBlock callSite = propertyConditional._then();
addSetProperty(jclass, callSite, propertyName, propertyType, valueParam, node);
callSite._return(TRUE);
}
}
JClass extendsType = jclass._extends();
JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
} else {
lastBlock._return(FALSE);
}
return method;
}
示例6: searchSuperClassesForField
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
/**
* This is recursive with searchClassAndSuperClassesForField
*/
private JFieldVar searchSuperClassesForField(String property, JDefinedClass jclass) {
JClass superClass = jclass._extends();
JDefinedClass definedSuperClass = definedClassOrNullFromType(superClass);
if (definedSuperClass == null) {
return null;
}
return searchClassAndSuperClassesForField(property, definedSuperClass);
}
示例7: apply
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
/**
* Applies this schema rule to take the required code generation steps.
* <p>
* When this rule is applied for schemas of type object, the properties of
* the schema are used to generate a new Java class and determine its
* characteristics. See other implementers of {@link Rule} for details.
*/
@Override
public JType apply(String nodeName, JsonNode node, JPackage _package, Schema schema) {
JType superType = getSuperType(nodeName, node, _package, schema);
if (superType.isPrimitive() || isFinal(superType)) {
return superType;
}
JDefinedClass jclass;
try {
jclass = createClass(nodeName, node, _package);
} catch (ClassAlreadyExistsException e) {
return e.getExistingClass();
}
jclass._extends((JClass) superType);
schema.setJavaTypeIfEmpty(jclass);
if (node.has("deserializationClassProperty")) {
addJsonTypeInfoAnnotation(jclass, node);
}
if (node.has("title")) {
ruleFactory.getTitleRule().apply(nodeName, node.get("title"), jclass, schema);
}
if (node.has("description")) {
ruleFactory.getDescriptionRule().apply(nodeName, node.get("description"), jclass, schema);
}
ruleFactory.getPropertiesRule().apply(nodeName, node.get("properties"), jclass, schema);
if (node.has("javaInterfaces")) {
addInterfaces(jclass, node.get("javaInterfaces"));
}
ruleFactory.getAdditionalPropertiesRule().apply(nodeName, node.get("additionalProperties"), jclass, schema);
ruleFactory.getDynamicPropertiesRule().apply(nodeName, node.get("properties"), jclass, schema);
if (node.has("required")) {
ruleFactory.getRequiredArrayRule().apply(nodeName, node.get("required"), jclass, schema);
}
if (ruleFactory.getGenerationConfig().isIncludeToString()) {
addToString(jclass);
}
if (ruleFactory.getGenerationConfig().isIncludeHashcodeAndEquals()) {
addHashCode(jclass, node);
addEquals(jclass, node);
}
if (ruleFactory.getGenerationConfig().isParcelable()) {
addParcelSupport(jclass);
}
if (ruleFactory.getGenerationConfig().isIncludeConstructors()) {
addConstructors(jclass, node, schema, ruleFactory.getGenerationConfig().isConstructorsRequiredPropertiesOnly());
}
if (ruleFactory.getGenerationConfig().isSerializable()) {
SerializableHelper.addSerializableSupport(jclass);
}
return jclass;
}
示例8: generateIFDSClass
import com.sun.codemodel.JDefinedClass; //導入方法依賴的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());
}