本文整理汇总了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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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};
}
示例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();
}
示例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);
}
}
}
}
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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));
}
}
}
示例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) {
}
}
}