本文整理汇总了Java中org.eclipse.jdt.internal.compiler.lookup.TypeBinding.erasure方法的典型用法代码示例。如果您正苦于以下问题:Java TypeBinding.erasure方法的具体用法?Java TypeBinding.erasure怎么用?Java TypeBinding.erasure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.lookup.TypeBinding
的用法示例。
在下文中一共展示了TypeBinding.erasure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: typeBindingToSignature
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private static String typeBindingToSignature(TypeBinding binding) {
binding = binding.erasure();
if (binding != null && binding.isBaseType()) {
return new String (binding.sourceName());
} else if (binding instanceof ReferenceBinding) {
String pkg = binding.qualifiedPackageName() == null ? "" : new String(binding.qualifiedPackageName());
String qsn = binding.qualifiedSourceName() == null ? "" : new String(binding.qualifiedSourceName());
return pkg.isEmpty() ? qsn : (pkg + "." + qsn);
} else if (binding instanceof ArrayBinding) {
StringBuilder out = new StringBuilder();
out.append(typeBindingToSignature(binding.leafComponentType()));
for (int i = 0; i < binding.dimensions(); i++) out.append("[]");
return out.toString();
}
return "";
}
示例2: computeConversion
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Base types need that the widening is explicitly done by the compiler using some bytecode like i2f.
* Also check unsafe type operations.
*/
public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) {
if (runtimeType == null || compileTimeType == null)
return;
if (this.implicitConversion != 0) return; // already set independently
// it is possible for a Byte to be unboxed to a byte & then converted to an int
// but it is not possible for a byte to become Byte & then assigned to an Integer,
// or to become an int before boxed into an Integer
if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) {
if (!compileTimeType.isBaseType()) {
TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType);
this.implicitConversion = TypeIds.UNBOXING;
scope.problemReporter().autoboxing(this, compileTimeType, runtimeType);
compileTimeType = unboxedType;
}
} else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) {
TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType);
if (TypeBinding.equalsEquals(boxedType, runtimeType)) // Object o = 12;
boxedType = compileTimeType;
this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id;
scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType));
return;
} else if (this.constant != Constant.NotAConstant && this.constant.typeID() != TypeIds.T_JavaLangString) {
this.implicitConversion = TypeIds.BOXING;
return;
}
int compileTimeTypeID, runtimeTypeID;
if ((compileTimeTypeID = compileTimeType.id) >= TypeIds.T_LastWellKnownTypeId) { // e.g. ? extends String ==> String (103227); >= TypeIds.T_LastWellKnownTypeId implies TypeIds.NoId
compileTimeTypeID = compileTimeType.erasure().id == TypeIds.T_JavaLangString ? TypeIds.T_JavaLangString : TypeIds.T_JavaLangObject;
} else if (runtimeType.isPrimitiveType() && compileTimeType instanceof ReferenceBinding && !compileTimeType.isBoxedPrimitiveType()) {
compileTimeTypeID = TypeIds.T_JavaLangObject; // treatment is the same as for jlO.
}
switch (runtimeTypeID = runtimeType.id) {
case T_byte :
case T_short :
case T_char :
if (compileTimeTypeID == TypeIds.T_JavaLangObject) {
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
} else {
this.implicitConversion |= (TypeIds.T_int << 4) + compileTimeTypeID;
}
break;
case T_JavaLangString :
case T_float :
case T_boolean :
case T_double :
case T_int : //implicitConversion may result in i2i which will result in NO code gen
case T_long :
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
break;
default : // regular object ref
// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {
// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);
// }
}
}
示例3: resolveStatements
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void resolveStatements() {
super.resolveStatements();
if (this.arguments != null) {
this.scope.problemReporter().annotationMembersCannotHaveParameters(this);
}
if (this.typeParameters != null) {
this.scope.problemReporter().annotationMembersCannotHaveTypeParameters(this);
}
if (this.extendedDimensions != 0) {
this.scope.problemReporter().illegalExtendedDimensions(this);
}
if (this.binding == null) return;
TypeBinding returnTypeBinding = this.binding.returnType;
if (returnTypeBinding != null) {
// annotation methods can only return base types, String, Class, enum type, annotation types and arrays of these
checkAnnotationMethodType: {
TypeBinding leafReturnType = returnTypeBinding.leafComponentType();
if (returnTypeBinding.dimensions() <= 1) { // only 1-dimensional array permitted
switch (leafReturnType.erasure().id) {
case T_byte :
case T_short :
case T_char :
case T_int :
case T_long :
case T_float :
case T_double :
case T_boolean :
case T_JavaLangString :
case T_JavaLangClass :
break checkAnnotationMethodType;
}
if (leafReturnType.isEnum() || leafReturnType.isAnnotationType())
break checkAnnotationMethodType;
}
this.scope.problemReporter().invalidAnnotationMemberType(this);
}
if (this.defaultValue != null) {
MemberValuePair pair = new MemberValuePair(this.selector, this.sourceStart, this.sourceEnd, this.defaultValue);
pair.binding = this.binding;
pair.resolveTypeExpecting(this.scope, returnTypeBinding);
this.binding.setDefaultValue(org.eclipse.jdt.internal.compiler.lookup.ElementValuePair.getValue(this.defaultValue));
} else { // let it know it does not have a default value so it won't try to find it
this.binding.setDefaultValue(null);
}
}
}
示例4: typeMismatchError
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
if (this.options.sourceLevel < ClassFileConstants.JDK1_5) { // don't expose type variable names, complain on erased types
if (actualType instanceof TypeVariableBinding)
actualType = actualType.erasure();
if (expectedType instanceof TypeVariableBinding)
expectedType = expectedType.erasure();
}
if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
if (location instanceof Annotation) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376977
return; // Already reported, don't report a secondary error
}
this.handle(
IProblem.UndefinedType,
new String[] {new String(actualType.leafComponentType().readableName())},
new String[] {new String(actualType.leafComponentType().shortReadableName())},
location.sourceStart,
location.sourceEnd);
return;
}
if (expectingLocation != null && (expectedType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
this.handle(
IProblem.UndefinedType,
new String[] {new String(expectedType.leafComponentType().readableName())},
new String[] {new String(expectedType.leafComponentType().shortReadableName())},
expectingLocation.sourceStart,
expectingLocation.sourceEnd);
return;
}
char[] actualShortReadableName = actualType.shortReadableName();
char[] expectedShortReadableName = expectedType.shortReadableName();
char[] actualReadableName = actualType.readableName();
char[] expectedReadableName = expectedType.readableName();
if (CharOperation.equals(actualShortReadableName, expectedShortReadableName)) {
if (CharOperation.equals(actualReadableName, expectedReadableName)) {
// if full type names are equal, assume the incompatibility is due to mismatching null annotations:
actualReadableName = actualType.nullAnnotatedReadableName(this.options, false);
expectedReadableName = expectedType.nullAnnotatedReadableName(this.options, false);
actualShortReadableName = actualType.nullAnnotatedReadableName(this.options, true);
expectedShortReadableName = expectedType.nullAnnotatedReadableName(this.options, true);
} else {
actualShortReadableName = actualReadableName;
expectedShortReadableName = expectedReadableName;
}
}
this.handle(
expectingLocation instanceof ReturnStatement ? IProblem.ReturnTypeMismatch : IProblem.TypeMismatch,
new String[] {new String(actualReadableName), new String(expectedReadableName)},
new String[] {new String(actualShortReadableName), new String(expectedShortReadableName)},
location.sourceStart,
location.sourceEnd);
}
示例5: computeConversion
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Base types need that the widening is explicitly done by the compiler using some bytecode like i2f.
* Also check unsafe type operations.
*/
public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) {
if (runtimeType == null || compileTimeType == null)
return;
if (this.implicitConversion != 0) return; // already set independantly
// it is possible for a Byte to be unboxed to a byte & then converted to an int
// but it is not possible for a byte to become Byte & then assigned to an Integer,
// or to become an int before boxed into an Integer
if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) {
if (!compileTimeType.isBaseType()) {
TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType);
this.implicitConversion = TypeIds.UNBOXING;
scope.problemReporter().autoboxing(this, compileTimeType, runtimeType);
compileTimeType = unboxedType;
}
} else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) {
TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType);
if (boxedType == runtimeType) // Object o = 12;
boxedType = compileTimeType;
this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id;
scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType));
return;
} else if (this.constant != Constant.NotAConstant && this.constant.typeID() != TypeIds.T_JavaLangString) {
this.implicitConversion = TypeIds.BOXING;
return;
}
int compileTimeTypeID, runtimeTypeID;
if ((compileTimeTypeID = compileTimeType.id) == TypeIds.NoId) { // e.g. ? extends String ==> String (103227)
compileTimeTypeID = compileTimeType.erasure().id == TypeIds.T_JavaLangString ? TypeIds.T_JavaLangString : TypeIds.T_JavaLangObject;
}
switch (runtimeTypeID = runtimeType.id) {
case T_byte :
case T_short :
case T_char :
if (compileTimeTypeID == TypeIds.T_JavaLangObject) {
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
} else {
this.implicitConversion |= (TypeIds.T_int << 4) + compileTimeTypeID;
}
break;
case T_JavaLangString :
case T_float :
case T_boolean :
case T_double :
case T_int : //implicitConversion may result in i2i which will result in NO code gen
case T_long :
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
break;
default : // regular object ref
// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {
// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);
// }
}
}
示例6: typeMismatchError
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
if (this.options.sourceLevel < ClassFileConstants.JDK1_5) { // don't expose type variable names, complain on erased types
if (actualType instanceof TypeVariableBinding)
actualType = actualType.erasure();
if (expectedType instanceof TypeVariableBinding)
expectedType = expectedType.erasure();
}
if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
if (location instanceof Annotation) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376977
return; // Already reported, don't report a secondary error
}
this.handle(
IProblem.UndefinedType,
new String[] {new String(actualType.leafComponentType().readableName())},
new String[] {new String(actualType.leafComponentType().shortReadableName())},
location.sourceStart,
location.sourceEnd);
return;
}
if (expectingLocation != null && (expectedType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
this.handle(
IProblem.UndefinedType,
new String[] {new String(expectedType.leafComponentType().readableName())},
new String[] {new String(expectedType.leafComponentType().shortReadableName())},
expectingLocation.sourceStart,
expectingLocation.sourceEnd);
return;
}
char[] actualShortReadableName = actualType.shortReadableName();
char[] expectedShortReadableName = expectedType.shortReadableName();
if (CharOperation.equals(actualShortReadableName, expectedShortReadableName)) {
actualShortReadableName = actualType.readableName();
expectedShortReadableName = expectedType.readableName();
}
this.handle(
IProblem.TypeMismatch,
new String[] {new String(actualType.readableName()), new String(expectedType.readableName())},
new String[] {new String(actualShortReadableName), new String(expectedShortReadableName)},
location.sourceStart,
location.sourceEnd);
}