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


Java JCAnnotation类代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCAnnotation的典型用法代码示例。如果您正苦于以下问题:Java JCAnnotation类的具体用法?Java JCAnnotation怎么用?Java JCAnnotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: diffAnnotation

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
protected int diffAnnotation(JCAnnotation oldT, JCAnnotation newT, int[] bounds) {
    int localPointer = bounds[0];
    int[] annotationBounds = getBounds(oldT.annotationType);
    copyTo(localPointer, annotationBounds[0]);
    localPointer = diffTree(oldT.annotationType, newT.annotationType, annotationBounds);
    JavaTokenId[] parens = null;
    if (oldT.args.nonEmpty()) {
        copyTo(localPointer, localPointer = getOldPos(oldT.args.head));
    } else {
        // check, if there are already written parenthesis
        int endPos = endPos(oldT);
        tokenSequence.move(endPos);
        tokenSequence.movePrevious();
        if (JavaTokenId.RPAREN != tokenSequence.token().id()) {
            parens = new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN };
        } else {
            endPos -= 1;
        }
        copyTo(localPointer, localPointer = endPos);
    }
    localPointer = diffParameterList(oldT.args, newT.args, oldT, parens, localPointer, Measure.ARGUMENT);
    copyTo(localPointer, bounds[1]);

    return bounds[1];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CasualDiff.java

示例2: diffAnnotationsLists

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
private int diffAnnotationsLists(com.sun.tools.javac.util.List<JCAnnotation> oldAnnotations, com.sun.tools.javac.util.List<JCAnnotation> newAnnotations, int startPos, int localPointer) {
    int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer;
    
    if (listsMatch(oldAnnotations, newAnnotations)) {
        copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos));
    } else {
        tokenSequence.move(startPos);
        if (tokenSequence.movePrevious() && JavaTokenId.WHITESPACE == tokenSequence.token().id()) {
            String text = tokenSequence.token().text().toString();
            int index = text.lastIndexOf('\n');
            startPos = tokenSequence.offset();
            if (index > -1) {
                startPos += index + 1;
            }
            if (startPos < localPointer) startPos = localPointer;
        }
        copyTo(localPointer, startPos);
        PositionEstimator est = EstimatorFactory.annotations(oldAnnotations,newAnnotations, diffContext, parameterPrint);
        localPointer = diffList(oldAnnotations, newAnnotations, startPos, est, Measure.ARGUMENT, printer);
    }

    return localPointer;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CasualDiff.java

示例3: resolveIdent

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
/**
 * Resolve an identifier.
 *
 * @param name The identifier to resolve
 */
