本文整理汇总了Java中com.helger.jcodemodel.JDefinedClass类的典型用法代码示例。如果您正苦于以下问题:Java JDefinedClass类的具体用法?Java JDefinedClass怎么用?Java JDefinedClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDefinedClass类属于com.helger.jcodemodel包,在下文中一共展示了JDefinedClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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));
}
示例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);
}
}
示例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;
}
示例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;
}
示例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 );
}
示例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 );
}
}
示例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 );
}
示例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 );
}
}
示例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 );
}
示例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() );
}