Skip to content

Commit

Permalink
TypeMaker refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 19, 2023
1 parent dd69c4c commit 0a10437
Showing 1 changed file with 25 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ private MethodTypes parseMethodSignature(String internalTypeName, String methodN
methodTypes.setTypeParameters(parseTypeParameters(reader));

// Parameters
if (reader.read() != '(') {
throw new SignatureFormatException(signature);
}
ensureReadCharacter(reader, '(');

Type firstParameterType = parseReferenceTypeSignature(reader);

Expand All @@ -395,9 +393,7 @@ private MethodTypes parseMethodSignature(String internalTypeName, String methodN
methodTypes.setParameterTypes(types);
}

if (reader.read() != ')') {
throw new SignatureFormatException(signature);
}
ensureReadCharacter(reader, ')');

// Result
methodTypes.setReturnedType(parseReferenceTypeSignature(reader));
Expand Down Expand Up @@ -474,9 +470,7 @@ private BaseTypeParameter parseTypeParameters(SignatureReader reader) {
typeParameters = list;
}

if (reader.read() != '>') {
throw new SignatureFormatException(reader.signature);
}
ensureReadCharacter(reader, '>');

return typeParameters;
}
Expand Down Expand Up @@ -555,11 +549,7 @@ ObjectType parseClassTypeSignature(SignatureReader reader, int dimension) {
if (reader.nextEqualsTo('L')) {
// Skip 'L'. Parse 'PackageSpecifier* SimpleClassTypeSignature'
int index = ++reader.index;
char endMarker = reader.searchEndMarker();

if (endMarker == 0) {
throw new SignatureFormatException(reader.signature);
}
char endMarker = ensureNonZeroEndMarker(reader);

String internalTypeName = reader.substring(index);
ObjectType ot = makeFromInternalTypeName(internalTypeName);
Expand All @@ -568,9 +558,7 @@ ObjectType parseClassTypeSignature(SignatureReader reader, int dimension) {
// Skip '<'
reader.index++;
ot = ot.createType(parseTypeArguments(reader));
if (reader.read() != '>') {
throw new SignatureFormatException(reader.signature);
}
ensureReadCharacter(reader, '>');
}

String name;
Expand All @@ -579,11 +567,7 @@ ObjectType parseClassTypeSignature(SignatureReader reader, int dimension) {
while (reader.nextEqualsTo('.')) {
// Skip '.'
index = ++reader.index;
endMarker = reader.searchEndMarker();

if (endMarker == 0) {
throw new SignatureFormatException(reader.signature);
}
endMarker = ensureNonZeroEndMarker(reader);

name = reader.substring(index);
internalTypeName = String.join("$", internalTypeName, name);
Expand All @@ -599,9 +583,7 @@ ObjectType parseClassTypeSignature(SignatureReader reader, int dimension) {
reader.index++;

BaseTypeArgument typeArguments = parseTypeArguments(reader);
if (reader.read() != '>') {
throw new SignatureFormatException(reader.signature);
}
ensureReadCharacter(reader, '>');

ot = new InnerObjectType(internalTypeName, qualifiedName, name, typeArguments, ot);
} else {
Expand All @@ -617,6 +599,20 @@ ObjectType parseClassTypeSignature(SignatureReader reader, int dimension) {
return null;
}

private static char ensureNonZeroEndMarker(SignatureReader reader) {
char endMarker = reader.searchEndMarker();
if (endMarker == 0) {
throw new SignatureFormatException(reader.signature);
}
return endMarker;
}

private static void ensureReadCharacter(SignatureReader reader, char closingCharacter) {
if (reader.read() != closingCharacter) {
throw new SignatureFormatException(reader.signature);
}
}

/** Rules: TypeArguments: '<' TypeArgument+ '>' */
private BaseTypeArgument parseTypeArguments(SignatureReader reader) {
TypeArgument firstTypeArgument = parseTypeArgument(reader);
Expand Down Expand Up @@ -764,39 +760,27 @@ static boolean isAClassTypeSignature(SignatureReader reader) {
reader.index++;

// Parse 'PackageSpecifier* SimpleClassTypeSignature'
char endMarker = reader.searchEndMarker();

if (endMarker == 0) {
throw new SignatureFormatException(reader.signature);
}
char endMarker = ensureNonZeroEndMarker(reader);

if (endMarker == '<') {
// Skip '<'
reader.index++;
isATypeArguments(reader);
if (reader.read() != '>') {
throw new SignatureFormatException(reader.signature);
}
ensureReadCharacter(reader, '>');
}

// Parse 'ClassTypeSignatureSuffix*'
while (reader.nextEqualsTo('.')) {
// Skip '.'
reader.index++;

endMarker = reader.searchEndMarker();

if (endMarker == 0) {
throw new SignatureFormatException(reader.signature);
}
endMarker = ensureNonZeroEndMarker(reader);

if (endMarker == '<') {
// Skip '<'
reader.index++;
isATypeArguments(reader);
if (reader.read() != '>') {
throw new SignatureFormatException(reader.signature);
}
ensureReadCharacter(reader, '>');
}
}

Expand Down Expand Up @@ -1326,10 +1310,6 @@ public void setMethodReturnedType(String internalTypeName, String methodName, St
makeMethodTypes(internalTypeName, methodName, descriptor).setReturnedType(type);
}

public MethodTypes makeMethodTypes(String internalTypeName, String descriptor) {
return parseMethodSignature(internalTypeName, null, descriptor, null);
}

public MethodTypes makeMethodTypes(String internalTypeName, String methodName, String descriptor) {
MethodTypes methodTypes = loadMethodTypes(internalTypeName, methodName, descriptor);

Expand Down

0 comments on commit 0a10437

Please sign in to comment.