public Symbol resolveIdent(String name) {
    if (name.equals(""))
        return syms.errSymbol;
    JavaFileObject prev = log.useSource(null);
    try {
        JCExpression tree = null;
        for (String s : name.split("\\.", -1)) {
            if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                return syms.errSymbol;
            tree = (tree == null) ? make.Ident(names.fromString(s))
                    : make.Select(tree, names.fromString(s));
        }
        JCCompilationUnit toplevel =
                make.TopLevel(List.<JCAnnotation>nil(), null, List.<JCTree>nil());
        toplevel.packge = syms.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:JavaCompiler.java

示例4: visitAnnotation

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void visitAnnotation(JCAnnotation tree) {
	print("@");
	print(tree.annotationType);
	if (tree.args.isEmpty()) return;
	print("(");
	boolean done = false;
	if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
		JCAssign arg1 = (JCAssign) tree.args.get(0);
		JCIdent arg1Name = arg1.lhs instanceof JCIdent ? ((JCIdent) arg1.lhs) : null;
		if (arg1Name != null && arg1Name.name == name_value(arg1Name.name)) {
			print(arg1.rhs);
			done = true;
		}
	}
	if (!done) print(tree.args, ", ");
	print(")");
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:18,代码来源:PrettyPrinter.java

示例5: handleAnnotation

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
/**
 * Handles the provided annotation node by first finding a qualifying instance of
 * {@link JavacAnnotationHandler} and if one exists, calling it with a freshly cooked up
 * instance of {@link lombok.core.AnnotationValues}.
 * 
 * Note that depending on the printASTOnly flag, the {@link lombok.core.PrintAST} annotation
 * will either be silently skipped, or everything that isn't {@code PrintAST} will be skipped.
 * 
 * The HandlerLibrary will attempt to guess if the given annotation node represents a lombok annotation.
 * For example, if {@code lombok.*} is in the import list, then this method will guess that
 * {@code Getter} refers to {@code lombok.Getter}, presuming that {@link lombok.javac.handlers.HandleGetter}
 * has been loaded.
 * 
 * @param unit The Compilation Unit that contains the Annotation AST Node.
 * @param node The Lombok AST Node representing the Annotation AST Node.
 * @param annotation 'node.get()' - convenience parameter.
 */
public void handleAnnotation(JCCompilationUnit unit, JavacNode node, JCAnnotation annotation, long priority) {
	TypeResolver resolver = new TypeResolver(node.getImportList());
	String rawType = annotation.annotationType.toString();
	String fqn = resolver.typeRefToFullyQualifiedName(node, typeLibrary, rawType);
	if (fqn == null) return;
	AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
	if (container == null) return;
	
	try {
		if (container.getPriority() == priority) {
			if (checkAndSetHandled(annotation)) container.handle(node);
		}
	} catch (AnnotationValueDecodeFail fail) {
		fail.owner.setError(fail.getMessage(), fail.idx);
	} catch (Throwable t) {
		String sourceName = "(unknown).java";
		if (unit != null && unit.sourcefile != null) sourceName = unit.sourcefile.getName();
		javacError(String.format("Lombok annotation handler %s failed on " + sourceName, container.handler.getClass()), t);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:38,代码来源:HandlerLibrary.java

示例6: buildTree

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected JavacNode buildTree(JCTree node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((JCCompilationUnit) node);
	case TYPE:
		return buildType((JCClassDecl) node);
	case FIELD:
		return buildField((JCVariableDecl) node);
	case INITIALIZER:
		return buildInitializer((JCBlock) node);
	case METHOD:
		return buildMethod((JCMethodDecl) node);
	case ARGUMENT:
		return buildLocalVar((JCVariableDecl) node, kind);
	case LOCAL:
		return buildLocalVar((JCVariableDecl) node, kind);
	case STATEMENT:
		return buildStatementOrExpression(node);
	case ANNOTATION:
		return buildAnnotation((JCAnnotation) node, false);
	default:
		throw new AssertionError("Did not expect: " + kind);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:JavacAST.java

示例7: buildType

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
private JavacNode buildType(JCClassDecl type) {
	if (setAndGetAsHandled(type)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	
	for (JCAnnotation annotation : type.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, false));
	for (JCTree def : type.defs) {
		/* A def can be:
		 *   JCClassDecl for inner types
		 *   JCMethodDecl for constructors and methods
		 *   JCVariableDecl for fields
		 *   JCBlock for (static) initializers
		 */
		if (def instanceof JCMethodDecl) addIfNotNull(childNodes, buildMethod((JCMethodDecl)def));
		else if (def instanceof JCClassDecl) addIfNotNull(childNodes, buildType((JCClassDecl)def));
		else if (def instanceof JCVariableDecl) addIfNotNull(childNodes, buildField((JCVariableDecl)def));
		else if (def instanceof JCBlock) addIfNotNull(childNodes, buildInitializer((JCBlock)def));
	}
	
	return putInMap(new JavacNode(this, type, childNodes, Kind.TYPE));
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacAST.java

示例8: handle

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.NO_ARGS_CONSTRUCTOR_FLAG_USAGE, "@NoArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	deleteAnnotationIfNeccessary(annotationNode, NoArgsConstructor.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
	List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
	NoArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	boolean force = ann.force();
	List<JavacNode> fields = force ? findFinalFields(typeNode) : List.<JavacNode>nil();
	new HandleConstructor().generateConstructor(typeNode, level, onConstructor, fields, force, staticName, SkipIfConstructorExists.NO, null, annotationNode);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:HandleConstructor.java

示例9: handle

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<Setter> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SETTER_FLAG_USAGE, "@Setter");
	
	Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
	deleteAnnotationIfNeccessary(annotationNode, Setter.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode node = annotationNode.up();
	AccessLevel level = annotation.getInstance().value();
	
	if (level == AccessLevel.NONE || node == null) return;
	
	List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod=", annotationNode);
	List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createSetterForFields(level, fields, 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

示例10: constructorExists

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的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 (JCClassDecl) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(JavacNode node) {
	node = upToTypeNode(node);
	
	if (node != null && node.get() instanceof JCClassDecl) {
		top: for (JCTree def : ((JCClassDecl)node.get()).defs) {
			if (def instanceof JCMethodDecl) {
				JCMethodDecl md = (JCMethodDecl) def;
				if (md.name.contentEquals("<init>")) {
					if ((md.mods.flags & Flags.GENERATEDCONSTR) != 0) continue;
					List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
					if (annotations != null) for (JCAnnotation anno : annotations) {
						if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) continue top;
					}
					return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
				}
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:28,代码来源:JavacHandlerUtil.java

示例11: findAnnotations

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的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 List<JCAnnotation> findAnnotations(JavacNode fieldNode, Pattern namePattern) {
	ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
	for (JavacNode child : fieldNode.down()) {
		if (child.getKind() == Kind.ANNOTATION) {
			JCAnnotation annotation = (JCAnnotation) child.get();
			String name = annotation.annotationType.toString();
			int idx = name.lastIndexOf(".");
			String suspect = idx == -1 ? name : name.substring(idx + 1);
			if (namePattern.matcher(suspect).matches()) {
				result.append(annotation);
			}
		}
	}	
	return result.toList();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacHandlerUtil.java

示例12: handle

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<SneakyThrows> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SNEAKY_THROWS_FLAG_USAGE, "@SneakyThrows");
	
	deleteAnnotationIfNeccessary(annotationNode, SneakyThrows.class);
	Collection<String> exceptionNames = annotation.getRawExpressions("value");
	if (exceptionNames.isEmpty()) {
		exceptionNames = Collections.singleton("java.lang.Throwable");
	}
	
	java.util.List<String> exceptions = new ArrayList<String>();
	for (String exception : exceptionNames) {
		if (exception.endsWith(".class")) exception = exception.substring(0, exception.length() - 6);
		exceptions.add(exception);
	}
	
	JavacNode owner = annotationNode.up();
	switch (owner.getKind()) {
	case METHOD:
		handleMethod(annotationNode, (JCMethodDecl)owner.get(), exceptions);
		break;
	default:
		annotationNode.addError("@SneakyThrows is legal only on methods and constructors.");
		break;
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:HandleSneakyThrows.java

示例13: handle

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<Wither> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
	
	Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
	deleteAnnotationIfNeccessary(annotationNode, Wither.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode node = annotationNode.up();
	AccessLevel level = annotation.getInstance().value();
	
	if (level == AccessLevel.NONE || node == null) return;
	
	List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod=", annotationNode);
	List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createWitherForFields(level, fields, 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

示例14: createCanEqual

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
	/* protected boolean canEqual(final java.lang.Object other) {
	 *     return other instanceof Outer.Inner.MyType;
	 * }
	 */
	JavacTreeMaker maker = typeNode.getTreeMaker();
	
	JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
	JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
	Name canEqualName = typeNode.toName("canEqual");
	JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
	Name otherName = typeNode.toName("other");
	long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
	List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));
	
	JCBlock body = maker.Block(0, List.<JCStatement>of(
			maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
	
	return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:HandleEqualsAndHashCode.java

示例15: handle

import com.sun.tools.javac.tree.JCTree.JCAnnotation; //导入依赖的package包/类
@Override public void handle(AnnotationValues<Data> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.DATA_FLAG_USAGE, "@Data");
	
	deleteAnnotationIfNeccessary(annotationNode, Data.class);
	JavacNode typeNode = annotationNode.up();
	boolean notAClass = !isClass(typeNode);
	
	if (notAClass) {
		annotationNode.addError("@Data is only supported on a class.");
		return;
	}
	
	String staticConstructorName = annotation.getInstance().staticConstructor();
	
	// TODO move this to the end OR move it to the top in eclipse.
	new HandleConstructor().generateRequiredArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, SkipIfConstructorExists.YES, annotationNode);
	new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
	new HandleSetter().generateSetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
	new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
	new HandleToString().generateToStringForType(typeNode, annotationNode);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:HandleData.java


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