mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 14:17:48 +00:00
Added ability to create new instances of AnnotationValues with all default values
This commit is contained in:
1 parent
ceeabe5103
commit
fb76daf5e4
1 file changed
+16
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-2012 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -118,6 +118,18 @@ public class AnnotationValues<A extends Annotation> {
|
||||
this.ast = ast;
|
||||
}
|
||||
|
||||
public static <A extends Annotation> AnnotationValues<A> of(Class<A> type) {
|
||||
return new AnnotationValues<A>(type, Collections.<String, AnnotationValue>emptyMap(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new annotation wrapper with all default values, and using the provided ast as lookup anchor for
|
||||
* class literals.
|
||||
*/
|
||||
public static <A extends Annotation> AnnotationValues<A> of(Class<A> type, LombokNode<?, ?, ?> ast) {
|
||||
return new AnnotationValues<A>(type, Collections.<String, AnnotationValue>emptyMap(), ast);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown on the fly if an actual annotation instance procured via the {@link #getInstance()} method is queried
|
||||
* for a method for which this AnnotationValues instance either doesn't have a guess or can't manage to fit
|
||||
@@ -423,7 +435,7 @@ public class AnnotationValues<A extends Annotation> {
|
||||
}
|
||||
|
||||
/* 2. Walk through non-star imports and search for a match. */ {
|
||||
for (String im : ast.getImportStatements()) {
|
||||
for (String im : ast == null ? Collections.<String>emptyList() : ast.getImportStatements()) {
|
||||
if (im.endsWith(".*")) continue;
|
||||
int idx = im.lastIndexOf('.');
|
||||
String simple = idx == -1 ? im : im.substring(idx+1);
|
||||
@@ -434,7 +446,7 @@ public class AnnotationValues<A extends Annotation> {
|
||||
}
|
||||
|
||||
/* 3. Walk through star imports and, if they start with "java.", use Class.forName based resolution. */ {
|
||||
List<String> imports = new ArrayList<String>(ast.getImportStatements());
|
||||
List<String> imports = ast == null ? Collections.<String>emptyList() : new ArrayList<String>(ast.getImportStatements());
|
||||
imports.add("java.lang.*");
|
||||
for (String im : imports) {
|
||||
if (!im.endsWith(".*") || !im.startsWith("java.")) continue;
|
||||
@@ -465,7 +477,7 @@ public class AnnotationValues<A extends Annotation> {
|
||||
|
||||
private static String inLocalPackage(LombokNode<?, ?, ?> node, String typeName) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration());
|
||||
if (node != null && node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration());
|
||||
if (result.length() > 0) result.append('.');
|
||||
result.append(typeName);
|
||||
return result.toString();
|
||||
|
||||
Reference in new issue
Block a user