本文整理汇总了Java中lombok.javac.JavacNode.get方法的典型用法代码示例。如果您正苦于以下问题:Java JavacNode.get方法的具体用法?Java JavacNode.get怎么用?Java JavacNode.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lombok.javac.JavacNode
的用法示例。
在下文中一共展示了JavacNode.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllFields
import lombok.javac.JavacNode; //导入方法依赖的package包/类
public static List<JavacNode> findAllFields(JavacNode typeNode) {
ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>();
for (JavacNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD) continue;
JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
//Skip fields that start with $
if (fieldDecl.name.toString().startsWith("$")) continue;
long fieldFlags = fieldDecl.mods.flags;
//Skip static fields.
if ((fieldFlags & Flags.STATIC) != 0) continue;
//Skip initialized final fields
boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
if (!isFinal || fieldDecl.init == null) fields.append(child);
}
return fields.toList();
}
示例2: findAnnotations
import lombok.javac.JavacNode; //导入方法依赖的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();
}
示例3: fieldExists
import lombok.javac.JavacNode; //导入方法依赖的package包/类
/**
* Checks if there is a field with the provided name.
*
* @param fieldName the field name to check for.
* @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
*/
public static MemberExistsResult fieldExists(String fieldName, JavacNode node) {
node = upToTypeNode(node);
if (node != null && node.get() instanceof JCClassDecl) {
for (JCTree def : ((JCClassDecl)node.get()).defs) {
if (def instanceof JCVariableDecl) {
if (((JCVariableDecl)def).name.contentEquals(fieldName)) {
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
}
}
return MemberExistsResult.NOT_EXISTS;
}
示例4: fieldQualifiesForGetterGeneration
import lombok.javac.JavacNode; //导入方法依赖的package包/类
public boolean fieldQualifiesForGetterGeneration(JavacNode field) {
if (field.getKind() != Kind.FIELD) return false;
JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
//Skip fields that start with $
if (fieldDecl.name.toString().startsWith("$")) return false;
//Skip static fields.
if ((fieldDecl.mods.flags & Flags.STATIC) != 0) return false;
return true;
}
示例5: generateBuilderFields
import lombok.javac.JavacNode; //导入方法依赖的package包/类
public void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JCTree source) {
int len = builderFields.size();
java.util.List<JavacNode> existing = new ArrayList<JavacNode>();
for (JavacNode child : builderType.down()) {
if (child.getKind() == Kind.FIELD) existing.add(child);
}
top:
for (int i = len - 1; i >= 0; i--) {
BuilderFieldData bfd = builderFields.get(i);
if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source));
} else {
for (JavacNode exists : existing) {
Name n = ((JCVariableDecl) exists.get()).name;
if (n.equals(bfd.name)) {
bfd.createdFields.add(exists);
continue top;
}
}
JavacTreeMaker maker = builderType.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PRIVATE);
JCVariableDecl newField = maker.VarDef(mods, bfd.name, cloneType(maker, bfd.type, source, builderType.getContext()), null);
bfd.createdFields.add(injectFieldAndMarkGenerated(builderType, newField));
}
}
}
示例6: handle
import lombok.javac.JavacNode; //导入方法依赖的package包/类
@Override public void handle(AnnotationValues<Value> annotation, JCAnnotation ast, JavacNode annotationNode) {
@SuppressWarnings("deprecation")
Class<? extends Annotation> oldExperimentalValue = lombok.experimental.Value.class;
handleFlagUsage(annotationNode, ConfigurationKeys.VALUE_FLAG_USAGE, "@Value");
deleteAnnotationIfNeccessary(annotationNode, Value.class, oldExperimentalValue);
JavacNode typeNode = annotationNode.up();
boolean notAClass = !isClass(typeNode);
if (notAClass) {
annotationNode.addError("@Value is only supported on a class.");
return;
}
String staticConstructorName = annotation.getInstance().staticConstructor();
if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, typeNode)) {
JCModifiers jcm = ((JCClassDecl) typeNode.get()).mods;
if ((jcm.flags & Flags.FINAL) == 0) {
jcm.flags |= Flags.FINAL;
typeNode.rebuild();
}
}
new HandleFieldDefaults().generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true);
// TODO move this to the end OR move it to the top in eclipse.
new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, SkipIfConstructorExists.YES, annotationNode);
new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
}
示例7: makeSimpleSetterMethodForBuilder
import lombok.javac.JavacNode; //导入方法依赖的package包/类
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);
}
示例8: handleMethodCall
import lombok.javac.JavacNode; //导入方法依赖的package包/类
private void handleMethodCall(final JCMethodInvocation methodCall) {
JavacNode methodCallNode = annotationNode.getAst().get(methodCall);
if (methodCallNode == null) {
// This should mean the node does not exist in the source at all. This is the case for generated nodes, such as implicit super() calls.
return;
}
JavacNode surroundingType = upToTypeNode(methodCallNode);
TypeSymbol surroundingTypeSymbol = ((JCClassDecl)surroundingType.get()).sym;
JCExpression receiver = receiverOf(methodCall);
String methodName = methodNameOf(methodCall);
if ("this".equals(methodName) || "super".equals(methodName)) return;
Type resolvedMethodCall = CLASS_AND_METHOD.resolveMember(methodCallNode, methodCall);
if (resolvedMethodCall == null) return;
if (!suppressBaseMethods && !(resolvedMethodCall instanceof ErrorType)) return;
Type receiverType = CLASS_AND_METHOD.resolveMember(methodCallNode, receiver);
if (receiverType == null) return;
if (receiverType.tsym.toString().endsWith(receiver.toString())) return;
Types types = Types.instance(annotationNode.getContext());
for (Extension extension : extensions) {
TypeSymbol extensionProvider = extension.extensionProvider;
if (surroundingTypeSymbol == extensionProvider) continue;
for (MethodSymbol extensionMethod : extension.extensionMethods) {
if (!methodName.equals(extensionMethod.name.toString())) continue;
Type extensionMethodType = extensionMethod.type;
if (!MethodType.class.isInstance(extensionMethodType) && !ForAll.class.isInstance(extensionMethodType)) continue;
Type firstArgType = types.erasure(extensionMethodType.asMethodType().argtypes.get(0));
if (!types.isAssignable(receiverType, firstArgType)) continue;
methodCall.args = methodCall.args.prepend(receiver);
methodCall.meth = chainDotsString(annotationNode, extensionProvider.toString() + "." + methodName);
return;
}
}
}
示例9: getFieldType
import lombok.javac.JavacNode; //导入方法依赖的package包/类
/**
* Returns the type of the field, unless a getter exists for this field, in which case the return type of the getter is returned.
*
* @see #createFieldAccessor(TreeMaker, JavacNode, FieldAccess)
*/
static JCExpression getFieldType(JavacNode field, FieldAccess fieldAccess) {
boolean lookForGetter = lookForGetter(field, fieldAccess);
GetterMethod getter = lookForGetter ? findGetter(field) : null;
if (getter == null) {
return ((JCVariableDecl)field.get()).vartype;
}
return getter.type;
}
示例10: generateNullCheck
import lombok.javac.JavacNode; //导入方法依赖的package包/类
/**
* Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
* variable name as message.
*
* @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
*/
public static JCStatement generateNullCheck(JavacTreeMaker maker, JavacNode variable, JavacNode source) {
NullCheckExceptionType exceptionType = source.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;
JCVariableDecl varDecl = (JCVariableDecl) variable.get();
if (isPrimitive(varDecl.vartype)) return null;
Name fieldName = varDecl.name;
JCExpression exType = genTypeRef(variable, exceptionType.getExceptionType());
JCExpression exception = maker.NewClass(null, List.<JCExpression>nil(), exType, List.<JCExpression>of(maker.Literal(exceptionType.toExceptionMessage(fieldName.toString()))), null);
JCStatement throwStatement = maker.Throw(exception);
JCBlock throwBlock = maker.Block(0, List.of(throwStatement));
return maker.If(maker.Binary(CTC_EQUAL, maker.Ident(fieldName), maker.Literal(CTC_BOT, null)), throwBlock, null);
}
示例11: isFieldDeprecated
import lombok.javac.JavacNode; //导入方法依赖的package包/类
/**
* Returns if a field is marked deprecated, either by {@code @Deprecated} or in javadoc
* @param field the field to check
* @return {@code true} if a field is marked deprecated, either by {@code @Deprecated} or in javadoc, otherwise {@code false}
*/
public static boolean isFieldDeprecated(JavacNode field) {
JCVariableDecl fieldNode = (JCVariableDecl) field.get();
if ((fieldNode.mods.flags & Flags.DEPRECATED) != 0) {
return true;
}
for (JavacNode child : field.down()) {
if (annotationTypeMatches(Deprecated.class, child)) {
return true;
}
}
return false;
}
示例12: createFieldAccessor
import lombok.javac.JavacNode; //导入方法依赖的package包/类
static JCExpression createFieldAccessor(JavacTreeMaker maker, JavacNode field, FieldAccess fieldAccess, JCExpression receiver) {
boolean lookForGetter = lookForGetter(field, fieldAccess);
GetterMethod getter = lookForGetter ? findGetter(field) : null;
JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
if (getter == null) {
if (receiver == null) {
if ((fieldDecl.mods.flags & Flags.STATIC) == 0) {
receiver = maker.Ident(field.toName("this"));
} else {
JavacNode containerNode = field.up();
if (containerNode != null && containerNode.get() instanceof JCClassDecl) {
JCClassDecl container = (JCClassDecl) field.up().get();
receiver = maker.Ident(container.name);
}
}
}
return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name);
}
if (receiver == null) receiver = maker.Ident(field.toName("this"));
JCMethodInvocation call = maker.Apply(List.<JCExpression>nil(),
maker.Select(receiver, getter.name), List.<JCExpression>nil());
return call;
}
示例13: shouldReturnThis
import lombok.javac.JavacNode; //导入方法依赖的package包/类
/**
* When generating a setter, the setter either returns void (beanspec) or Self (fluent).
* This method scans for the {@code Accessors} annotation to figure that out.
*/
public static boolean shouldReturnThis(JavacNode field) {
if ((((JCVariableDecl) field.get()).mods.flags & Flags.STATIC) != 0) return false;
AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
return HandlerUtil.shouldReturnThis0(accessors, field.getAst());
}
示例14: findAllStaticMethodNames
import lombok.javac.JavacNode; //导入方法依赖的package包/类
private static Set<String> findAllStaticMethodNames(JavacNode typeNode) {
Set<String> methodNames = new LinkedHashSet<>();
for (JavacNode child : typeNode.down()) {
if (child.getKind() != AST.Kind.METHOD) continue;
JCTree.JCMethodDecl methodDecl = (JCTree.JCMethodDecl) child.get();
long methodFlags = methodDecl.mods.flags;
//Take static methods
if ((methodFlags & Flags.STATIC) != 0) {
methodNames.add(child.getName());
}
}
return methodNames;
}
示例15: upToTypeNode
import lombok.javac.JavacNode; //导入方法依赖的package包/类
public static JavacNode upToTypeNode(JavacNode node) {
if (node == null) throw new NullPointerException("node");
while ((node != null) && !(node.get() instanceof JCClassDecl)) node = node.up();
return node;
}