當前位置: 首頁>>代碼示例>>Java>>正文


Java JDefinedClass.constructor方法代碼示例

本文整理匯總了Java中com.sun.codemodel.JDefinedClass.constructor方法的典型用法代碼示例。如果您正苦於以下問題:Java JDefinedClass.constructor方法的具體用法?Java JDefinedClass.constructor怎麽用?Java JDefinedClass.constructor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.codemodel.JDefinedClass的用法示例。


在下文中一共展示了JDefinedClass.constructor方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addValueField

import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JFieldVar addValueField(JDefinedClass _enum, JType type) {
    JFieldVar valueField = _enum.field(JMod.PRIVATE | JMod.FINAL, type, VALUE_FIELD_NAME);

    JMethod constructor = _enum.constructor(JMod.PRIVATE);
    JVar valueParam = constructor.param(type, VALUE_FIELD_NAME);
    JBlock body = constructor.body();
    body.assign(JExpr._this().ref(valueField), valueParam);

    return valueField;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:EnumRule.java

示例2: addParcelSupport

import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private void addParcelSupport(JDefinedClass jclass) {
    jclass._implements(Parcelable.class);

    parcelableHelper.addWriteToParcel(jclass);
    parcelableHelper.addDescribeContents(jclass);
    parcelableHelper.addCreator(jclass);
    parcelableHelper.addConstructorFromParcel(jclass);
    // #742 : includeConstructors will include the default constructor
    if (!ruleFactory.getGenerationConfig().isIncludeConstructors()) {
        // Add empty constructor
        jclass.constructor(JMod.PUBLIC);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ObjectRule.java

示例3: generatePopulationCode

import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
/**
 * Generates a Holder class that will hold an {@link ArrayList} with all the
 * first level beans in the graph (contents of {@link #beans}) on it.
 */
private void generatePopulationCode() {
    try {
        // Generate the holder class
        JDefinedClass holderClass = cm._class(Config.CFG.getBasePackageName() + ".Holder");
        JClass alObject = (JClass) cm._ref(ArrayList.class);
        alObject = alObject.narrow(Object.class);
        JFieldVar beansField = holderClass.field(JMod.PUBLIC, alObject, "beans", JExpr._new(alObject));
        JMethod defConstructor = holderClass.constructor(JMod.PUBLIC);
        JBlock body = defConstructor.body();

        // Init the beans and add them to the array
        for (MetaJavaBean mjb : beans) {
            mjb.generateStaticInitCode();
            JVar beanDecl = generateBeanNonStaticInitCode(mjb, body, 0);
            body.add(beansField.invoke("add").arg(beanDecl));
        }

        // Init the base beans but don't add them to the array
        for (MetaJavaBean bmjb : baseBeans) {
            bmjb.generateStaticInitCode();
        }

    } catch (JClassAlreadyExistsException e) {
        throw new RuntimeException("Error generating the holder class.", e);
    }
}
 
開發者ID:hibernate,項目名稱:beanvalidation-benchmark,代碼行數:31,代碼來源:Generator.java

示例4: ClassGenerator

import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
ClassGenerator(CodeGenerator<T> codeGenerator, MappingSet mappingSet, SignatureHolder signature, EvaluationVisitor eval, JDefinedClass clazz, JCodeModel model) throws JClassAlreadyExistsException {
  this.codeGenerator = codeGenerator;
  this.clazz = clazz;
  this.mappings = mappingSet;
  this.sig = signature;
  this.evaluationVisitor = eval;
  this.model = Preconditions.checkNotNull(model, "Code model object cannot be null.");
  blocks = new LinkedList[sig.size()];

  for (int i =0; i < sig.size(); i++) {
    blocks[i] = Lists.newLinkedList();
  }
  rotateBlock();

  for (SignatureHolder child : signature.getChildHolders()) {
    final String innerClassName = child.getSignatureClass().getSimpleName();
    final JDefinedClass innerClazz;
    // we need to extend the template class and avoid using static inner classes.
    innerClazz = clazz._class(JMod.FINAL, innerClassName)._extends(child.getSignatureClass());

    // we also need to delegate any inner class constructors.
    for(Constructor<?> c : child.getSignatureClass().getDeclaredConstructors()){
      final Class<?>[] params = c.getParameterTypes();
      JMethod constructor = innerClazz.constructor(JMod.PUBLIC);
      JBlock block = constructor.body();
      JInvocation invoke = block.invoke("super");
      block.invoke(SignatureHolder.INIT_METHOD);

      // start at 1 since first parameter is the parent class
      for (int i = 1; i < params.length; i++) {
        constructor.param(params[i], "arg" + i);
        invoke.arg(JExpr.direct("arg" + i));
      }
    }

    innerClasses.put(innerClassName, new ClassGenerator<>(codeGenerator, mappingSet, child, eval, innerClazz, model));
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:40,代碼來源:ClassGenerator.java

示例5: 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());
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:81,代碼來源:CodeGenerator.java


注:本文中的com.sun.codemodel.JDefinedClass.constructor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。