Delete almost all code related to signature writing
Delete org.jetbrains.jet.rt.signature and jet.typeinfo packages from runtime, refactor BothSignatureWriter so that it now writes only java generic signature and saves parameter types and kinds
This commit is contained in:
committed by
Pavel V. Talanov
parent
5d647cac94
commit
763572663e
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package jet.typeinfo;
|
||||
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureVariance;
|
||||
|
||||
public enum TypeInfoVariance {
|
||||
INVARIANT("", JetSignatureVariance.INVARIANT) ,
|
||||
IN("in", JetSignatureVariance.IN),
|
||||
OUT("out", JetSignatureVariance.OUT);
|
||||
|
||||
private final String label;
|
||||
private final JetSignatureVariance variance;
|
||||
|
||||
TypeInfoVariance(String label, JetSignatureVariance variance) {
|
||||
this.label = label;
|
||||
this.variance = variance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
|
||||
public class JetSignatureAdapter implements JetSignatureVisitor {
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameterEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitClassBound() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterfaceBound() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitSuperclass() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterface() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitParameterType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitReturnType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitExceptionType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBaseType(char descriptor, boolean nullable) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeVariable(String name, boolean nullable) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassType(String name, boolean nullable, boolean forceReal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClassType(String name, boolean nullable, boolean forceReal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeArgument() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
|
||||
public class JetSignatureExceptionsAdapter implements JetSignatureVisitor {
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameterEnd() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitClassBound() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterfaceBound() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitSuperclass() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterface() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitParameterType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitReturnType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitExceptionType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBaseType(char descriptor, boolean nullable) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeVariable(String name, boolean nullable) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassType(String name, boolean nullable, boolean forceReal) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClassType(String name, boolean nullable, boolean forceReal) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeArgument() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
|
||||
/**
|
||||
* @see SignatureReader
|
||||
*/
|
||||
public class JetSignatureReader {
|
||||
|
||||
private final String signature;
|
||||
|
||||
public JetSignatureReader(String signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
|
||||
public void accept(JetSignatureVisitor v) {
|
||||
String signature = this.signature;
|
||||
int len = signature.length();
|
||||
int pos = acceptFormalTypeParameters(v);
|
||||
|
||||
if (signature.charAt(pos) == '(') {
|
||||
pos++;
|
||||
while (signature.charAt(pos) != ')') {
|
||||
pos = parseType(signature, pos, v.visitParameterType());
|
||||
}
|
||||
pos = parseType(signature, pos + 1, v.visitReturnType());
|
||||
while (pos < len) {
|
||||
pos = parseType(signature, pos + 1, v.visitExceptionType());
|
||||
}
|
||||
}
|
||||
else {
|
||||
pos = parseType(signature, pos, v.visitSuperclass());
|
||||
while (pos < len) {
|
||||
pos = parseType(signature, pos, v.visitInterface());
|
||||
}
|
||||
}
|
||||
|
||||
if (pos != signature.length()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public int acceptFormalTypeParameters(JetSignatureVisitor v) {
|
||||
int pos;
|
||||
char c;
|
||||
if (signature.length() > 0 && signature.charAt(0) == '<') {
|
||||
pos = 1;
|
||||
do {
|
||||
TypeInfoVariance variance;
|
||||
boolean reified = true;
|
||||
|
||||
if (signature.substring(pos).startsWith("erased ")) {
|
||||
reified = false;
|
||||
pos += "erased ".length();
|
||||
}
|
||||
if (signature.substring(pos).startsWith("in ")) {
|
||||
variance = TypeInfoVariance.IN;
|
||||
pos += "in ".length();
|
||||
}
|
||||
else if (signature.substring(pos).startsWith("out ")) {
|
||||
variance = TypeInfoVariance.OUT;
|
||||
pos += "out ".length();
|
||||
}
|
||||
else {
|
||||
variance = TypeInfoVariance.INVARIANT;
|
||||
pos += "".length();
|
||||
}
|
||||
int end = signature.indexOf(':', pos);
|
||||
if (end < 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
String typeParameterName = signature.substring(pos, end);
|
||||
if (typeParameterName.isEmpty()) {
|
||||
throw new IllegalStateException("incorrect signature: " + signature);
|
||||
}
|
||||
JetSignatureVisitor parameterVisitor = v.visitFormalTypeParameter(typeParameterName, variance, reified);
|
||||
pos = end + 1;
|
||||
|
||||
c = signature.charAt(pos);
|
||||
if (c == 'L' || c == 'M' || c == '[' || c == 'T' || c == '?') {
|
||||
pos = parseType(signature, pos, parameterVisitor.visitClassBound());
|
||||
}
|
||||
|
||||
while ((c = signature.charAt(pos)) == ':') {
|
||||
++pos;
|
||||
pos = parseType(signature, pos, parameterVisitor.visitInterfaceBound());
|
||||
}
|
||||
|
||||
parameterVisitor.visitFormalTypeParameterEnd();
|
||||
} while (c != '>');
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
pos = 0;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void acceptFormalTypeParametersOnly(JetSignatureVisitor v) {
|
||||
int r = acceptFormalTypeParameters(v);
|
||||
if (r != signature.length()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public int acceptType(JetSignatureVisitor v) {
|
||||
return parseType(this.signature, 0, v);
|
||||
}
|
||||
|
||||
public void acceptTypeOnly(JetSignatureVisitor v) {
|
||||
int r = acceptType(v);
|
||||
if (r != signature.length()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int parseType(
|
||||
String signature,
|
||||
int pos,
|
||||
JetSignatureVisitor v)
|
||||
{
|
||||
if (signature.length() == 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
char c;
|
||||
int start;
|
||||
int end;
|
||||
boolean visited;
|
||||
boolean inner;
|
||||
|
||||
boolean nullable;
|
||||
if (signature.charAt(pos) == '?') {
|
||||
nullable = true;
|
||||
pos++;
|
||||
}
|
||||
else {
|
||||
nullable = false;
|
||||
}
|
||||
|
||||
switch (c = signature.charAt(pos++)) {
|
||||
case 'Z':
|
||||
case 'C':
|
||||
case 'B':
|
||||
case 'S':
|
||||
case 'I':
|
||||
case 'F':
|
||||
case 'J':
|
||||
case 'D':
|
||||
case 'V':
|
||||
v.visitBaseType(c, nullable);
|
||||
return pos;
|
||||
|
||||
case '[':
|
||||
switch (c = signature.charAt(pos)) {
|
||||
case '+':
|
||||
case '-':
|
||||
return parseType(signature, pos + 1, v.visitArrayType(nullable, JetSignatureVariance.parseVariance(c)));
|
||||
default:
|
||||
return parseType(signature, pos, v.visitArrayType(nullable, JetSignatureVariance.INVARIANT));
|
||||
}
|
||||
|
||||
case 'T':
|
||||
end = signature.indexOf(';', pos);
|
||||
v.visitTypeVariable(signature.substring(pos, end), nullable);
|
||||
return end + 1;
|
||||
|
||||
case 'L':
|
||||
case 'M':
|
||||
boolean forceReal = signature.charAt(pos - 1) == 'M';
|
||||
start = pos;
|
||||
visited = false;
|
||||
inner = false;
|
||||
while (true) {
|
||||
switch (c = signature.charAt(pos++)) {
|
||||
case '.':
|
||||
case ';':
|
||||
if (!visited) {
|
||||
parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal);
|
||||
}
|
||||
if (c == ';') {
|
||||
v.visitEnd();
|
||||
return pos;
|
||||
}
|
||||
visited = false;
|
||||
inner = true;
|
||||
break;
|
||||
|
||||
case '<':
|
||||
parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal);
|
||||
visited = true;
|
||||
pos = parseTypeArguments(signature, pos, v);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
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, forceReal);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
public enum JetSignatureVariance {
|
||||
INVARIANT('='),
|
||||
IN('-'),
|
||||
OUT('+'),
|
||||
;
|
||||
|
||||
private final char c;
|
||||
|
||||
private JetSignatureVariance(char c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return c;
|
||||
}
|
||||
|
||||
public static JetSignatureVariance parseVariance(char c) {
|
||||
switch (c) {
|
||||
case '=': return INVARIANT;
|
||||
case '+': return OUT;
|
||||
case '-': return IN;
|
||||
default: throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
|
||||
/**
|
||||
* @see SignatureVisitor
|
||||
* @url http://confluence.jetbrains.net/display/JET/Jet+Signatures
|
||||
*/
|
||||
public interface JetSignatureVisitor {
|
||||
|
||||
/**
|
||||
* Wildcard for an "extends" type argument.
|
||||
*/
|
||||
char EXTENDS = '+';
|
||||
|
||||
/**
|
||||
* Wildcard for a "super" type argument.
|
||||
*/
|
||||
char SUPER = '-';
|
||||
|
||||
/**
|
||||
* Wildcard for a normal type argument.
|
||||
*/
|
||||
char INSTANCEOF = '=';
|
||||
|
||||
/**
|
||||
* Visits a formal type parameter.
|
||||
*
|
||||
* TODO should not store reified flag in signature
|
||||
*
|
||||
* @param name the name of the formal parameter.
|
||||
*/
|
||||
JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified);
|
||||
|
||||
void visitFormalTypeParameterEnd();
|
||||
|
||||
/**
|
||||
* Visits the class bound of the last visited formal type parameter.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the class bound.
|
||||
*/
|
||||
JetSignatureVisitor visitClassBound();
|
||||
|
||||
/**
|
||||
* Visits an interface bound of the last visited formal type parameter.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the interface bound.
|
||||
*/
|
||||
JetSignatureVisitor visitInterfaceBound();
|
||||
|
||||
/**
|
||||
* Visits the type of the super class.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the super class
|
||||
* type.
|
||||
*/
|
||||
JetSignatureVisitor visitSuperclass();
|
||||
|
||||
/**
|
||||
* Visits the type of an interface implemented by the class.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the interface type.
|
||||
*/
|
||||
JetSignatureVisitor visitInterface();
|
||||
|
||||
/**
|
||||
* Visits the type of a method parameter.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the parameter type.
|
||||
*/
|
||||
JetSignatureVisitor visitParameterType();
|
||||
|
||||
/**
|
||||
* Visits the return type of the method.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the return type.
|
||||
*/
|
||||
JetSignatureVisitor visitReturnType();
|
||||
|
||||
/**
|
||||
* Visits the type of a method exception.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the exception type.
|
||||
*/
|
||||
JetSignatureVisitor visitExceptionType();
|
||||
|
||||
/**
|
||||
* Visits a signature corresponding to a primitive type.
|
||||
*
|
||||
* @param descriptor the descriptor of the primitive type, or 'V' for
|
||||
* <tt>void</tt>.
|
||||
*/
|
||||
void visitBaseType(char descriptor, boolean nullable);
|
||||
|
||||
/**
|
||||
* Visits a signature corresponding to a type variable.
|
||||
*
|
||||
* @param name the name of the type variable.
|
||||
*/
|
||||
void visitTypeVariable(String name, boolean nullable);
|
||||
|
||||
/**
|
||||
* Visits a signature corresponding to an array type.
|
||||
*
|
||||
* @return a non null visitor to visit the signature of the array element
|
||||
* type.
|
||||
*/
|
||||
JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard);
|
||||
|
||||
/**
|
||||
* Starts the visit of a signature corresponding to a class or interface
|
||||
* type.
|
||||
*
|
||||
* @param name the internal name of the class or interface.
|
||||
*/
|
||||
void visitClassType(String name, boolean nullable, boolean forceReal);
|
||||
|
||||
/**
|
||||
* Visits an inner class.
|
||||
*
|
||||
* @param name the full name of the inner class.
|
||||
*/
|
||||
void visitInnerClassType(String name, boolean nullable, boolean forceReal);
|
||||
|
||||
/**
|
||||
* Visits an unbounded type argument of the last visited class or inner
|
||||
* class type.
|
||||
*/
|
||||
void visitTypeArgument();
|
||||
|
||||
/**
|
||||
* Visits a type argument of the last visited class or inner class type.
|
||||
*
|
||||
* @param wildcard '+', '-' or '='.
|
||||
* @return a non null visitor to visit the signature of the type argument.
|
||||
*/
|
||||
JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard);
|
||||
|
||||
/**
|
||||
* Ends the visit of a signature corresponding to a class or interface type.
|
||||
*/
|
||||
void visitEnd();
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.rt.signature;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
|
||||
/**
|
||||
* @see SignatureWriter
|
||||
*/
|
||||
public class JetSignatureWriter implements JetSignatureVisitor {
|
||||
|
||||
/**
|
||||
* Buffer used to construct the signature.
|
||||
*/
|
||||
private final StringBuffer buf = new StringBuffer();
|
||||
|
||||
/**
|
||||
* Indicates if the signature contains formal type parameters.
|
||||
*/
|
||||
private boolean hasFormals;
|
||||
|
||||
/**
|
||||
* Indicates if the signature contains method parameter types.
|
||||
*/
|
||||
private boolean hasParameters;
|
||||
|
||||
/**
|
||||
* Stack used to keep track of class types that have arguments. Each element
|
||||
* of this stack is a boolean encoded in one bit. The top of the stack is
|
||||
* the lowest order bit. Pushing false = *2, pushing true = *2+1, popping =
|
||||
* /2.
|
||||
*/
|
||||
private int argumentStack;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link SignatureWriter} object.
|
||||
*/
|
||||
public JetSignatureWriter() {
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Implementation of the SignatureVisitor interface
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) {
|
||||
if (!hasFormals) {
|
||||
hasFormals = true;
|
||||
buf.append('<');
|
||||
}
|
||||
if (!reified) {
|
||||
buf.append("erased ");
|
||||
}
|
||||
switch (variance) {
|
||||
case OUT:
|
||||
buf.append("out ");
|
||||
break;
|
||||
case IN:
|
||||
buf.append("in ");
|
||||
break;
|
||||
case INVARIANT:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
buf.append(name);
|
||||
buf.append(':');
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameterEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitClassBound() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitInterfaceBound() {
|
||||
buf.append(':');
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitSuperclass() {
|
||||
endFormals();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitInterface() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitParameterType() {
|
||||
endFormals();
|
||||
if (!hasParameters) {
|
||||
hasParameters = true;
|
||||
buf.append('(');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitReturnType() {
|
||||
endFormals();
|
||||
if (!hasParameters) {
|
||||
buf.append('(');
|
||||
}
|
||||
buf.append(')');
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitExceptionType() {
|
||||
buf.append('^');
|
||||
return this;
|
||||
}
|
||||
|
||||
private void visitNullabe(boolean nullable) {
|
||||
if (nullable) {
|
||||
buf.append('?');
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBaseType(char descriptor, boolean nullable) {
|
||||
visitNullabe(nullable);
|
||||
buf.append(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeVariable(String name, boolean nullable) {
|
||||
visitNullabe(nullable);
|
||||
buf.append('T');
|
||||
buf.append(name);
|
||||
buf.append(';');
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
|
||||
visitNullabe(nullable);
|
||||
buf.append('[');
|
||||
if (wildcard != JetSignatureVariance.INVARIANT) {
|
||||
buf.append(wildcard.getChar());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassType(String name, boolean nullable, boolean forceReal) {
|
||||
visitNullabe(nullable);
|
||||
buf.append(forceReal ? 'M' : 'L');
|
||||
buf.append(name);
|
||||
argumentStack *= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClassType(String name, boolean nullable, boolean forceReal) {
|
||||
endArguments();
|
||||
visitNullabe(nullable);
|
||||
buf.append('.');
|
||||
buf.append(name);
|
||||
argumentStack *= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeArgument() {
|
||||
if (argumentStack % 2 == 0) {
|
||||
++argumentStack;
|
||||
buf.append('<');
|
||||
}
|
||||
buf.append('*');
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureWriter visitTypeArgument(JetSignatureVariance variance) {
|
||||
if (argumentStack % 2 == 0) {
|
||||
++argumentStack;
|
||||
buf.append('<');
|
||||
}
|
||||
if (variance != JetSignatureVariance.INVARIANT) {
|
||||
buf.append(variance.getChar());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
endArguments();
|
||||
buf.append(';');
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ends the formal type parameters section of the signature.
|
||||
*/
|
||||
private void endFormals() {
|
||||
if (hasFormals) {
|
||||
hasFormals = false;
|
||||
buf.append('>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the type arguments of a class or inner class type.
|
||||
*/
|
||||
private void endArguments() {
|
||||
if (argumentStack % 2 != 0) {
|
||||
buf.append('>');
|
||||
}
|
||||
argumentStack /= 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user