本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.isEqualTo方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.isEqualTo方法的具體用法?Java ITypeBinding.isEqualTo怎麽用?Java ITypeBinding.isEqualTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.isEqualTo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getExplicitCast
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Returns the type to which an inlined variable initializer should be cast, or
* <code>null</code> if no cast is necessary.
*
* @param initializer the initializer expression of the variable to inline
* @param reference the reference to the variable (which is to be inlined)
* @return a type binding to which the initializer should be cast, or <code>null</code> iff no cast is necessary
* @since 3.6
*/
public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) {
ITypeBinding initializerType= initializer.resolveTypeBinding();
ITypeBinding referenceType= reference.resolveTypeBinding();
if (initializerType == null || referenceType == null) {
return null;
}
if (initializerType.isPrimitive() && referenceType.isPrimitive() && ! referenceType.isEqualTo(initializerType)) {
return referenceType;
} else if (initializerType.isPrimitive() && ! referenceType.isPrimitive()) { // initializer is autoboxed
ITypeBinding unboxedReferenceType= Bindings.getUnboxedTypeBinding(referenceType, reference.getAST());
if (!unboxedReferenceType.isEqualTo(initializerType)) {
return unboxedReferenceType;
} else if (needsExplicitBoxing(reference)) {
return referenceType;
}
} else if (! initializerType.isPrimitive() && referenceType.isPrimitive()) { // initializer is autounboxed
ITypeBinding unboxedInitializerType= Bindings.getUnboxedTypeBinding(initializerType, reference.getAST());
if (!unboxedInitializerType.isEqualTo(referenceType)) {
return referenceType;
}
} else if (initializerType.isRawType() && referenceType.isParameterizedType()) {
return referenceType; // don't lose the unchecked conversion
} else if (initializer instanceof LambdaExpression || initializer instanceof MethodReference) {
if (isTargetAmbiguous(reference, isExplicitlyTypedLambda(initializer))) {
return referenceType;
} else {
ITypeBinding targetType= getTargetType(reference);
if (targetType == null || targetType != referenceType) {
return referenceType;
}
}
} else if (! TypeRules.canAssign(initializerType, referenceType)) {
if (!Bindings.containsTypeVariables(referenceType)) {
return referenceType;
}
}
return null;
}
示例2: createNarrowCastIfNessecary
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Checks if the assignment needs a downcast and inserts it if necessary
*
* @param expression
* the right hand-side
* @param expressionType
* the type of the right hand-side. Can be null
* @param ast
* the AST
* @param variableType
* the Type of the variable the expression will be assigned to
* @param is50OrHigher
* if <code>true</code> java 5.0 code will be assumed
* @return the casted expression if necessary
*/
private static Expression createNarrowCastIfNessecary(Expression expression, ITypeBinding expressionType, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
PrimitiveType castTo = null;
if (variableType.isEqualTo(expressionType))
{
return expression; //no cast for same type
}
if (is50OrHigher) {
if (ast.resolveWellKnownType("java.lang.Character").isEqualTo(variableType)) {
castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
}
if (ast.resolveWellKnownType("java.lang.Byte").isEqualTo(variableType)) {
castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
}
if (ast.resolveWellKnownType("java.lang.Short").isEqualTo(variableType)) {
castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
}
}
if (ast.resolveWellKnownType("char").isEqualTo(variableType)) {
castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
}
if (ast.resolveWellKnownType("byte").isEqualTo(variableType)) {
castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
}
if (ast.resolveWellKnownType("short").isEqualTo(variableType)) {
castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
}
if (castTo != null) {
CastExpression cast = ast.newCastExpression();
if (NecessaryParenthesesChecker.needsParentheses(expression, cast, CastExpression.EXPRESSION_PROPERTY)) {
ParenthesizedExpression parenthesized = ast.newParenthesizedExpression();
parenthesized.setExpression(expression);
cast.setExpression(parenthesized);
} else {
cast.setExpression(expression);
}
cast.setType(castTo);
return cast;
}
return expression;
}
示例3: getMethodBinding
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static IMethodBinding getMethodBinding(ITypeBinding superclass, String methodName, ITypeBinding[] paramTypes, ITypeBinding returnType) {
IMethodBinding overriddenMethod = null;
boolean include = false;
IMethodBinding[] declaredMethods = superclass.getDeclaredMethods();
for (int ii = 0; ii < declaredMethods.length; ii++) {
IMethodBinding declaredMethod = declaredMethods[ii];
if (declaredMethod.getName().compareTo(methodName) != 0) {
continue;
}
// Overridden method must be public or protected
if (Modifier.isPrivate(declaredMethod.getModifiers())) {
continue;
}
// Overridden method cannot be static
if (Modifier.isStatic(declaredMethod.getModifiers())) {
continue;
}
if (!isEqual(declaredMethod.getReturnType(), returnType)) {
continue;
}
// Include if method return is non-primitive
include |= (returnType != null && !returnType.isPrimitive());
ITypeBinding[] parameterTypes = declaredMethod.getParameterTypes();
if (parameterTypes.length != paramTypes.length) {
continue;
}
boolean equal = true;
for (int jj = 0; jj < parameterTypes.length; jj++) {
ITypeBinding parameterType = parameterTypes[jj];
equal &= parameterType.isEqualTo(paramTypes[jj]);
if (!equal) {
break;
}
// Include if at least one param is non-primitive
include |= (parameterType != null && !parameterType.isPrimitive());
}
if (equal) {
overriddenMethod = declaredMethod;
break;
}
}
// Not an interesting method
if(!include) {
overriddenMethod = null;
}
return overriddenMethod;
}
示例4: translateFtoA
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Translate a typeBinding with a formal type parameter into one with fully substituted type
* based on the enclosing type
* @param typeBinding: e.g., virtual field of type <E extends java.lang.Object>
* @param actualBinding: the enclosing type, e.g., class ArrayList<courses.Course>
* where the generic type declaration is class ArrayList<E> {...}
* @return typeBinding with the type substitution performed, e.g., courses.Course
*/
public static ITypeBinding translateFtoA(ITypeBinding typeBinding, ITypeBinding actualBinding) {
ITypeBinding toTypeBindingActual = typeBinding;
// HACK: Introduced bugs!
// Check that it is a generic type, to avoid generating a type that does not exist!
// if(!typeBinding.isGenericType()) {
// return typeBinding;
// }
// HACK: Introduced bugs!
if (typeBinding.isEqualTo(actualBinding)) {
return typeBinding;
}
// Instantiate generic types...
if (actualBinding.isParameterizedType()) {
ITypeBinding[] typeParameters = actualBinding.getErasure().getTypeParameters();
int pIndex = -1;
int index = 0;
for(ITypeBinding typeParameter : typeParameters ) {
if ( typeParameter.isEqualTo(typeBinding) ) {
pIndex = index;
break;
}
index++;
}
ITypeBinding[] typeArguments = actualBinding.getTypeArguments();
if ( typeBinding.isTypeVariable() && typeArguments != null && pIndex != -1 && pIndex < typeArguments.length) {
toTypeBindingActual = typeArguments[pIndex];
}
else {
String[] typeArgumentString = getParameters(typeArguments);
String bindingKey = BindingKey.createParameterizedTypeBindingKey(typeBinding.getKey(), typeArgumentString);
toTypeBindingActual = GenHelper.mapBindingKeyToTypeBinding(bindingKey);
}
}
return toTypeBindingActual;
}