本文整理汇总了Java中com.helger.jcodemodel.JAnnotationUse类的典型用法代码示例。如果您正苦于以下问题:Java JAnnotationUse类的具体用法?Java JAnnotationUse怎么用?Java JAnnotationUse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JAnnotationUse类属于com.helger.jcodemodel包,在下文中一共展示了JAnnotationUse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFactory
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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;
}
示例2: buildProtectedConstructor
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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));
}
}
示例3: readGetter
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
GenerationResult<Void> readGetter(MethodUsage interfaceMethod, VariableDeclaration param, AbstractJType paramType, boolean isVarArg) {
GenerationProcess generation = new GenerationProcess();
for (JAnnotationUse annotationUsage: param.annotations()) {
AbstractJClass annotationClass = annotationUsage.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null && annotationClassName.equals(Getter.class.getName())) {
String getterName = annotationUsage.getParam("name", String.class);
if (getterName == null || getterName.equals(":auto"))
getterName = param.name();
MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
boolean isNullable = Source.isNullable(param);
FieldFlags flags = new FieldFlags(isNullable, isVarArg, accessLevel);
FieldConfiguration configuration = new FieldConfiguration(getterName, paramType, flags);
generation.processGenerationResult(read(interfaceMethod, param, configuration));
}
}
}
return generation.<Void>createGenerationResult(null);
}
示例4: readUpdater
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
GenerationResult<Void> readUpdater(MethodUsage interfaceMethod, VariableDeclaration param, AbstractJType paramType, boolean isVarArg) {
GenerationProcess generation = new GenerationProcess();
for (JAnnotationUse annotationUsage: param.annotations()) {
AbstractJClass annotationClass = annotationUsage.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null && annotationClassName.equals(Updater.class.getName())) {
String updaterName = annotationUsage.getParam("name", String.class);
if (updaterName == null || updaterName.equals(":auto"))
updaterName = "with" + Source.capitalize(param.name());
MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
boolean isNullable = Source.isNullable(param);
FieldFlags flags = new FieldFlags(isNullable, isVarArg, accessLevel);
FieldConfiguration configuration = new FieldConfiguration(updaterName, paramType, flags);
generation.processGenerationResult(read(interfaceMethod, param, configuration));
}
}
}
return generation.<Void>createGenerationResult(null);
}
示例5: read
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
GenerationResult<Void> read(JMethod interfaceMethod, JAnnotationUse annotationUsage) {
GenerationProcess generation = new GenerationProcess();
String annotationClassName = annotationUsage.getAnnotationClass().fullName();
if (annotationClassName != null) {
if (annotationClassName.equals(GeneratePredicate.class.getName())) {
String predicateName = annotationUsage.getParam("name", String.class);
MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
generation.processGenerationResult(read(interfaceMethod, predicateName, accessLevel));
} else if (annotationClassName.equals(GeneratePredicates.class.getName())) {
JAnnotationUse[] annotations = annotationUsage.getParam("value", JAnnotationUse[].class);
if (annotations != null) {
for (JAnnotationUse annotation: annotations) {
generation.processGenerationResult(read(interfaceMethod, annotation));
}
}
}
}
return generation.createGenerationResult(null);
}
示例6: createInstance
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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: getNullability
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
public static GenerationResult<Boolean> getNullability(AbstractJType type, String name, Collection<? extends JAnnotationUse> annotations) {
boolean hasNonnull = false;
boolean hasNullable = false;
for (JAnnotationUse annotationUse: annotations) {
AbstractJClass annotationClass = annotationUse.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null) {
if (annotationClassName.equals("javax.annotation.Nonnull")) {
hasNonnull = true;
}
if (annotationClassName.equals("javax.annotation.Nullable")) {
hasNullable = true;
}
}
}
}
if (hasNonnull && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is declared as both @Nullable and @Nonnull",
name)));
if (!type.isReference() && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is non-reference, but declared as @Nullable",
name)));
return new GenerationResult<>(hasNullable, Collections.<String>emptyList());
}
示例8: createStage1Model
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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);
}
}
示例9: processStage0
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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;
}
示例10: tag
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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() );
}
示例11: removeRuntimePermissionsAnnotation
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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
示例12: getPredicates
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
public GenerationResult<Map<String, PredicateConfigutation>> getPredicates() {
GenerationProcess generation = new GenerationProcess();
Map<String, PredicateConfigutation> predicates = new TreeMap<>();
PredicatesReader predicatesReader = new PredicatesReader(predicates);
for (JMethod interfaceMethod: visitorDefinition.methodDefinitions()) {
for (JAnnotationUse annotationUsage: interfaceMethod.annotations()) {
generation.processGenerationResult(predicatesReader.read(interfaceMethod, annotationUsage));
}
}
return generation.createGenerationResult(predicates);
}
示例13: createStage0Model
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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);
}
示例14: visitMessage_def
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的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 );
}
}
示例15: serialization
import com.helger.jcodemodel.JAnnotationUse; //导入依赖的package包/类
private static Serialization serialization(JAnnotationUse annotation) {
if (!annotation.getParam("isSerializable", Boolean.class))
return Serialization.notSerializable();
else
return Serialization.serializable(annotation.getParam("serialVersionUID", Long.class));
}