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


Java Kind.METHOD属性代码示例

本文整理汇总了Java中lombok.core.AST.Kind.METHOD属性的典型用法代码示例。如果您正苦于以下问题:Java Kind.METHOD属性的具体用法?Java Kind.METHOD怎么用?Java Kind.METHOD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在lombok.core.AST.Kind的用法示例。


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

示例1: preHandle

@Override public void preHandle(AnnotationValues<Synchronized> annotation, Annotation source, EclipseNode annotationNode) {
	EclipseNode methodNode = annotationNode.up();
	if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) return;
	MethodDeclaration method = (MethodDeclaration)methodNode.get();
	if (method.isAbstract()) return;
	
	createLockField(annotation, annotationNode, method.isStatic(), false);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:8,代码来源:HandleSynchronized.java

示例2: changeModifiersAndGenerateConstructor

private void changeModifiersAndGenerateConstructor(JavacNode typeNode, JavacNode errorNode) {
	JCClassDecl classDecl = (JCClassDecl) typeNode.get();
	
	boolean makeConstructor = true;
	
	classDecl.mods.flags |= Flags.FINAL;
	
	boolean markStatic = true;
	
	if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false;
	if (markStatic && typeNode.up().getKind() == Kind.TYPE) {
		JCClassDecl typeDecl = (JCClassDecl) typeNode.up().get();
		if ((typeDecl.mods.flags & Flags.INTERFACE) != 0) markStatic = false;
	}
	
	if (markStatic) classDecl.mods.flags |= Flags.STATIC;
	
	for (JavacNode element : typeNode.down()) {
		if (element.getKind() == Kind.FIELD) {
			JCVariableDecl fieldDecl = (JCVariableDecl) element.get();
			fieldDecl.mods.flags |= Flags.STATIC;
		} else if (element.getKind() == Kind.METHOD) {
			JCMethodDecl methodDecl = (JCMethodDecl) element.get();
			if (methodDecl.name.contentEquals("<init>")) {
				if (getGeneratedBy(methodDecl) == null && (methodDecl.mods.flags & Flags.GENERATEDCONSTR) == 0) {
					element.addError("@UtilityClasses cannot have declared constructors.");
					makeConstructor = false;
					continue;
				}
			}
			
			methodDecl.mods.flags |= Flags.STATIC;
		} else if (element.getKind() == Kind.TYPE) {
			JCClassDecl innerClassDecl = (JCClassDecl) element.get();
			innerClassDecl.mods.flags |= Flags.STATIC;
		}
	}
	
	if (makeConstructor) createPrivateDefaultConstructor(typeNode);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:40,代码来源:HandleUtilityClass.java

示例3: makeSimpleSetterMethodForBuilder

private void makeSimpleSetterMethodForBuilder(JavacNode builderType, JavacNode fieldNode, JavacNode source, boolean fluent, boolean chain) {
	Name fieldName = ((JCVariableDecl) fieldNode.get()).name;
	
	for (JavacNode child : builderType.down()) {
		if (child.getKind() != Kind.METHOD) continue;
		Name existingName = ((JCMethodDecl) child.get()).name;
		if (existingName.equals(fieldName)) return;
	}
	
	String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
	
	JavacTreeMaker maker = fieldNode.getTreeMaker();
	JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, fieldNode, maker, setterName, chain, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil());
	injectMethod(builderType, newMethod);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:15,代码来源:HandleBuilder.java

示例4: changeModifiersAndGenerateConstructor

private void changeModifiersAndGenerateConstructor(EclipseNode typeNode, EclipseNode annotationNode) {
	TypeDeclaration classDecl = (TypeDeclaration) typeNode.get();
	
	boolean makeConstructor = true;
	
	classDecl.modifiers |= ClassFileConstants.AccFinal;
	
	boolean markStatic = true;
	boolean requiresClInit = false;
	boolean alreadyHasClinit = false;
	
	if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false;
	if (markStatic && typeNode.up().getKind() == Kind.TYPE) {
		TypeDeclaration typeDecl = (TypeDeclaration) typeNode.up().get();
		if ((typeDecl.modifiers & ClassFileConstants.AccInterface) != 0) markStatic = false;
	}
	
	if (markStatic) classDecl.modifiers |= ClassFileConstants.AccStatic;
	
	for (EclipseNode element : typeNode.down()) {
		if (element.getKind() == Kind.FIELD) {
			FieldDeclaration fieldDecl = (FieldDeclaration) element.get();
			if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) == 0) {
				requiresClInit = true;
				fieldDecl.modifiers |= ClassFileConstants.AccStatic;
			}
		} else if (element.getKind() == Kind.METHOD) {
			AbstractMethodDeclaration amd = (AbstractMethodDeclaration) element.get();
			if (amd instanceof ConstructorDeclaration) {
				ConstructorDeclaration constrDecl = (ConstructorDeclaration) element.get();
				if (getGeneratedBy(constrDecl) == null && (constrDecl.bits & ASTNode.IsDefaultConstructor) == 0) {
					element.addError("@UtilityClasses cannot have declared constructors.");
					makeConstructor = false;
					continue;
				}
			} else if (amd instanceof MethodDeclaration) {
				amd.modifiers |= ClassFileConstants.AccStatic;
			} else if (amd instanceof Clinit) {
				alreadyHasClinit = true;
			}
		} else if (element.getKind() == Kind.TYPE) {
			((TypeDeclaration) element.get()).modifiers |= ClassFileConstants.AccStatic;
		}
	}
	
	if (makeConstructor) createPrivateDefaultConstructor(typeNode, annotationNode);
	if (requiresClInit && !alreadyHasClinit) classDecl.addClinit();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:48,代码来源:HandleUtilityClass.java

