本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil.erasure方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil.erasure方法的具体用法?Java TypeConversionUtil.erasure怎么用?Java TypeConversionUtil.erasure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.TypeConversionUtil
的用法示例。
在下文中一共展示了TypeConversionUtil.erasure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findExtensionMethodNavigationElement
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiElement findExtensionMethodNavigationElement( PsiClass extClass, PsiMethod plantedMethod )
{
PsiMethod[] found = extClass.findMethodsByName( plantedMethod.getName(), false );
outer:
for( PsiMethod m : found )
{
PsiParameter[] extParams = m.getParameterList().getParameters();
PsiParameter[] plantedParams = plantedMethod.getParameterList().getParameters();
if( extParams.length - 1 == plantedParams.length )
{
for( int i = 1; i < extParams.length; i++ )
{
PsiParameter extParam = extParams[i];
PsiParameter plantedParam = plantedParams[i - 1];
PsiType extErased = TypeConversionUtil.erasure( extParam.getType() );
PsiType plantedErased = TypeConversionUtil.erasure( plantedParam.getType() );
if( !extErased.toString().equals( plantedErased.toString() ) )
{
continue outer;
}
}
return m.getNavigationElement();
}
}
return null;
}
示例2: appendJvmSignature
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean appendJvmSignature(@NonNull StringBuilder buffer, @Nullable PsiType type) {
if (type == null) {
return false;
}
final PsiType psiType = TypeConversionUtil.erasure(type);
if (psiType instanceof PsiArrayType) {
buffer.append('[');
appendJvmSignature(buffer, ((PsiArrayType)psiType).getComponentType());
}
else if (psiType instanceof PsiClassType) {
PsiClass resolved = ((PsiClassType)psiType).resolve();
if (resolved == null) {
return false;
}
if (!appendJvmTypeName(buffer, resolved)) {
return false;
}
}
else if (psiType instanceof PsiPrimitiveType) {
buffer.append(JVMNameUtil.getPrimitiveSignature(psiType.getCanonicalText()));
}
else {
return false;
}
return true;
}
示例3: visitMethodCallExpression
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
if (!MethodCallUtils.isEqualsCall(expression)) {
return;
}
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, CommonClassNames.JAVA_LANG_ENUM)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length > 0) {
final PsiType comparedTypeErasure = TypeConversionUtil.erasure(qualifier.getType());
final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(arguments[0].getType());
if (comparedTypeErasure == null || comparisonTypeErasure == null ||
!TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) {
return;
}
}
registerMethodCallError(expression, expression);
}
示例4: areConvertible
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static boolean areConvertible(PsiType type1, PsiType type2) {
if (TypeConversionUtil.areTypesConvertible(type1, type2)) {
return true;
}
final PsiType comparedTypeErasure = TypeConversionUtil.erasure(type1);
final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(type2);
if (comparedTypeErasure == null || comparisonTypeErasure == null ||
TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) {
if (type1 instanceof PsiClassType && type2 instanceof PsiClassType) {
final PsiClassType classType1 = (PsiClassType)type1;
final PsiClassType classType2 = (PsiClassType)type2;
final PsiType[] parameters1 = classType1.getParameters();
final PsiType[] parameters2 = classType2.getParameters();
if (parameters1.length != parameters2.length) {
return ((PsiClassType)type1).isRaw() || ((PsiClassType)type2).isRaw();
}
for (int i = 0; i < parameters1.length; i++) {
if (!areConvertible(parameters1[i], parameters2[i])) {
return false;
}
}
}
return true;
}
return false;
}
示例5: visitNamedArgument
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitNamedArgument(GrNamedArgument argument) {
final GrArgumentLabel label = argument.getLabel();
if (label != null) {
PsiType expectedType = label.getExpectedArgumentType();
if (expectedType != null) {
expectedType = TypeConversionUtil.erasure(expectedType);
final GrExpression expr = argument.getExpression();
if (expr != null) {
final PsiType argType = expr.getType();
if (argType != null) {
final PsiClassType listType = JavaPsiFacade.getInstance(argument.getProject()).getElementFactory()
.createTypeByFQClassName(CommonClassNames.JAVA_UTIL_LIST, argument.getResolveScope());
if (listType.isAssignableFrom(argType)) return; //this is constructor arguments list
checkAssignability(expectedType, expr, argument);
}
}
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java
示例6: getResultType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getResultType(PsiMethodCallExpression call,
PsiReferenceExpression methodExpression,
JavaResolveResult result,
@NotNull final LanguageLevel languageLevel) {
final PsiMethod method = (PsiMethod)result.getElement();
if (method == null) return null;
boolean is15OrHigher = languageLevel.compareTo(LanguageLevel.JDK_1_5) >= 0;
final PsiType getClassReturnType = PsiTypesUtil.patchMethodGetClassReturnType(call, methodExpression, method,
new Condition<IElementType>() {
@Override
public boolean value(IElementType type) {
return type != JavaElementType.CLASS;
}
}, languageLevel);
if (getClassReturnType != null) {
return getClassReturnType;
}
PsiType ret = method.getReturnType();
if (ret == null) return null;
if (ret instanceof PsiClassType) {
ret = ((PsiClassType)ret).setLanguageLevel(languageLevel);
}
if (is15OrHigher) {
return captureReturnType(call, method, ret, result, languageLevel);
}
return TypeConversionUtil.erasure(ret);
}
示例7: writeTypeForNew
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static void writeTypeForNew(@NotNull StringBuilder builder, @Nullable PsiType type, @NotNull PsiElement context) {
//new Array[] cannot contain generics
if (type instanceof PsiArrayType) {
PsiType erased = TypeConversionUtil.erasure(type);
if (erased != null) {
type = erased;
}
}
writeType(builder, type, context, new GeneratorClassNameProvider());
}
示例8: substituteType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static PsiType substituteType(final PsiSubstitutor substitutor, final PsiType type, @NotNull PsiTypeParameterListOwner owner) {
if (PsiUtil.isRawSubstitutor(owner, substitutor)) {
return TypeConversionUtil.erasure(type);
}
final PsiType psiType = substitutor.substitute(type);
if (psiType != null) {
final PsiType deepComponentType = psiType.getDeepComponentType();
if (!(deepComponentType instanceof PsiCapturedWildcardType || deepComponentType instanceof PsiWildcardType)){
return psiType;
}
}
return TypeConversionUtil.erasure(type);
}
示例9: getMethodTypes
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static String getMethodTypes(PsiMethod method) {
final StringBuilder buf = new StringBuilder();
for (PsiParameter parameter : method.getParameterList().getParameters()) {
PsiType type = TypeConversionUtil.erasure(parameter.getType());
if (type instanceof PsiEllipsisType) {
type = new PsiArrayType(((PsiEllipsisType)type).getComponentType());
}
buf.append(", ").append(type.getPresentableText()).append(".class");
}
return buf.toString();
}
示例10: getRealType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getRealType(PsiMethod method) {
final PsiElement navigationElement = method.getNavigationElement();
if (navigationElement instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod)navigationElement).getParameterList().getParameters();
if (parameters.length != 0) {
return TypeConversionUtil.erasure(parameters[0].getType());
}
}
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null) return null;
return JavaPsiFacade.getElementFactory(method.getProject()).createType(containingClass);
}
示例11: createMethodProcessor
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NotNull
private MethodResolverProcessor createMethodProcessor(boolean allVariants,
@Nullable String name,
final boolean byShape,
@Nullable GrExpression upToArgument) {
final PsiType[] argTypes = PsiUtil.getArgumentTypes(this, false, upToArgument, byShape);
if (byShape && argTypes != null) {
for (int i = 0; i < argTypes.length; i++) {
argTypes[i] = TypeConversionUtil.erasure(argTypes[i]);
}
}
PsiType qualifierType = PsiImplUtil.getQualifierType(this);
return new MethodResolverProcessor(name, this, false, qualifierType, argTypes, getTypeArguments(), allVariants, byShape);
}
示例12: processLocalVariableInitializer
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiType processLocalVariableInitializer( final PsiExpression psiExpression )
{
PsiType result = null;
if( null != psiExpression && !(psiExpression instanceof PsiArrayInitializerExpression) )
{
if( psiExpression instanceof PsiConditionalExpression )
{
result = RecursionManager.doPreventingRecursion( psiExpression, true, () ->
{
final PsiExpression thenExpression = ((PsiConditionalExpression)psiExpression).getThenExpression();
final PsiExpression elseExpression = ((PsiConditionalExpression)psiExpression).getElseExpression();
final PsiType thenType = null != thenExpression ? thenExpression.getType() : null;
final PsiType elseType = null != elseExpression ? elseExpression.getType() : null;
if( thenType == null )
{
return elseType;
}
if( elseType == null )
{
return thenType;
}
if( TypeConversionUtil.isAssignable( thenType, elseType, false ) )
{
return thenType;
}
if( TypeConversionUtil.isAssignable( elseType, thenType, false ) )
{
return elseType;
}
return thenType;
} );
}
else
{
result = RecursionManager.doPreventingRecursion( psiExpression, true, psiExpression::getType );
}
if( psiExpression instanceof PsiNewExpression )
{
final PsiJavaCodeReferenceElement reference = ((PsiNewExpression)psiExpression).getClassOrAnonymousClassReference();
if( reference != null )
{
final PsiReferenceParameterList parameterList = reference.getParameterList();
if( parameterList != null )
{
final PsiTypeElement[] elements = parameterList.getTypeParameterElements();
if( elements.length == 1 && elements[0].getType() instanceof PsiDiamondType )
{
result = TypeConversionUtil.erasure( result );
}
}
}
}
}
return result;
}
示例13: captureReturnType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static PsiType captureReturnType(PsiMethodCallExpression call,
PsiMethod method,
PsiType ret,
JavaResolveResult result,
LanguageLevel languageLevel) {
PsiSubstitutor substitutor = result.getSubstitutor();
PsiType substitutedReturnType = substitutor.substitute(ret);
if (substitutedReturnType == null) {
return TypeConversionUtil.erasure(ret);
}
if (InferenceSession.wasUncheckedConversionPerformed(call)) {
// 18.5.2
// if unchecked conversion was necessary, then this substitution provides the parameter types of the invocation type,
// while the return type and thrown types are given by the erasure of m's type (without applying θ').
return TypeConversionUtil.erasure(substitutedReturnType);
}
//15.12.2.6. Method Invocation Type
// If unchecked conversion was necessary for the method to be applicable,
// the parameter types of the invocation type are the parameter types of the method's type,
// and the return type and thrown types are given by the erasures of the return type and thrown types of the method's type.
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8) &&
(method.hasTypeParameters() || JavaVersionService.getInstance().isAtLeast(call, JavaSdkVersion.JDK_1_8)) &&
result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isApplicable()) {
final PsiType[] args = call.getArgumentList().getExpressionTypes();
final boolean allowUncheckedConversion = false;
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method, substitutor, args, languageLevel, allowUncheckedConversion, true);
if (applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE) {
return TypeConversionUtil.erasure(substitutedReturnType);
}
}
if (PsiUtil.isRawSubstitutor(method, substitutor)) {
final PsiType returnTypeErasure = TypeConversionUtil.erasure(ret);
if (Comparing.equal(TypeConversionUtil.erasure(substitutedReturnType), returnTypeErasure)) {
return returnTypeErasure;
}
}
return PsiImplUtil.normalizeWildcardTypeByPosition(substitutedReturnType, call);
}
示例14: getMemberUseKey1
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NonNls @NotNull
public static String getMemberUseKey1(@Nullable PsiType qualifierType) {
qualifierType = TypeConversionUtil.erasure(qualifierType);
return "member#" + (qualifierType == null ? "" : qualifierType.getCanonicalText());
}
示例15: createTypeValue
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public DfaValue createTypeValue(@Nullable PsiType type, Nullness nullability) {
type = TypeConversionUtil.erasure(type);
if (type == null) return DfaUnknownValue.getInstance();
return getTypeFactory().createTypeValue(internType(type), nullability);
}