本文整理汇总了Java中com.helger.jcodemodel.JMethod类的典型用法代码示例。如果您正苦于以下问题:Java JMethod类的具体用法?Java JMethod怎么用?Java JMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JMethod类属于com.helger.jcodemodel包,在下文中一共展示了JMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFromMap
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void createFromMap(JCodeModel codeModel, JDefinedClass genClazz) {
JMethod fromMap = genClazz.method(JMod.PUBLIC | JMod.STATIC, genClazz, "fromMap");
fromMap.param(codeModel.directClass(Map.class.getCanonicalName()).narrow(String.class).narrow(Object.class), "obj");
fromMap.body().directStatement("return obj != null ? new " + genClazz.name() + "(obj) : null;");
JMethod fromMapList = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(List.class.getCanonicalName()).narrow(genClazz), "fromMap");
fromMapList.param(codeModel.directClass(List.class.getCanonicalName()).narrow(codeModel.directClass(Map.class.getCanonicalName()).narrow(String.class).narrow(Object.class)), "obj");
StringBuilder mBuilder = new StringBuilder()
.append("if(obj != null) { \n")
.append("java.util.List<" + genClazz.name() + "> result = new java.util.ArrayList<" + genClazz.name() + ">(); \n")
.append("for(java.util.Map<String, Object> entry : obj) { \n")
.append("result.add(new " + genClazz.name() + "(entry)); \n")
.append("} \n")
.append("return result; \n")
.append("} \n")
.append("return null; \n");
fromMapList.body().directStatement(mBuilder.toString());
}
示例2: buildFactory
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
JMethod buildFactory(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
JDefinedClass factory = buildFactoryClass(constructorMethods);
JFieldVar factoryField = environment.buildValueClassField(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, factory, "FACTORY");
JAnnotationUse fieldAnnotationUse = factoryField.annotate(SuppressWarnings.class);
JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
paramArray.param("unchecked");
paramArray.param("rawtypes");
factoryField.init(JExpr._new(factory));
JMethod factoryMethod = environment.buildValueClassMethod(Source.toJMod(environment.factoryMethodAccessLevel()) | JMod.STATIC, "factory");
Source.annotateNonnull(factoryMethod);
JAnnotationUse methodAnnotationUse = factoryMethod.annotate(SuppressWarnings.class);
methodAnnotationUse.param("value", "unchecked");
for (JTypeVar visitorTypeParameter: environment.getValueTypeParameters()) {
JTypeVar typeParameter = factoryMethod.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
AbstractJClass usedValueClassType = environment.wrappedValueClassType(factoryMethod.typeParams());
factoryMethod.type(environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException).getVisitorType());
factoryMethod.body()._return(factoryField);
return factoryMethod;
}
示例3: declareAcceptMethod
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private JMethod declareAcceptMethod(JDefinedClass caseClass, AbstractJClass usedValueClassType) {
JMethod acceptMethod = caseClass.method(JMod.PUBLIC, types._void, environment.acceptMethodName());
acceptMethod.annotate(Override.class);
JTypeVar visitorResultTypeParameter = environment.visitorDefinition().getResultTypeParameter();
AbstractJClass resultType;
if (visitorResultTypeParameter == null)
resultType = types._Object;
else {
JTypeVar resultTypeVar = acceptMethod.generify(visitorResultTypeParameter.name());
resultTypeVar.boundLike(visitorResultTypeParameter);
resultType = resultTypeVar;
}
acceptMethod.type(resultType);
JTypeVar visitorExceptionTypeParameter = environment.visitorDefinition().getExceptionTypeParameter();
JTypeVar exceptionType = null;
if (visitorExceptionTypeParameter != null) {
JTypeVar exceptionTypeParameter = acceptMethod.generify(visitorExceptionTypeParameter.name());
exceptionTypeParameter.boundLike(visitorExceptionTypeParameter);
exceptionType = exceptionTypeParameter;
acceptMethod._throws(exceptionType);
}
VisitorDefinition.VisitorUsage usedVisitorType = environment.visitor(usedValueClassType, resultType, exceptionType);
acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");
return acceptMethod;
}
示例4: buildProtectedConstructor
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
void buildProtectedConstructor(Serialization serialization) {
JMethod constructor = environment.buildValueClassConstructor(JMod.PROTECTED);
JAnnotationUse annotation = constructor.annotate(SuppressWarnings.class);
annotation.paramArray("value", "null");
AbstractJClass unwrappedUsedValueClassType = environment.unwrappedValueClassTypeInsideValueClass();
JVar param = constructor.param(unwrappedUsedValueClassType, "implementation");
Source.annotateNonnull(param);
if (isError) {
constructor.body()._throw(JExpr._new(types._UnsupportedOperationException));
} else {
JConditional nullCheck = constructor.body()._if(JExpr.ref("implementation").eq(JExpr._null()));
JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: 'implementation' argument in class constructor invocation: " + environment.valueClassQualifiedName()));
nullCheck._then()._throw(nullPointerExceptionConstruction);
if (environment.hashCodeCaching().enabled())
constructor.body().assign(JExpr.refthis(hashCodeCachedValueField), param.ref(hashCodeCachedValueField));
constructor.body().assign(JExpr.refthis(acceptorField), param.ref(acceptorField));
}
}
示例5: generatePredicate
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
void generatePredicate(String name, PredicateConfigutation predicate) {
JMethod predicateMethod = environment.buildValueClassMethod(Source.toJMod(predicate.accessLevel()) | JMod.FINAL, name);
predicateMethod.type(types._boolean);
if (isError) {
predicateMethod.body()._throw(JExpr._new(types._UnsupportedOperationException));
} else {
JMethod implementation = environment.buildAcceptingInterfaceMethod(JMod.PUBLIC, name);
implementation.type(types._boolean);
predicateMethod.body()._return(JExpr.refthis(acceptorField).invoke(implementation));
for (JMethod interfaceMethod1: environment.visitorDefinition().methodDefinitions()) {
JDefinedClass caseClass = caseClasses.get(interfaceMethod1.name());
predicateMethod = caseClass.method(JMod.PUBLIC | JMod.FINAL, types._boolean, name);
predicateMethod.annotate(Override.class);
boolean result = predicate.isTrueFor(interfaceMethod1);
predicateMethod.body()._return(JExpr.lit(result));
}
}
}
示例6: read
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private GenerationResult<Void> read(JMethod interfaceMethod, String predicateName, MemberAccess accessLevel) {
GenerationProcess generation = new GenerationProcess();
if (predicateName.equals(":auto")) {
predicateName = "is" + Source.capitalize(interfaceMethod.name());
}
PredicateConfigutation existingConfiguration = predicates.get(predicateName);
if (existingConfiguration == null) {
existingConfiguration = new PredicateConfigutation(interfaceMethod, accessLevel);
predicates.put(predicateName, existingConfiguration);
}
try {
existingConfiguration.put(interfaceMethod, accessLevel);
} catch (PredicateConfigurationException ex) {
generation.reportError(MessageFormat.format("Unable to generate {0} predicate: inconsistent access levels: {1}",
predicateName, ex.getMessage()));
}
return generation.createGenerationResult(null);
}
示例7: visitEnum_def
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
@Override
public Void visitEnum_def(Enum_defContext ctx) {
try {
String name = ctx.enum_name().IDENTIFIER().getText();
ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JPackage jPackage = codeModel._package( pkg );
JDefinedClass m = codeModel._package( pkg )._enum( name );
JDefinedClass container = jPackage._getClass( containerName );
String tag = "tag";
m.field( JMod.PUBLIC | JMod.FINAL, codeModel.INT, tag );
JMethod constructor = m.constructor( JMod.PRIVATE );
constructor.param( codeModel.INT, tag );
constructor.body().assign( JExpr._this().ref( tag ), JExpr.ref( tag ) );
addDenifition( container, m );
logger.info( "Enum({}.{})", m._package().name(), m.name() );
return super.visitEnum_def( ctx );
}
catch ( JClassAlreadyExistsException err ) {
throw new RuntimeException( err );
}
}
示例8: tag
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
public static int tag(JFieldVar f, JDefinedClass m, JCodeModel codeModel) {
String getterName = getterName( f, m, codeModel );
JMethod getter = m.getMethod( getterName, new AbstractJType[] {} );
Collection<JAnnotationUse> annotations = getter.annotations();
for ( JAnnotationUse annotation : annotations ) {
if ( JsonProperty.class.getName().equals( annotation.getAnnotationClass().fullName() ) ) {
JAnnotationStringValue val = (JAnnotationStringValue) annotation.getParam( "index" );
Object nativeValue = val.nativeValue();
if ( nativeValue instanceof Integer )
return (Integer) val.nativeValue();
JFieldRef ref = (JFieldRef) nativeValue;
return Integer.valueOf( expressionValue( fieldInit( m.fields().get( ref.name() ) ) ).toString() );
}
}
throw new IllegalStateException( "no field tag defined in " + f.name() );
}
示例9: createGetterBodySubEntity
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void createGetterBodySubEntity(CblFieldHolder fieldHolder, JMethod getter) {
StringBuilder builder = new StringBuilder();
builder.append("return (" + fieldHolder.getType().fullName() + ") " + fieldHolder.getSubEntityName() + ".fromMap((");
if (fieldHolder.isSubEntityIsTypeParam()) {
builder.append("java.util.List<java.util.Map<String, Object>>");
} else {
builder.append("java.util.Map<String, Object>");
}
builder.append(")mDoc.get(" + ConversionUtil.convertCamelToUnderscore(fieldHolder.getDbField()).toUpperCase() + "));");
getter.body().directStatement(builder.toString());
}
示例10: createSetterBodySubEntity
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void createSetterBodySubEntity(CblFieldHolder fieldHolder, JMethod setter) {
StringBuilder builder = new StringBuilder();
builder.append("mDocChanges.put(" + ConversionUtil.convertCamelToUnderscore(fieldHolder.getDbField()).toUpperCase() + ", " + fieldHolder.getSubEntityName() + ".toMap((");
if (fieldHolder.isSubEntityIsTypeParam()) {
builder.append(fieldHolder.getType().fullName());
} else {
builder.append(fieldHolder.getSubEntityName());
}
builder.append(")value)); return this;");
setter.body().directStatement(builder.toString());
}
示例11: createToMap
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void createToMap(JCodeModel codeModel, JDefinedClass genClazz) {
JMethod toMap = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(HashMap.class.getCanonicalName()).narrow(String.class).narrow(Object.class), "toMap");
toMap.param(genClazz, "obj");
StringBuilder builderSingle = new StringBuilder();
builderSingle.append("if(obj == null){ \n");
builderSingle.append("return null; \n");
builderSingle.append("} \n");
builderSingle.append("java.util.HashMap<String, Object> result = new java.util.HashMap<String, Object>(); \n");
builderSingle.append("result.putAll(obj.mDoc); \n");
builderSingle.append("result.putAll(obj.mDocChanges);\n");
builderSingle.append("return result;\n");
toMap.body().directStatement(builderSingle.toString());
JMethod toMapList = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(List.class.getCanonicalName()).narrow(codeModel.directClass(HashMap.class.getCanonicalName()).narrow(String.class).narrow(Object.class)), "toMap");
toMapList.param(codeModel.directClass(List.class.getCanonicalName()).narrow(genClazz), "obj");
StringBuilder builderMulti = new StringBuilder();
builderMulti.append("if(obj == null) return null; \n");
builderMulti.append("java.util.List<java.util.HashMap<String, Object>> result = new java.util.ArrayList<java.util.HashMap<String, Object>>(); \n");
builderMulti.append("for(" + genClazz.name() + " entry : obj) {\n");
builderMulti.append("result.add(((" + genClazz.name() + ")entry).toMap(entry));\n");
builderMulti.append("}\n");
builderMulti.append("return result;\n");
toMapList.body().directStatement(builderMulti.toString());
}
示例12: createSaveMethod
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void createSaveMethod(JCodeModel codeModel, JDefinedClass genClazz, List<CblFieldHolder> attachments, List<CblConstantHolder> constantFields) {
JMethod mSave = genClazz.method(JMod.PUBLIC, codeModel.VOID, "save");
mSave._throws(CouchbaseLiteException.class);
StringBuilder builder = new StringBuilder();
builder.append("com.couchbase.lite.Document doc = kaufland.com.coachbasebinderapi.PersistenceConfig.getInstance().createOrGet(getId()); \n");
for (CblConstantHolder constant : constantFields) {
builder.append("mDocChanges.put(\"" + constant.getDbField() + "\",\"" + constant.getConstantValue() + "\"); \n");
}
builder.append("java.util.HashMap<String, Object> temp = new java.util.HashMap<String, Object>(); \n");
builder.append("if(doc.getProperties() != null){ \n");
builder.append("temp.putAll(doc.getProperties()); \n");
builder.append("} \n");
builder.append("if(mDocChanges != null){ \n");
builder.append("temp.putAll(mDocChanges); \n");
builder.append("} \n");
builder.append("doc.putProperties(temp); \n");
if (attachments.size() > 0) {
builder.append("com.couchbase.lite.UnsavedRevision rev = doc.createRevision(); \n");
for (CblFieldHolder attachment : attachments) {
builder.append("if(" + attachment.getDbField() + " != null){ \n");
builder.append("rev.setAttachment(\"" + attachment.getDbField() + "\", \"" + attachment.getAttachmentType() + "\", " + attachment.getDbField() + "); \n");
builder.append("} \n");
}
builder.append("rev.save(); \n");
}
builder.append("rebind(doc.getProperties()); \n");
mSave.body().directStatement(builder.toString());
}
示例13: annotate
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
public JMethod annotate(final Method m) {
javaxRsAnnotation(m).ifPresent(a -> {
this.type = a;
getMethod().annotate(a);
});
return getMethod();
}
示例14: annotate
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
public JMethod annotate(final String parentPathPrefix, final Method method) {
this.path = path(parentPathPrefix, method);
if (!TypeHelper.isResource(methodStep.getReturnType())) {
getMethod().annotate(Path.class).param("value", this.path);
}
return getMethod();
}
示例15: setPermissionMethods
import com.helger.jcodemodel.JMethod; //导入依赖的package包/类
private void setPermissionMethods(Element element, EComponentHolder holder, AbstractJClass delegateClass, JFieldVar dispatcherCalledField) {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod overrideMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(overrideMethod);
JBlock overrideMethodBody = overrideMethod.body();
JConditional conditional = overrideMethodBody._if(dispatcherCalledField.not());
JBlock thenBlock = conditional._then();
thenBlock.assign(dispatcherCalledField, JExpr.TRUE);
String delegateMethodName = element.getSimpleName().toString() + "WithPermissionCheck";
JInvocation delegateCall = delegateClass.staticInvoke(delegateMethodName)
.arg(JExpr._this());
overrideMethod.params().forEach(delegateCall::arg);
if (overrideMethod.hasVarArgs()) {
JVar jVar = overrideMethod.varParam();
if (jVar != null) {
delegateCall.arg(jVar);
}
}
if (!removeRuntimePermissionsAnnotation(holder.getGeneratedClass())) {
codeModelHelper.copyAnnotation(overrideMethod, findAnnotation(element));
}
thenBlock.add(delegateCall);
JBlock elseBlock = conditional._else();
elseBlock.assign(dispatcherCalledField, JExpr.FALSE);
elseBlock.add(previousMethodBody);
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:36,代码来源:NeedsPermissionHandler.java