当前位置: 首页>>代码示例>>Java>>正文


Java TypeConversionUtil类代码示例

本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil类的具体用法?Java TypeConversionUtil怎么用?Java TypeConversionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeConversionUtil类属于com.intellij.psi.util包,在下文中一共展示了TypeConversionUtil类的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;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:27,代码来源:ManAugmentProvider.java

示例2: isAssignable

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
private static boolean isAssignable( boolean structural, boolean covariant, PsiType to, PsiType from )
{
  if( to.equals( from ) )
  {
    return true;
  }

  if( structural )
  {
    return TypeConversionUtil.isAssignable( to, from ) ||
           arePrimitiveTypesAssignable( to, from ) ||
           isStructurallyAssignable( to, from, structural ) ||
           TypeConversionUtil.boxingConversionApplicable( to, from );
  }

  if( covariant )
  {
    TypeConversionUtil.isAssignable( to, from );
  }

  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:23,代码来源:TypeUtil.java

示例3: getCollectionComponentType

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@Nullable
private static PsiType getCollectionComponentType(PsiType type, Project project) {
  if (!(type instanceof PsiClassType)) return null;
  PsiClassType classType = (PsiClassType) type;
  PsiClassType.ClassResolveResult result = classType.resolveGenerics();
  PsiClass clazz = result.getElement();
  if (clazz == null) return null;
  JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  @SuppressWarnings({"ConstantConditions"}) PsiClass collectionClass = facade.findClass("java.util.Collection", type.getResolveScope());
  if (collectionClass == null || collectionClass.getTypeParameters().length != 1) return null;
  PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(collectionClass, clazz, result.getSubstitutor());

  if (substitutor == null) return null;
  PsiType componentType = substitutor.substitute(collectionClass.getTypeParameters()[0]);
  return componentType instanceof PsiIntersectionType ? null : componentType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GroovyNameSuggestionUtil.java

示例4: wrapWithNewExpression

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
public static TypeConversionDescriptor wrapWithNewExpression(PsiType to, PsiType from, @Nullable PsiExpression expression, PsiElement context) {
  final String typeText = PsiDiamondTypeUtil.getCollapsedType(to, context);
  final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(to);
  final PsiClass atomicClass = resolveResult.getElement();
  LOG.assertTrue(atomicClass != null);
  final PsiTypeParameter[] typeParameters = atomicClass.getTypeParameters();
  if (typeParameters.length == 1) {
    final PsiType initial = resolveResult.getSubstitutor().substitute(typeParameters[0]);
    final PsiPrimitiveType unboxedInitialType = PsiPrimitiveType.getUnboxedType(initial);
    if (unboxedInitialType != null) {
      LOG.assertTrue(initial != null);
      if (from instanceof PsiPrimitiveType) {
        final PsiClassType boxedFromType = ((PsiPrimitiveType)from).getBoxedType(atomicClass);
        LOG.assertTrue(boxedFromType != null);
        if (!TypeConversionUtil.isAssignable(initial, boxedFromType)) {
          return new TypeConversionDescriptor("$val$", "new " + typeText + "((" + unboxedInitialType.getCanonicalText() + ")$val$)", expression);
        }
      }
    }
  }
  return new TypeConversionDescriptor("$val$", "new " + typeText + "($val$)", expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AtomicConversionRule.java

示例5: getHandlerSignature

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
private static String getHandlerSignature(JavaFxEventHandlerReference ref) {
  final XmlAttributeValue element = ref.getElement();
  String canonicalText = JavaFxCommonClassNames.JAVAFX_EVENT;
  final PsiElement parent = element.getParent();
  if (parent instanceof XmlAttribute) {
    final XmlAttribute xmlAttribute = (XmlAttribute)parent;
    final Project project = element.getProject();
    final PsiField handlerField = ref.myCurrentTagClass.findFieldByName(xmlAttribute.getName(), true);
    if (handlerField != null) {
      final PsiClassType classType = JavaFxPsiUtil.getPropertyClassType(handlerField);
      if (classType != null) {
        final PsiClass eventHandlerClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_EVENT_EVENT_HANDLER, GlobalSearchScope.allScope(project));
        final PsiTypeParameter[] typeParameters = eventHandlerClass != null ? eventHandlerClass.getTypeParameters() : null;
        if (typeParameters != null && typeParameters.length == 1) {
          final PsiTypeParameter typeParameter = typeParameters[0];
          final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(eventHandlerClass, classType);
          final PsiType eventType = substitutor.substitute(typeParameter);
          if (eventType != null) {
            canonicalText = eventType.getCanonicalText();
          }
        }
      }
    }
  }
  return "public void " + element.getValue().substring(1) + "(" + canonicalText + " e)";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaFxEventHandlerReference.java

示例6: findConversion

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@NonNls
@Nullable
public TypeConversionDescriptorBase findConversion(final PsiType from, final PsiType to, final PsiMember member, final PsiExpression context,
                                                   final boolean isCovariantPosition, final TypeMigrationLabeler labeler) {
  final TypeConversionDescriptorBase conversion = findConversion(from, to, member, context, labeler);
  if (conversion != null) return conversion;

  if (isCovariantPosition) {
    if (to instanceof PsiEllipsisType) {
      if (TypeConversionUtil.isAssignable(((PsiEllipsisType)to).getComponentType(), from)) return new TypeConversionDescriptorBase();
    }
    if (TypeConversionUtil.isAssignable(to, from)) return new TypeConversionDescriptorBase();
  }

  return !isCovariantPosition && TypeConversionUtil.isAssignable(from, to) ? new TypeConversionDescriptorBase() : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:TypeMigrationRules.java

示例7: getTypeClass

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@Override
@Nullable
public ResolvedClass getTypeClass() {
  if (!TypeConversionUtil.isPrimitiveAndNotNull(myType)) {
    GlobalSearchScope resolveScope = myType.getResolveScope();
    if (resolveScope != null && resolveScope.getProject() != null) {
      ApplicationManager.getApplication().assertReadAccessAllowed();
      PsiClass aClass = JavaPsiFacade.getInstance(resolveScope.getProject()).findClass(getSignature(), resolveScope);
      if (aClass != null) {
        return new ResolvedPsiClass(aClass);
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:LombokPsiParser.java

示例8: inferGenericArgType

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@Nullable
private static PsiType inferGenericArgType(@NotNull GrClosureSignature signature,
                                           @NotNull PsiType targetType,
                                           int genericIndex,
                                           int param) {
  if (targetType instanceof PsiClassType) {
    final PsiClassType.ClassResolveResult result = ((PsiClassType)targetType).resolveGenerics();
    final PsiClass psiClass = result.getElement();
    if (psiClass != null) {
      final PsiSubstitutor substitutor = result.getSubstitutor();

      final PsiType baseType = signature.getParameters()[param].getType();
      final PsiClass baseClass = PsiUtil.resolveClassInClassTypeOnly(baseType);

      if (baseClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, baseClass, true)) {
        final PsiTypeParameter[] typeParameters = baseClass.getTypeParameters();
        if (genericIndex < typeParameters.length) {
          final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(baseClass, psiClass, substitutor);
          return superClassSubstitutor.substitute(typeParameters[genericIndex]);
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GrDelegatesToUtil.java

示例9: findVariablesOfType

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
  VariablesProcessor proc = new VariablesProcessor(false) {
    @Override
    protected boolean check(PsiVariable var, ResolveState state) {
      for (PsiElement element : declaration.getDeclaredElements()) {
        if (element == var) return false;
      }
      return TypeConversionUtil.isAssignable(var.getType(), type);
    }
  };
  PsiElement scope = declaration;
  while (scope != null) {
    if (scope instanceof PsiFile || 
        scope instanceof PsiMethod || 
        scope instanceof PsiLambdaExpression ||
        scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return proc;
  PsiScopesUtil.treeWalkUp(proc, declaration, scope);
  return proc;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ReassignVariableUtil.java

示例10: appendJVMSignature

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@SuppressWarnings({"HardCodedStringLiteral"})
private static void appendJVMSignature(JVMNameBuffer buffer , PsiType type){
  if (type == null) {
    return;
  }
  final PsiType psiType = TypeConversionUtil.erasure(type);
  if (psiType instanceof PsiArrayType) {
    buffer.append(new JVMRawText("["));
    appendJVMSignature(buffer, ((PsiArrayType) psiType).getComponentType());
  }
  else if (psiType instanceof PsiClassType) {
    final JVMName jvmName = getJVMQualifiedName(psiType);
    appendJvmClassQualifiedName(buffer, jvmName);
  }
  else if (psiType instanceof PsiPrimitiveType) {
    buffer.append(getPrimitiveSignature(psiType.getCanonicalText()));
  }
  else {
    LOG.error("unknown type " + type.getCanonicalText());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JVMNameUtil.java

示例11: applyUnboxedRelation

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
private boolean applyUnboxedRelation(DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
  PsiType type = dfaLeft.getVariableType();
  if (!TypeConversionUtil.isPrimitiveWrapper(type)) {
    return true;
  }
  if (negated) {
    // from the fact "wrappers are not the same" it does not follow that "unboxed values are not equal"
    return true;
  }

  DfaBoxedValue.Factory boxedFactory = myFactory.getBoxedFactory();
  DfaValue unboxedLeft = boxedFactory.createUnboxed(dfaLeft);
  DfaValue unboxedRight = boxedFactory.createUnboxed(dfaRight);
  return applyRelation(unboxedLeft, unboxedRight, false) &&
         checkCompareWithBooleanLiteral(unboxedLeft, unboxedRight, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DfaMemoryStateImpl.java

示例12: createFromValue

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@NotNull
public DfaConstValue createFromValue(Object value, final PsiType type, @Nullable PsiVariable constant) {
  if (value == Boolean.TRUE) return dfaTrue;
  if (value == Boolean.FALSE) return dfaFalse;

  if (TypeConversionUtil.isNumericType(type) && !TypeConversionUtil.isFloatOrDoubleType(type)) {
    value = TypeConversionUtil.computeCastTo(value, PsiType.LONG);
  }
  if (value instanceof Double || value instanceof Float) {
    double doubleValue = ((Number)value).doubleValue();
    if (doubleValue == -0.0) doubleValue = +0.0;
    value = new Double(doubleValue);
  }
  DfaConstValue instance = myValues.get(value);
  if (instance == null) {
    instance = new DfaConstValue(value, myFactory, constant);
    myValues.put(value, instance);
  }

  return instance;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DfaConstValue.java

示例13: register

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
public static void register(HighlightInfo highlightInfo, PsiExpression expression, @NotNull PsiType lType) {
  if (lType != PsiType.NULL && expression instanceof PsiConditionalExpression) {
    final PsiExpression thenExpression = ((PsiConditionalExpression)expression).getThenExpression();
    final PsiExpression elseExpression = ((PsiConditionalExpression)expression).getElseExpression();
    if (thenExpression != null && elseExpression != null) {
      final PsiType thenType = thenExpression.getType();
      final PsiType elseType = elseExpression.getType();
      if (thenType != null && elseType != null) {
        final boolean thenAssignable = TypeConversionUtil.isAssignable(lType, thenType);
        final boolean elseAssignable = TypeConversionUtil.isAssignable(lType, elseType);
        if (!thenAssignable && thenExpression instanceof PsiMethodCallExpression) {
          inferTypeArgs(highlightInfo, lType, thenExpression);
        }
        if (!elseAssignable && elseExpression instanceof PsiMethodCallExpression) {
          inferTypeArgs(highlightInfo, lType, elseExpression);
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AddTypeArgumentsConditionalFix.java

示例14: isMemberEnabled

import com.intellij.psi.util.TypeConversionUtil; //导入依赖的package包/类
@Override
public boolean isMemberEnabled(GrMemberInfo member) {
  PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  if (!currentSuperClass.isInterface()) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    if (currentSuperClass.isInterface()) {
      final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
      final MethodSignature signature = ((PsiMethod)element).getSignature(superSubstitutor);
      final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
      if (superClassMethod != null) return false;
    }
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GrPullUpDialog.java

示例15: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:IntellijLintUtils.java


注:本文中的com.intellij.psi.util.TypeConversionUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。