示例5: handle

@Override public void handle(AnnotationValues<Synchronized> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SYNCHRONIZED_FLAG_USAGE, "@Synchronized");
	
	if (inNetbeansEditor(annotationNode)) return;
	
	deleteAnnotationIfNeccessary(annotationNode, Synchronized.class);
	JavacNode methodNode = annotationNode.up();
	
	if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof JCMethodDecl)) {
		annotationNode.addError("@Synchronized is legal only on methods.");
		
		return;
	}
	
	JCMethodDecl method = (JCMethodDecl)methodNode.get();
	
	if ((method.mods.flags & Flags.ABSTRACT) != 0) {
		annotationNode.addError("@Synchronized is legal only on concrete methods.");
		
		return;
	}
	boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
	String lockName = annotation.getInstance().value();
	boolean autoMake = false;
	if (lockName.length() == 0) {
		autoMake = true;
		lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
	}
	
	JavacTreeMaker maker = methodNode.getTreeMaker().at(ast.pos);
	Context context = methodNode.getContext();
	
	if (fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS) {
		if (!autoMake) {
			annotationNode.addError("The field " + lockName + " does not exist.");
			return;
		}
		JCExpression objectType = genJavaLangTypeRef(methodNode, ast.pos, "Object");
		//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
		JCNewArray newObjectArray = maker.NewArray(genJavaLangTypeRef(methodNode, ast.pos, "Object"),
				List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null);
		JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
				maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
				methodNode.toName(lockName), objectType, newObjectArray), ast, context);
		injectFieldAndMarkGenerated(methodNode.up(), fieldDecl);
	}
	
	if (method.body == null) return;
	
	JCExpression lockNode;
	if (isStatic) {
		lockNode = chainDots(methodNode, ast.pos, methodNode.up().getName(), lockName);
	} else {
		lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
	}
	
	recursiveSetGeneratedBy(lockNode, ast, context);
	method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), ast, context))), ast, context);
	
	methodNode.rebuild();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:61,代码来源:HandleSynchronized.java

示例6: isMethodAnnotation

private boolean isMethodAnnotation(EclipseNode annotationNode) {
	EclipseNode parent = annotationNode.up();
	if (parent == null) return false;
	return parent.getKind() == Kind.METHOD;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:5,代码来源:HandlerLibrary.java

示例7: handle

@Override public void handle(AnnotationValues<Synchronized> annotation, JCAnnotation ast, JavacNode annotationNode) {
	if (inNetbeansEditor(annotationNode)) return;
	
	deleteAnnotationIfNeccessary(annotationNode, Synchronized.class);
	JavacNode methodNode = annotationNode.up();
	
	if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof JCMethodDecl)) {
		annotationNode.addError("@Synchronized is legal only on methods.");
		
		return;
	}
	
	JCMethodDecl method = (JCMethodDecl)methodNode.get();
	
	if ((method.mods.flags & Flags.ABSTRACT) != 0) {
		annotationNode.addError("@Synchronized is legal only on concrete methods.");
		
		return;
	}
	boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
	String lockName = annotation.getInstance().value();
	boolean autoMake = false;
	if (lockName.length() == 0) {
		autoMake = true;
		lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
	}
	
	TreeMaker maker = methodNode.getTreeMaker().at(ast.pos);
	
	if (fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS) {
		if (!autoMake) {
			annotationNode.addError("The field " + lockName + " does not exist.");
			return;
		}
		JCExpression objectType = chainDots(methodNode, ast.pos, "java", "lang", "Object");
		//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
		JCNewArray newObjectArray = maker.NewArray(chainDots(methodNode, ast.pos, "java", "lang", "Object"),
				List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null);
		JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
				maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
				methodNode.toName(lockName), objectType, newObjectArray), ast);
		injectFieldSuppressWarnings(methodNode.up(), fieldDecl);
	}
	
	if (method.body == null) return;
	
	JCExpression lockNode;
	if (isStatic) {
		lockNode = chainDots(methodNode, ast.pos, methodNode.up().getName(), lockName);
	} else {
		lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
	}
	
	recursiveSetGeneratedBy(lockNode, ast);
	method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), ast))), ast);
	
	methodNode.rebuild();
}
 
开发者ID:redundent,项目名称:lombok,代码行数:58,代码来源:HandleSynchronized.java


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