This commit is contained in:
Jesper Wilhelmsson 2020-12-21 09:09:05 +00:00
commit d234388042
76 changed files with 1559 additions and 541 deletions

View file

@ -38,6 +38,10 @@ public interface AnnotatedParameterizedType extends AnnotatedType {
/**
* Returns the potentially annotated actual type arguments of this parameterized type.
*
* <p>Note that in some cases, the returned array can be empty. This can occur
* if this annotated type represents a non-parameterized type nested within
* a parameterized type.
*
* @return the potentially annotated actual type arguments of this parameterized type
* @see ParameterizedType#getActualTypeArguments()
*/

View file

@ -662,7 +662,7 @@ public final class Constructor<T> extends Executable {
getConstantPool(thisDeclClass),
this,
thisDeclClass,
resolveToOwnerType(enclosingClass),
parameterize(enclosingClass),
TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
}
}

View file

@ -699,10 +699,29 @@ public abstract class Executable extends AccessibleObject
getConstantPool(getDeclaringClass()),
this,
getDeclaringClass(),
resolveToOwnerType(getDeclaringClass()),
parameterize(getDeclaringClass()),
TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
}
Type parameterize(Class<?> c) {
Class<?> ownerClass = c.getDeclaringClass();
TypeVariable<?>[] typeVars = c.getTypeParameters();
if (ownerClass == null) { // base case
if (typeVars.length == 0)
return c;
else
return ParameterizedTypeImpl.make(c, typeVars, null);
}
// Resolve owner
Type ownerType = parameterize(ownerClass);
if (ownerType instanceof Class<?> && typeVars.length == 0) // We have yet to encounter type parameters
return c;
else
return ParameterizedTypeImpl.make(c, typeVars, ownerType);
}
/**
* Returns an array of {@code AnnotatedType} objects that represent the use
* of types to specify formal parameter types of the method/constructor
@ -753,24 +772,4 @@ public abstract class Executable extends AccessibleObject
getGenericExceptionTypes(),
TypeAnnotation.TypeAnnotationTarget.THROWS);
}
static Type resolveToOwnerType(Class<?> c) {
TypeVariable<?>[] v = c.getTypeParameters();
Type o = resolveOwner(c);
Type t;
if (o != null || v.length > 0) {
t = ParameterizedTypeImpl.make(c, v, o);
} else {
t = c;
}
return t;
}
private static Type resolveOwner(Class<?> t) {
if (Modifier.isStatic(t.getModifiers()) || !(t.isLocalClass() || t.isMemberClass() || t.isAnonymousClass())) {
return null;
}
Class<?> d = t.getDeclaringClass();
return ParameterizedTypeImpl.make(d, d.getTypeParameters(), resolveOwner(d));
}
}

View file

@ -2063,7 +2063,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
Node prev = null;
Node firstTail = null;
Branch branch = null;
BranchConn branchConn = null;
Node branchConn = null;
for (;;) {
Node node = sequence(end);
@ -2211,24 +2211,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
break;
}
if (node instanceof LineEnding) {
LineEnding le = (LineEnding)node;
node = closureOfLineEnding(le);
if (node != le) {
// LineEnding was replaced with an anonymous group
if (head == null)
head = node;
else
tail.next = node;
// Double return: Tail was returned in root
tail = root;
continue;
}
} else {
node = closure(node);
}
node = closure(node);
/* save the top dot-greedy nodes (.*, .+) as well
if (node instanceof GreedyCharProperty &&
((GreedyCharProperty)node).cp instanceof Dot) {
@ -3096,31 +3079,18 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
if (saveTCNCount < topClosureNodes.size())
topClosureNodes.subList(saveTCNCount, topClosureNodes.size()).clear();
return groupWithClosure(node, head, tail, capturingGroup);
}
/**
* Transforms a Group with quantifiers into some special constructs
* (such as Branch or Loop/GroupCurly), if necessary.
*
* This method is applied either to actual groups or to the Unicode
* linebreak (aka \\R) represented as an anonymous group.
*/
private Node groupWithClosure(Node node, Node head, Node tail,
boolean capturingGroup)
{
if (node instanceof Ques) {
Ques ques = (Ques) node;
if (ques.type == Qtype.POSSESSIVE) {
root = node;
return node;
}
BranchConn branchConn = new BranchConn();
tail = tail.next = branchConn;
tail.next = new BranchConn();
tail = tail.next;
if (ques.type == Qtype.GREEDY) {
head = new Branch(head, null, branchConn);
head = new Branch(head, null, tail);
} else { // Reluctant quantifier
head = new Branch(null, head, branchConn);
head = new Branch(null, head, tail);
}
root = tail;
return head;
@ -3297,31 +3267,6 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
return new Curly(prev, cmin, MAX_REPS, qtype);
}
/**
* Processing repetition of a Unicode linebreak \\R.
*/
private Node closureOfLineEnding(LineEnding le) {
int ch = peek();
if (ch != '?' && ch != '*' && ch != '+' && ch != '{') {
return le;
}
// Replace the LineEnding with an anonymous group
// (?:\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029])
Node grHead = createGroup(true);
Node grTail = root;
BranchConn branchConn = new BranchConn();
branchConn.next = grTail;
Node slice = new Slice(new int[] {0x0D, 0x0A});
slice.next = branchConn;
Node chClass = newCharProperty(x -> x == 0x0A || x == 0x0B ||
x == 0x0C || x == 0x0D || x == 0x85 || x == 0x2028 ||
x == 0x2029);
chClass.next = branchConn;
grHead.next = new Branch(slice, chClass, branchConn);
return groupWithClosure(closure(grHead), grHead, grTail, false);
}
/**
* Processes repetition. If the next character peeked is a quantifier
* then new nodes must be appended to handle the repetition.
@ -4777,8 +4722,8 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
static final class Branch extends Node {
Node[] atoms = new Node[2];
int size = 2;
BranchConn conn;
Branch(Node first, Node second, BranchConn branchConn) {
Node conn;
Branch(Node first, Node second, Node branchConn) {
conn = branchConn;
atoms[0] = first;
atoms[1] = second;
@ -4786,10 +4731,9 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
void add(Node node) {
if (size >= atoms.length) {
int len = ArraysSupport.newLength(size,
1, /* minimum growth */
size /* preferred growth */);
atoms = Arrays.copyOf(atoms, len);
Node[] tmp = new Node[atoms.length*2];
System.arraycopy(atoms, 0, tmp, 0, atoms.length);
atoms = tmp;
}
atoms[size++] = node;
}