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


Java PsiUtil.resolveClassInType方法代码示例

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


在下文中一共展示了PsiUtil.resolveClassInType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isStructuralType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private boolean isStructuralType( PsiTypeElement typeElem )
{
  if( typeElem != null )
  {
    PsiClass psiClass = PsiUtil.resolveClassInType( typeElem.getType() );
    if( psiClass == null )
    {
      return false;
    }
    PsiAnnotation structuralAnno = psiClass.getModifierList() == null
                                   ? null
                                   : psiClass.getModifierList().findAnnotation( "manifold.ext.api.Structural" );
    if( structuralAnno != null )
    {
      return true;
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:20,代码来源:ManHighlightInfoFilter.java

示例2: addTypeParametersFolding

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void addTypeParametersFolding(List<FoldingDescriptor> foldElements, Document document, PsiReferenceParameterList list,
                                      final int ifLongerThan, boolean quick) {
  if (!quick) {
    for (final PsiType type : list.getTypeArguments()) {
      if (!type.isValid()) {
        return;
      }
      if (type instanceof PsiClassType || type instanceof PsiArrayType) {
        if (PsiUtil.resolveClassInType(type) == null) {
          return;
        }
      }
    }
  }

  final String text = list.getText();
  if (text.startsWith("<") && text.endsWith(">") && text.length() > ifLongerThan) {
    final TextRange range = list.getTextRange();
    addFoldRegion(foldElements, list, document, true, range);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaFoldingBuilderBase.java

示例3: unify

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiSubstitutor unify(@NotNull PsiSubstitutor substitutor, @NotNull PsiSubstitutor parentSubstitutor, @NotNull Project project) {
  Map<PsiTypeParameter,PsiType> newMap = new THashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap());

  for (Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) {
    PsiTypeParameter typeParameter = entry.getKey();
    PsiType type = entry.getValue();
    PsiClass resolved = PsiUtil.resolveClassInType(type);
    if (!parentSubstitutor.getSubstitutionMap().containsKey(typeParameter)) continue;
    PsiType parentType = parentSubstitutor.substitute(parentSubstitutor.substitute(typeParameter));

    if (resolved instanceof PsiTypeParameter) {
      PsiTypeParameter res = (PsiTypeParameter)resolved;
      newMap.put(res, parentType);
    }
    else if (!Comparing.equal(type, parentType)) {
      return null; // cannot unify
    }
  }
  return JavaPsiFacade.getElementFactory(project).createSubstitutor(newMap);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:SliceUtil.java

示例4: getTypeByExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static PsiType getTypeByExpression(PsiExpression expr) {
  PsiType type = expr.getType();
  if (type == null) {
    if (expr instanceof PsiArrayInitializerExpression) {
      PsiExpression[] initializers = ((PsiArrayInitializerExpression)expr).getInitializers();
      if (initializers.length > 0) {
        PsiType initType = getTypeByExpression(initializers[0]);
        if (initType == null) return null;
        return initType.createArrayType();
      }
    }

    if (expr instanceof PsiReferenceExpression && PsiUtil.isOnAssignmentLeftHand(expr)) {
      return getTypeByExpression(((PsiAssignmentExpression)expr.getParent()).getRExpression());
    }
    return null;
  }
  PsiClass refClass = PsiUtil.resolveClassInType(type);
  if (refClass instanceof PsiAnonymousClass) {
    type = ((PsiAnonymousClass)refClass).getBaseClassType();
  }

  return GenericsUtil.getVariableTypeByExpressionType(type);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:RefactoringChangeUtil.java

示例5: hasNonTrivialParameters

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
/**
 * Checks if the class type has any parameters which are not unbounded wildcards (and not extends-wildcard with the same bound as corresponding type parameter bound)
 * and do not have substituted arguments.
 *
 * @return true if the class type has nontrivial non-substituted parameters, false otherwise
 */
public boolean hasNonTrivialParameters() {
  final ClassResolveResult resolveResult = resolveGenerics();
  PsiClass aClass = resolveResult.getElement();
  if (aClass == null) return false;
  for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(aClass)) {
    PsiType type = resolveResult.getSubstitutor().substitute(parameter);
    if (type != null) {
      if (!(type instanceof PsiWildcardType)) {
        return true;
      }
      final PsiType bound = ((PsiWildcardType)type).getBound();
      if (bound != null) {
        if (((PsiWildcardType)type).isExtends()) {
          final PsiClass superClass = parameter.getSuperClass();
          if (superClass != null && PsiUtil.resolveClassInType(bound) == superClass) {
            continue;
          }
        }
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PsiClassType.java

示例6: getSymbolTypeDeclarations

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
@Nullable
public PsiElement[] getSymbolTypeDeclarations(@NotNull final PsiElement targetElement) {
  PsiType type;
  if (targetElement instanceof GrVariable){
    type = ((GrVariable)targetElement).getTypeGroovy();
  }
  else if (targetElement instanceof GrMethod){
    type = ((GrMethod)targetElement).getInferredReturnType();
  }
  else {
    return null;
  }
  if (type == null) return null;
  PsiClass psiClass = PsiUtil.resolveClassInType(type);
  return psiClass == null ? null : new PsiElement[] {psiClass};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyTypeDeclarationProvider.java

示例7: testResolveTypeReference

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public void testResolveTypeReference() throws Exception {
  setupLoadingFilter();

  PsiClass aClass = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject));

  PsiType type1 = aClass.getFields()[1].getType();
  PsiElement target1 = PsiUtil.resolveClassInType(type1);
  assertNotNull(target1);
  PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(myProject));
  assertEquals(objectClass, target1);

  PsiType type2 = aClass.getFields()[1].getType();
  PsiElement target2 = PsiUtil.resolveClassInType(type2);
  assertNotNull(target2);
  assertEquals(objectClass, target2);

  teardownLoadingFilter();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SrcRepositoryUseTest.java

示例8: validate

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void validate(@NotNull XmlTag context, @NotNull ValidationHost host) {
  final String contextName = context.getName();
  if (FxmlConstants.FX_ROOT.equals(contextName)) {
    if (context.getParentTag() != null) {
      host.addMessage(context.getNavigationElement(), "<fx:root> is valid only as the root node of an FXML document",
                      ValidationHost.ErrorType.ERROR);
    }
  } else {
    final XmlTag referencedTag = getReferencedTag(context);
    if (referencedTag != null) {
      final XmlElementDescriptor descriptor = referencedTag.getDescriptor();
      if (descriptor != null) {
        final PsiElement declaration = descriptor.getDeclaration();
        if (declaration instanceof PsiClass) {
          final PsiClass psiClass = (PsiClass)declaration;
          final String canCoerceError = JavaFxPsiUtil.isClassAcceptable(context.getParentTag(), psiClass);
          if (canCoerceError != null) {
            host.addMessage(context.getNavigationElement(), canCoerceError, ValidationHost.ErrorType.ERROR);
          }
          if (FxmlConstants.FX_COPY.equals(contextName)) {
            boolean copyConstructorFound = false;
            for (PsiMethod constructor : psiClass.getConstructors()) {
              final PsiParameter[] parameters = constructor.getParameterList().getParameters();
              if (parameters.length == 1 && psiClass == PsiUtil.resolveClassInType(parameters[0].getType())) {
                copyConstructorFound = true;
                break;
              }
            }
            if (!copyConstructorFound) {
              host.addMessage(context.getNavigationElement(), "Copy constructor not found for \'" + psiClass.getName() + "\'",
                              ValidationHost.ErrorType.ERROR);
            }
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:JavaFxDefaultPropertyElementDescriptor.java

示例9: processMembers

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where,
                           final boolean acceptMethods, final boolean searchInheritors) {
  if (where == null || isPrimitiveClass(where)) return;

  final boolean searchFactoryMethods = searchInheritors &&
                                 !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) &&
                                 !isPrimitiveClass(where);

  final Project project = myPlace.getProject();
  final GlobalSearchScope scope = myPlace.getResolveScope();

  final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
  Consumer<PsiType> consumer = new Consumer<PsiType>() {
    @Override
    public void consume(PsiType psiType) {
      PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
      if (psiClass == null) {
        return;
      }
      psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
      if (mayProcessMembers(psiClass)) {
        final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE);
        psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
        doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults());

        String name = psiClass.getName();
        if (name != null && searchFactoryMethods) {
          Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
          doProcessMembers(acceptMethods, results, false, factoryMethods);
        }
      }
    }
  };
  consumer.consume(baseType);
  if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) {
    CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:MembersGetter.java

示例10: compareExpectedTypes

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static int compareExpectedTypes(ExpectedTypeInfo o1, ExpectedTypeInfo o2, PsiExpression expression) {
  PsiClass c1 = PsiUtil.resolveClassInType(o1.getDefaultType());
  PsiClass c2 = PsiUtil.resolveClassInType(o2.getDefaultType());
  if (c1 == null && c2 == null) return 0;
  if (c1 == null || c2 == null) return c1 == null ? -1 : 1;
  return compareMembers(c1, c2, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:CreateFromUsageUtils.java

示例11: collectClassParams

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void collectClassParams(PsiType item, List<PsiClass> classes) {
  PsiClass aClass = PsiUtil.resolveClassInType(item);
  if (aClass instanceof PsiTypeParameter) {
    classes.add(aClass);
  }

  if (item instanceof PsiClassType) {
    PsiType[] parameters = ((PsiClassType)item).getParameters();
    for (PsiType parameter : parameters) {
      collectClassParams(parameter, classes);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:JavaTemplateUtil.java

示例12: testTypeReference

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public void testTypeReference() {
  PsiClass aClass = getFile("MyClass").getClasses()[0];

  PsiType type1 = aClass.getFields()[0].getType();
  assertNull(PsiUtil.resolveClassInType(type1));

  PsiType type2 = aClass.getFields()[1].getType();
  PsiType componentType = ((PsiArrayType)type2).getComponentType();
  assertTrue(componentType instanceof PsiClassType);
  assertTrue(componentType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT));
  assertEquals(CommonClassNames.JAVA_LANG_OBJECT_SHORT, componentType.getPresentableText());

  PsiElement target = PsiUtil.resolveClassInType(type2);
  assertEquals(myObjectClass, target);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ClsPsiTest.java

示例13: createOccurrenceClassProvider

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private ExpectedTypesProvider.ExpectedClassProvider createOccurrenceClassProvider() {
  final Set<PsiClass> occurrenceClasses = new HashSet<PsiClass>();
  for (final PsiExpression occurrence : myOccurrences) {
    final PsiType occurrenceType = occurrence.getType();
    final PsiClass aClass = PsiUtil.resolveClassInType(occurrenceType);
    if (aClass != null) {
      occurrenceClasses.add(aClass);
    }
  }
  return new ExpectedTypeUtil.ExpectedClassesFromSetProvider(occurrenceClasses);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:TypeSelectorManagerImpl.java

示例14: addCompletions

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void addCompletions(@NotNull final CompletionParameters parameters,
                           final ProcessingContext context,
                           @NotNull final CompletionResultSet result) {
  final PsiElement element = parameters.getPosition();

  for (final PsiType type : ExpectedTypesGetter.getExpectedTypes(element, false)) {
    final PsiClass psiClass = PsiUtil.resolveClassInType(type);
    if (psiClass != null && psiClass.isAnnotationType()) {
      result.addElement(AllClassesGetter.createLookupItem(psiClass, AnnotationInsertHandler.INSTANCE));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ExpectedAnnotationsProvider.java

示例15: addClassLiteralLookupElement

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void addClassLiteralLookupElement(@Nullable final PsiType type, final Consumer<LookupElement> resultSet, final PsiFile context) {
  if (type instanceof PsiClassType &&
      PsiUtil.resolveClassInType(type) != null &&
      !((PsiClassType)type).hasParameters() &&
      !(((PsiClassType)type).resolve() instanceof PsiTypeParameter)) {
    try {
      resultSet.consume(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(new ClassLiteralLookupElement((PsiClassType)type, context)));
    }
    catch (IncorrectOperationException ignored) {
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ClassLiteralGetter.java


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