本文整理汇总了Java中com.helger.jcodemodel.JDefinedClass.annotate方法的典型用法代码示例。如果您正苦于以下问题:Java JDefinedClass.annotate方法的具体用法?Java JDefinedClass.annotate怎么用?Java JDefinedClass.annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.jcodemodel.JDefinedClass
的用法示例。
在下文中一共展示了JDefinedClass.annotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStage0Model
import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
public Stage0ValueClassModel createStage0Model(JDefinedClass bootModel, Visitor visitorAnnotation) {
GenerationProcess generation = new GenerationProcess();
JAnnotationUse annotation = null;
for (JAnnotationUse anyAnnotation: bootModel.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(bootModel, visitorAnnotation));
ValueClassConfiguration configuration = generation.processGenerationResult(ValueClassConfiguration.createInstance(visitorModel, annotation));
int mods = configuration.isValueClassPublic() ? JMod.PUBLIC: JMod.NONE;
JDefinedClass valueClass;
try {
valueClass = factory.defineClass(bootModel._package().name(), mods, configuration.valueClassName());
} catch (JClassAlreadyExistsException ex) {
return new Stage0ValueClassModel("Class " + configuration.valueClassName() + " already exists");
}
JAnnotationUse generatedAnnotation = valueClass.annotate(Generated.class);
generatedAnnotation.param("value", GenerateValueClassForVisitorProcessor.class.getName());
Source.annotateParametersAreNonnullByDefault(valueClass);
return new Stage0ValueClassModel(valueClass);
}
示例2: visitMessage_def
import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
@Override
public Void visitMessage_def(Message_defContext ctx) {
try {
boolean isError = ctx.messsage_type().ERROR_LITERAL() != null;
String name = ctx.message_name().IDENTIFIER().getText();
AbstractJClass parent = isError ? codeModel.ref( Exception.class ) : codeModel.ref( Object.class );
ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JPackage jPackage = codeModel._package( pkg );
JDefinedClass m = jPackage._class( name );
JDefinedClass container = jPackage._getClass( containerName );
if ( ctx.message_parent() != null && ctx.message_parent().message_parent_message() != null ) {
All_identifiersContext parentCtx = ctx.message_parent().message_parent_message().all_identifiers();
parent = resolveType( container, parentCtx );
}
if ( parent != null ) {
m._extends( parent );
}
container.field( JMod.PUBLIC | JMod.FINAL | JMod.STATIC, m, name, JExpr._new( m ) );
addDenifition( container, m );
JAnnotationUse generated = m.annotate( Generated.class );
generated.param( "date", new Date().toString() );
generated.paramArray( JAnnotationUse.SPECIAL_KEY_VALUE ).param( Generator.class.getName() );
logger.info( "Message({}.{})", m._package().name(), m.name() );
return super.visitMessage_def( ctx );
}
catch ( JClassAlreadyExistsException err ) {
throw new RuntimeException( err );
}
}