本文整理汇总了Java中com.helger.jcodemodel.JDefinedClass类的典型用法代码示例。如果您正苦于以下问题:Java JDefinedClass类的具体用法?Java JDefinedClass怎么用?Java JDefinedClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDefinedClass类属于com.helger.jcodemodel包,在下文中一共展示了JDefinedClass类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createFromMap
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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());
}
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:22,代码来源:EntityGeneration.java
示例2: createMethodBuilder
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
MethodBuilder createMethodBuilder(Serialization serialization) {
if (isError)
return new MethodBuilder(null, null);
else {
JFieldVar acceptorField = buildAcceptorField();
Map<String, JDefinedClass> caseClasses;
try {
caseClasses = buildCaseClasses(serialization);
} catch (JClassAlreadyExistsException ex) {
throw new RuntimeException("Unexpected exception :)", ex);
}
Caching hashCode = environment.hashCodeCaching();
if (!hashCode.enabled())
return new MethodBuilder(caseClasses, acceptorField);
else {
JFieldVar hashCodeField = buildHashCodeCachedValueField(serialization);
return new MethodBuilder(caseClasses, acceptorField, hashCodeField);
}
}
}
开发者ID:sviperll,项目名称:adt4j,代码行数:21,代码来源:FinalValueClassModel.java
示例3: buildFactory
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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;
}
开发者ID:sviperll,项目名称:adt4j,代码行数:24,代码来源:FinalValueClassModel.java
示例4: declareAcceptMethod
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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;
}
开发者ID:sviperll,项目名称:adt4j,代码行数:26,代码来源:FinalValueClassModel.java
示例5: generatePredicate
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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));
}
}
}
开发者ID:sviperll,项目名称:adt4j,代码行数:22,代码来源:FinalValueClassModel.java
示例6: createInstance
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
public static GenerationResult<ValueClassConfiguration> createInstance(VisitorDefinition visitorDefinition, JAnnotationUse annotation, JDefinedClass valueClass) {
GenerationProcess generation = new GenerationProcess();
String acceptMethodName = annotation.getParam("acceptMethodName", String.class);
MemberAccess acceptMethodAccess = annotation.getParam("acceptMethodAccess", MemberAccess.class);
boolean isPublic = annotation.getParam("isPublic", Boolean.class);
Caching hashCodeCaching = annotation.getParam("hashCodeCaching", Caching.class);
int hashCodeBase = annotation.getParam("hashCodeBase", Integer.class);
boolean isComparable = annotation.getParam("isComparable", Boolean.class);
float floatEpsilon = annotation.getParam("floatEpsilon", Float.class);
double doubleEpsilon = annotation.getParam("doubleEpsilon", Double.class);
FloatCustomization floatCustomization = new FloatCustomization(floatEpsilon, doubleEpsilon);
Serialization serialization = serialization(annotation);
ClassCustomization classCustomization = generation.processGenerationResult(classCustomization(annotation, visitorDefinition, valueClass));
AbstractJClass[] interfaces = annotation.getParam("implementsInterfaces", AbstractJClass[].class);
AcceptMethodCustomization acceptMethodCustomization = new AcceptMethodCustomization(acceptMethodName, acceptMethodAccess);
InterfacesCustomization interfaceCustomization = new InterfacesCustomization(isComparable, serialization, interfaces);
APICustomization apiCustomization = new APICustomization(isPublic, acceptMethodCustomization, interfaceCustomization);
ImplementationCustomization implementationCustomization = new ImplementationCustomization(hashCodeCaching, hashCodeBase, floatCustomization);
Customization customiztion = new Customization(classCustomization, apiCustomization, implementationCustomization);
return generation.createGenerationResult(new ValueClassConfiguration(visitorDefinition, customiztion));
}
开发者ID:sviperll,项目名称:adt4j,代码行数:24,代码来源:ValueClassConfiguration.java
示例7: createStage1Model
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
public GenerationResult<Stage1ValueClassModel> createStage1Model(JDefinedClass jVisitorModel, Visitor visitorAnnotation) {
GenerationProcess generation = new GenerationProcess();
if (error != null) {
generation.reportError(error);
return generation.createGenerationResult(null);
} else {
JAnnotationUse annotation = null;
for (JAnnotationUse anyAnnotation: jVisitorModel.annotations()) {
AbstractJClass annotationClass = anyAnnotation.getAnnotationClass();
if (!annotationClass.isError()) {
String fullName = annotationClass.fullName();
if (fullName != null && fullName.equals(GenerateValueClassForVisitor.class.getName()))
annotation = anyAnnotation;
}
}
if (annotation == null)
throw new IllegalStateException("ValueClassModelFactory can't be run for interface without " + GenerateValueClassForVisitor.class + " annotation");
VisitorDefinition visitorModel = generation.processGenerationResult(VisitorDefinition.createInstance(jVisitorModel, visitorAnnotation));
ValueClassConfiguration configuration = generation.processGenerationResult(ValueClassConfiguration.createInstance(visitorModel, annotation, valueClass));
Stage1ValueClassModel result = createStage1Model(configuration);
return generation.createGenerationResult(result);
}
}
开发者ID:sviperll,项目名称:adt4j,代码行数:24,代码来源:Stage0ValueClassModel.java
示例8: processStage0
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
private Map<String, Stage0ValueClassModel> processStage0() throws RuntimeException {
Map<String, Stage0ValueClassModel> result = new TreeMap<>();
JCodeModel bootJCodeModel = new JCodeModel();
final Elements elementUtils = processingEnv.getElementUtils();
final JCodeModelJavaxLangModelAdapter adapter = new JCodeModelJavaxLangModelAdapter(bootJCodeModel, elementUtils);
Stage0ValueClassModelFactory stage0Processor = Stage0ValueClassModelFactory.createFactory(new CheckExistingJDefinedClassFactory(adapter, elementUtils));
for (TypeElement element: elements) {
JDefinedClass bootVisitorModel;
try {
bootVisitorModel = adapter.getClassWithErrorTypes(element);
} catch (CodeModelBuildingException ex) {
throw new RuntimeException("Unexpected exception", ex);
}
JAnnotationUse generateAnnotation = bootVisitorModel.getAnnotation(GenerateValueClassForVisitor.class);
if (generateAnnotation != null) {
Visitor visitorAnnotation = element.getAnnotation(Visitor.class);
if (visitorAnnotation == null) {
visitorAnnotation = DEFAULT_VISITOR_IMPLEMENTATION;
}
Stage0ValueClassModel model = stage0Processor.createStage0Model(bootVisitorModel, visitorAnnotation);
result.put(element.getQualifiedName().toString(), model);
}
}
return result;
}
开发者ID:sviperll,项目名称:adt4j,代码行数:26,代码来源:GenerateValueClassForVisitorProcessor.java
示例9: processStage2
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
private Map<String, TypeElement> processStage2(Map<String, Stage1ValueClassModel> stage1Results) {
Map<String, TypeElement> result = new TreeMap<>();
for (TypeElement element: elements) {
GenerationProcess generation = new GenerationProcess();
generation.reportAllErrors(errorMap.get(element.getQualifiedName().toString()));
Stage1ValueClassModel stage1Model = stage1Results.get(element.getQualifiedName().toString());
if (stage1Model != null) {
JDefinedClass model = generation.processGenerationResult(stage1Model.createResult());
if (model == null)
throw new IllegalStateException("Model shouldn't be null during stage2");
errorMap.put(element.getQualifiedName().toString(), generation.reportedErrors());
result.put(model.fullName(), element);
}
}
return result;
}
开发者ID:sviperll,项目名称:adt4j,代码行数:17,代码来源:GenerateValueClassForVisitorProcessor.java
示例10: visitConstant_def
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
@Override
public Void visitConstant_def(Constant_defContext ctx) {
String constName = ctx.constant_name().IDENTIFIER().getText();
String constType = ctx.constant_type().TYPE_LITERAL().getText();
Literal_valueContext lit = ctx.literal_value();
ProtoTypes type = ProtoTypes.valueOf( constType.toUpperCase() );
ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JDefinedClass container = codeModel._package( pkg )._getClass( containerName );
int modifier = JMod.PUBLIC | JMod.STATIC | JMod.FINAL;
AbstractJType jtype = primitiveType( type ).unboxify();
JFieldVar f = container.field( modifier, jtype, constName.toUpperCase(), parse( type, container, lit ) );
logger.info( "\t +-> {} {} = {}", f.type().name(), f.name(), lit.getText() );
return super.visitConstant_def( ctx );
}
开发者ID:turbospaces,项目名称:protoc,代码行数:20,代码来源:Antlr4ProtoVisitor.java
示例11: visitEnum_def
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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 );
}
}
开发者ID:turbospaces,项目名称:protoc,代码行数:27,代码来源:Antlr4ProtoVisitor.java
示例12: visitEnum_member_tag
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
@Override
public Void visitEnum_member_tag(Enum_member_tagContext ctx) {
int enumTag = Integer.parseInt( ctx.enum_tag().INTEGER_LITERAL().getText() );
String enumMember = ctx.enum_member().IDENTIFIER().getText();
Enum_defContext enumCtx = (Enum_defContext) ctx.getParent();
String enumName = enumCtx.enum_name().IDENTIFIER().getText();
ProtoContext pkgCtx = (ProtoContext) enumCtx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JDefinedClass m = codeModel._package( pkg )._getClass( enumName );
JEnumConstant enumConstant = m.enumConstant( enumMember );
enumConstant.arg( JExpr.lit( enumTag ) ).annotate( JsonProperty.class ).param( "index", enumTag );
logger.info( "\t +-> {}.{} {}", m._package().name(), m.name(), enumMember );
return super.visitEnum_member_tag( ctx );
}
开发者ID:turbospaces,项目名称:protoc,代码行数:18,代码来源:Antlr4ProtoVisitor.java
示例13: visitService_def
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
@Override
public Void visitService_def(Service_defContext ctx) {
try {
String name = ctx.service_name().IDENTIFIER().getText();
ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JPackage jPackage = codeModel._package( pkg );
JDefinedClass i = jPackage._interface( name );
JDefinedClass container = jPackage._getClass( containerName );
if ( ctx.service_parent() != null && ctx.service_parent().service_parent_message() != null ) {
All_identifiersContext parent = ctx.service_parent().service_parent_message().all_identifiers();
i._extends( resolveType( container, parent ) );
}
addDenifition( container, i );
logger.info( "Interface({}.{})", i._package().name(), i.name() );
return super.visitService_def( ctx );
}
catch ( JClassAlreadyExistsException err ) {
throw new RuntimeException( err );
}
}
开发者ID:turbospaces,项目名称:protoc,代码行数:26,代码来源:Antlr4ProtoVisitor.java
示例14: parseBool
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
private boolean parseBool(JDefinedClass container, Literal_valueContext l) {
String asText;
if ( l.literal_substitude() != null ) {
All_identifiersContext subsitude = l.literal_substitude().all_identifiers();
JAtom init = (JAtom) parseSubstitution( container, subsitude );
asText = init.what();
}
else {
asText = l.literal_without_substitude().BOOL_LITERAL().getText();
}
if ( Boolean.TRUE.toString().equals( asText ) )
return true;
else if ( Boolean.FALSE.toString().equals( asText ) )
return false;
throw new IllegalArgumentException( "unable to parse boolean value " + asText );
}
开发者ID:turbospaces,项目名称:protoc,代码行数:18,代码来源:Antlr4ProtoVisitor.java
示例15: tag
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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() );
}
开发者ID:turbospaces,项目名称:protoc,代码行数:17,代码来源:Generator.java
示例16: createToMap
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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());
}
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:28,代码来源:EntityGeneration.java
示例17: createSaveMethod
import com.helger.jcodemodel.JDefinedClass; //导入依赖的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());
}
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:36,代码来源:EntityGeneration.java
示例18: generate
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
@Override
@SneakyThrows
public JCodeModel generate() {
final JDefinedClass c = camundaRestService.getDefinedClass();
// class information
c._extends(camundaRestService.getServiceImplClass());
c.annotate(codeModel.ref(Path.class)).param("value", camundaRestService.getPath());
final String tags = TagRespository.lookup(camundaRestService);
camundaRestService.getRestService().setPath(camundaRestService.getPath());
camundaRestService.getRestService().setTags(tags);
camundaRestService.getRestService().setDescription(camundaRestService.getName());
c.annotate(codeModel.ref(Api.class)).param("value", camundaRestService.getName()).param("tags", tags);
// generate constructor
for (final Constructor<?> constructor : camundaRestService.getServiceImplClass().getConstructors()) {
new InvocationStep(c.constructor(constructor.getModifiers())).constructor(constructor);
}
// construct return type information
final Map<Method, ReturnTypeInfo> returnTypes = Arrays.stream(camundaRestService.getServiceInterfaceClass().getDeclaredMethods()) // iterate over interface
// methods
.map(m -> new ReturnTypeInfo(camundaRestService.getModelRepository(), codeModel, m)
.applyImplementationMethods(camundaRestService.getServiceImplClass().getDeclaredMethods())) // apply impl methods
.collect(Collectors.toMap(r -> r.getMethod(), r -> r)); // build the map
generateMethods(c, camundaRestService.getRestService(), returnTypes, NO_PREFIX);
return this.codeModel;
}
开发者ID:camunda,项目名称:camunda-bpm-swagger,代码行数:32,代码来源:SwaggerServiceModelGenerator.java
示例19: generateMethods
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
private void generateMethods(final JDefinedClass clazz, final RestService restService, final Map<Method, ReturnTypeInfo> methods, final String parentPathPrefix,
final ParentInvocation... parentInvocations) {
for (final Method m : methods.keySet()) {
// create method
final MethodStep methodStep = new MethodStep(camundaRestService.getModelRepository(), restService, clazz);
methodStep.create(methods.get(m), Pair.of(camundaRestService.getPath(), parentPathPrefix), camundaRestService.getModelRepository().getDocumentation().get(), parentInvocations);
// dive into resource processing
if (TypeHelper.isResource(methodStep.getReturnType())) {
// add doc reference
final RestService resourceService = new RestService();
resourceService.setTags(TagRespository.lookup(camundaRestService));
// path is not needed for the sub resource
// resourceService.setPath(camundaRestService.getPath() + methodStep.getPath());
camundaRestService.getModelRepository().addService(methodStep.getReturnType().getName(), resourceService);
generateMethods(clazz, // the class
resourceService,
ResourceMethodGenerationHelper.resourceReturnTypeInfos(camundaRestService.getModelRepository(), codeModel, methodStep.getReturnType()), // info about return types
methodStep.getPath(), // path prefix to generate REST paths
ResourceMethodGenerationHelper.createParentInvocations(parentInvocations, m) // invocation hierarchy
);
}
}
}
开发者ID:camunda,项目名称:camunda-bpm-swagger,代码行数:29,代码来源:SwaggerServiceModelGenerator.java
示例20: removeRuntimePermissionsAnnotation
import com.helger.jcodemodel.JDefinedClass; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private boolean removeRuntimePermissionsAnnotation(JDefinedClass definedClass) {
try {
Field annotationsField = definedClass.getClass().getDeclaredField("m_aAnnotations");
annotationsField.setAccessible(true);
List<JAnnotationUse> annotations = (List<JAnnotationUse>) annotationsField.get(definedClass);
if (annotations == null) {
return true;
}
annotations.removeIf(jAnnotationUse -> jAnnotationUse.getAnnotationClass().name().equals("RuntimePermissions"));
return true;
} catch (ClassCastException | NoSuchFieldException | IllegalAccessException e) {
return false;
}
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:16,代码来源:NeedsPermissionHandler.java
注:本文中的com.helger.jcodemodel.JDefinedClass类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论