refactoring
extracted methods parseTypeConstructor, parseTypeArguments
This commit is contained in:
@@ -144,15 +144,19 @@ public class JetSignatureReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
int start, end;
|
int start;
|
||||||
boolean visited, inner;
|
int end;
|
||||||
String name;
|
boolean visited;
|
||||||
|
boolean inner;
|
||||||
|
|
||||||
boolean nullable = false;
|
boolean nullable;
|
||||||
if (signature.charAt(pos) == '?') {
|
if (signature.charAt(pos) == '?') {
|
||||||
nullable = true;
|
nullable = true;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
nullable = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (c = signature.charAt(pos++)) {
|
switch (c = signature.charAt(pos++)) {
|
||||||
case 'Z':
|
case 'Z':
|
||||||
@@ -186,13 +190,7 @@ public class JetSignatureReader {
|
|||||||
case '.':
|
case '.':
|
||||||
case ';':
|
case ';':
|
||||||
if (!visited) {
|
if (!visited) {
|
||||||
name = signature.substring(start, pos - 1);
|
parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal);
|
||||||
if (inner) {
|
|
||||||
v.visitInnerClassType(name, nullable);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
v.visitClassType(name, nullable, forceReal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (c == ';') {
|
if (c == ';') {
|
||||||
v.visitEnd();
|
v.visitEnd();
|
||||||
@@ -204,35 +202,12 @@ public class JetSignatureReader {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '<':
|
case '<':
|
||||||
name = signature.substring(start, pos - 1);
|
parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal);
|
||||||
if (inner) {
|
|
||||||
v.visitInnerClassType(name, nullable);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
v.visitClassType(name, nullable, forceReal);
|
|
||||||
}
|
|
||||||
visited = true;
|
visited = true;
|
||||||
top: while (true) {
|
pos = parseTypeArguments(signature, pos, v);
|
||||||
switch (c = signature.charAt(pos)) {
|
|
||||||
case '>':
|
default:
|
||||||
break top;
|
break;
|
||||||
case '*':
|
|
||||||
++pos;
|
|
||||||
v.visitTypeArgument();
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
case '-':
|
|
||||||
pos = parseType(signature,
|
|
||||||
pos + 1,
|
|
||||||
v.visitTypeArgument(JetSignatureVariance.parseVariance(c)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pos = parseType(signature,
|
|
||||||
pos,
|
|
||||||
v.visitTypeArgument(JetSignatureVariance.INVARIANT));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -240,5 +215,46 @@ public class JetSignatureReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void parseTypeConstructor(
|
||||||
|
String signature,
|
||||||
|
JetSignatureVisitor v,
|
||||||
|
int start,
|
||||||
|
int pos,
|
||||||
|
boolean inner,
|
||||||
|
boolean nullable,
|
||||||
|
boolean forceReal
|
||||||
|
) {
|
||||||
|
String name = signature.substring(start, pos - 1);
|
||||||
|
if (inner) {
|
||||||
|
v.visitInnerClassType(name, nullable);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
v.visitClassType(name, nullable, forceReal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int parseTypeArguments(String signature, int pos, JetSignatureVisitor v) {
|
||||||
|
char c;
|
||||||
|
while (true) {
|
||||||
|
switch (c = signature.charAt(pos)) {
|
||||||
|
case '>':
|
||||||
|
return pos;
|
||||||
|
case '*':
|
||||||
|
++pos;
|
||||||
|
v.visitTypeArgument();
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
case '-':
|
||||||
|
pos = parseType(signature,
|
||||||
|
pos + 1,
|
||||||
|
v.visitTypeArgument(JetSignatureVariance.parseVariance(c)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pos = parseType(signature,
|
||||||
|
pos,
|
||||||
|
v.visitTypeArgument(JetSignatureVariance.INVARIANT));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user