当前位置: 首页>>代码示例>>Java>>正文


Java Annotation类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.Annotation的典型用法代码示例。如果您正苦于以下问题:Java Annotation类的具体用法?Java Annotation怎么用?Java Annotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Annotation类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了Annotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAnnotations

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
/**
 * Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
 * 
 * Only the simple name is checked - the package and any containing class are ignored.
 */
public static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) {
	List<Annotation> result = new ArrayList<Annotation>();
	if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
	for (Annotation annotation : field.annotations) {
		TypeReference typeRef = annotation.type;
		if (typeRef != null && typeRef.getTypeName() != null) {
			char[][] typeName = typeRef.getTypeName();
			String suspect = new String(typeName[typeName.length - 1]);
			if (namePattern.matcher(suspect).matches()) {
				result.add(annotation);
			}
		}
	}	
	return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:Eclipse.java

示例2: getApplicableExtensionMethods

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
	List<Extension> extensions = new ArrayList<Extension>();
	if ((typeNode != null) && (ann != null) && (receiverType != null)) {
		BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
		EclipseNode annotationNode = typeNode.getNodeFor(ann);
		AnnotationValues<ExtensionMethod> annotation = createAnnotation(ExtensionMethod.class, annotationNode);
		boolean suppressBaseMethods = false;
		try {
			suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
		} catch (AnnotationValueDecodeFail fail) {
			fail.owner.setError(fail.getMessage(), fail.idx);
		}
		for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
			if (extensionMethodProvider instanceof ClassLiteralAccess) {
				TypeBinding binding = ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
				if (binding == null) continue;
				if (!binding.isClass() && !binding.isEnum()) continue;
				Extension e = new Extension();
				e.extensionMethods = getApplicableExtensionMethodsDefinedInProvider(typeNode, (ReferenceBinding) binding, receiverType);
				e.suppressBaseMethods = suppressBaseMethods;
				extensions.add(e);
			}
		}
	}
	return extensions;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:PatchExtensionMethod.java

示例3: buildTree

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((CompilationUnitDeclaration) node);
	case TYPE:
		return buildType((TypeDeclaration) node);
	case FIELD:
		return buildField((FieldDeclaration) node);
	case INITIALIZER:
		return buildInitializer((Initializer) node);
	case METHOD:
		return buildMethod((AbstractMethodDeclaration) node);
	case ARGUMENT:
		return buildLocal((Argument) node, kind);
	case LOCAL:
		return buildLocal((LocalDeclaration) node, kind);
	case STATEMENT:
		return buildStatement((Statement) node);
	case ANNOTATION:
		return buildAnnotation((Annotation) node, false);
	default:
		throw new AssertionError("Did not expect to arrive here: " + kind);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:EclipseAST.java

示例4: createFactoryParameter

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
@Override public Expression createFactoryParameter(ClassLiteralAccess type, Annotation source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	
	MessageSend factoryParameterCall = new MessageSend();
	setGeneratedBy(factoryParameterCall, source);
	
	factoryParameterCall.receiver = super.createFactoryParameter(type, source);
	factoryParameterCall.selector = "getName".toCharArray();
	
	factoryParameterCall.nameSourcePosition = p;
	factoryParameterCall.sourceStart = pS;
	factoryParameterCall.sourceEnd = factoryParameterCall.statementEnd = pE;
	
	return factoryParameterCall;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:HandleLog.java

示例5: handle

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.NO_ARGS_CONSTRUCTOR_FLAG_USAGE, "@NoArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
	NoArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	String staticName = ann.staticName();
	if (level == AccessLevel.NONE) return;
	
	boolean force = ann.force();
	
	List<EclipseNode> fields = force ? findFinalFields(typeNode) : Collections.<EclipseNode>emptyList();
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(typeNode, level, fields, force, staticName, SkipIfConstructorExists.NO, null, onConstructor, annotationNode);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:18,代码来源:HandleConstructor.java

示例6: handle

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SETTER_FLAG_USAGE, "@Setter");
	
	EclipseNode node = annotationNode.up();
	AccessLevel level = annotation.getInstance().value();
	if (level == AccessLevel.NONE || node == null) return;
	
	List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod=", annotationNode);
	List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
		break;
	case TYPE:
		if (!onMethod.isEmpty()) {
			annotationNode.addError("'onMethod' is not supported for @Setter on a type.");
		}
		if (!onParam.isEmpty()) {
			annotationNode.addError("'onParam' is not supported for @Setter on a type.");
		}
		generateSetterForType(node, annotationNode, level, false);
		break;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:HandleSetter.java

示例7: sanityCheckForMethodGeneratingAnnotationsOnBuilderClass

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
public static void sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(EclipseNode typeNode, EclipseNode errorNode) {
	List<String> disallowed = null;
	for (EclipseNode child : typeNode.down()) {
		if (child.getKind() != Kind.ANNOTATION) continue;
		for (Class<? extends java.lang.annotation.Annotation> annType : INVALID_ON_BUILDERS) {
			if (annotationTypeMatches(annType, child)) {
				if (disallowed == null) disallowed = new ArrayList<String>();
				disallowed.add(annType.getSimpleName());
			}
		}
	}
	
	int size = disallowed == null ? 0 : disallowed.size();
	if (size == 0) return;
	if (size == 1) {
		errorNode.addError("@" + disallowed.get(0) + " is not allowed on builder classes.");
		return;
	}
	StringBuilder out = new StringBuilder();
	for (String a : disallowed) out.append("@").append(a).append(", ");
	out.setLength(out.length() - 2);
	errorNode.addError(out.append(" are not allowed on builder classes.").toString());
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:24,代码来源:EclipseHandlerUtil.java

示例8: hasAnnotation

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
public static boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type, EclipseNode node) {
	if (node == null) return false;
	if (type == null) return false;
	switch (node.getKind()) {
	case ARGUMENT:
	case FIELD:
	case LOCAL:
	case TYPE:
	case METHOD:
		for (EclipseNode child : node.down()) {
			if (annotationTypeMatches(type, child)) return true;
		}
		// intentional fallthrough
	default:
		return false;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:18,代码来源:EclipseHandlerUtil.java

示例9: constructorExists

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
/**
 * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
 * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(EclipseNode node) {
	while (node != null && !(node.get() instanceof TypeDeclaration)) {
		node = node.up();
	}
	
	if (node != null && node.get() instanceof TypeDeclaration) {
		TypeDeclaration typeDecl = (TypeDeclaration)node.get();
		if (typeDecl.methods != null) top: for (AbstractMethodDeclaration def : typeDecl.methods) {
			if (def instanceof ConstructorDeclaration) {
				if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
				
				if (def.annotations != null) for (Annotation anno : def.annotations) {
					if (typeMatches(Tolerate.class, node, anno.type)) continue top;
				}
				
				return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:29,代码来源:EclipseHandlerUtil.java

示例10: handle

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<Wither> annotation, Annotation ast, EclipseNode annotationNode) {
	handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
	
	EclipseNode node = annotationNode.up();
	AccessLevel level = annotation.getInstance().value();
	if (level == AccessLevel.NONE || node == null) return;
	
	List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod=", annotationNode);
	List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createWitherForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
		break;
	case TYPE:
		if (!onMethod.isEmpty()) {
			annotationNode.addError("'onMethod' is not supported for @Wither on a type.");
		}
		if (!onParam.isEmpty()) {
			annotationNode.addError("'onParam' is not supported for @Wither on a type.");
		}
		generateWitherForType(node, annotationNode, level, false);
		break;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:HandleWither.java

示例11: makeSimpleSetterMethodForBuilder

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
	TypeDeclaration td = (TypeDeclaration) builderType.get();
	AbstractMethodDeclaration[] existing = td.methods;
	if (existing == null) existing = EMPTY;
	int len = existing.length;
	FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
	char[] name = fd.name;
	
	for (int i = 0; i < len; i++) {
		if (!(existing[i] instanceof MethodDeclaration)) continue;
		char[] existingName = existing[i].selector;
		if (Arrays.equals(name, existingName)) return;
	}
	
	String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
	
	MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
		sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
	injectMethod(builderType, setter);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:HandleBuilder.java

示例12: handle

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.REQUIRED_ARGS_CONSTRUCTOR_FLAG_USAGE, "@RequiredArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
	RequiredArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(
			typeNode, level, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO,
			suppressConstructorProperties, onConstructor, annotationNode);
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:23,代码来源:HandleConstructor.java

示例13: handle

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
public void handle(AnnotationValues<FieldDefaults> annotation, Annotation ast, EclipseNode annotationNode) {
	handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.FIELD_DEFAULTS_FLAG_USAGE, "@FieldDefaults");
	
	EclipseNode node = annotationNode.up();
	FieldDefaults instance = annotation.getInstance();
	AccessLevel level = instance.level();
	boolean makeFinal = instance.makeFinal();
	
	if (level == AccessLevel.NONE && !makeFinal) {
		annotationNode.addError("This does nothing; provide either level or makeFinal or both.");
		return;
	}
	
	if (level == AccessLevel.PACKAGE) {
		annotationNode.addError("Setting 'level' to PACKAGE does nothing. To force fields as package private, use the @PackagePrivate annotation on the field.");
	}
	
	if (!makeFinal && annotation.isExplicit("makeFinal")) {
		annotationNode.addError("Setting 'makeFinal' to false does nothing. To force fields to be non-final, use the @NonFinal annotation on the field.");
	}
	
	if (node == null) return;
	
	generateFieldDefaultsForType(node, annotationNode, level, makeFinal, false);
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:26,代码来源:HandleFieldDefaults.java

示例14: makeSimpleSetterMethodForBuilder

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
	TypeDeclaration td = (TypeDeclaration) builderType.get();
	AbstractMethodDeclaration[] existing = td.methods;
	if (existing == null) existing = EMPTY;
	int len = existing.length;
	FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
	char[] name = fd.name;
	
	for (int i = 0; i < len; i++) {
		if (!(existing[i] instanceof MethodDeclaration)) continue;
		char[] existingName = existing[i].selector;
		if (Arrays.equals(name, existingName)) return;
	}
	
	String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
	
	MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
			sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
	injectMethod(builderType, setter);
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:21,代码来源:HandleBuilder.java

示例15: visit

import org.eclipse.jdt.internal.compiler.ast.Annotation; //导入依赖的package包/类
@Override
public boolean visit(Argument argument, BlockScope scope) {
	Annotation[] annotations = argument.annotations;
	ReferenceContext referenceContext = scope.referenceContext();
	if (referenceContext instanceof AbstractMethodDeclaration) {
		MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
		if (binding != null) {
			TypeDeclaration typeDeclaration = scope.referenceType();
			typeDeclaration.binding.resolveTypesFor(binding);
			if (argument.binding != null) {
				argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
			}
		}
		if (annotations != null) {
			this.resolveAnnotations(
					scope,
					annotations,
					argument.binding);
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:AnnotationDiscoveryVisitor.java


注:本文中的org.eclipse.jdt.internal.compiler.ast.Annotation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。