Java Code Examples for com.intellij.psi.PsiClassType#resolve()
The following examples show how to use
com.intellij.psi.PsiClassType#resolve() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeGenerator.java From ParcelablePlease with Apache License 2.0 | 6 votes |
/** * Make the class implementing Parcelable */ private void makeClassImplementParcelable(PsiElementFactory elementFactory, JavaCodeStyleManager styleManager) { final PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); final String implementsType = "android.os.Parcelable"; for (PsiClassType implementsListType : implementsListTypes) { PsiClass resolved = implementsListType.resolve(); // Already implements Parcelable, no need to add it if (resolved != null && implementsType.equals(resolved.getQualifiedName())) { return; } } PsiJavaCodeReferenceElement implementsReference = elementFactory.createReferenceFromText(implementsType, psiClass); PsiReferenceList implementsList = psiClass.getImplementsList(); if (implementsList != null) { styleManager.shortenClassReferences(implementsList.add(implementsReference)); } }
Example 2
Source File: CleanupProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void validateCleanUpMethodExists(@NotNull PsiLocalVariable psiVariable, @NotNull String cleanupName, @NotNull ProblemNewBuilder problemNewBuilder) { final PsiType psiType = psiVariable.getType(); if (psiType instanceof PsiClassType) { final PsiClassType psiClassType = (PsiClassType) psiType; final PsiClass psiClassOfField = psiClassType.resolve(); final PsiMethod[] methods; if (psiClassOfField != null) { methods = psiClassOfField.findMethodsByName(cleanupName, true); boolean hasCleanupMethod = false; for (PsiMethod method : methods) { if (0 == method.getParameterList().getParametersCount()) { hasCleanupMethod = true; } } if (!hasCleanupMethod) { problemNewBuilder.addError("'@Cleanup': method '%s()' not found on target class", cleanupName); } } } else { problemNewBuilder.addError("'@Cleanup': is legal only on a local variable declaration inside a block"); } }
Example 3
Source File: PsiCustomUtil.java From intellij-spring-assistant with MIT License | 5 votes |
@Nullable public static PsiClass toValidPsiClass(@NotNull PsiClassType type) { if (isValidType(type)) { return type.resolve(); } return null; }
Example 4
Source File: PsiUtils.java From data-mediator with Apache License 2.0 | 5 votes |
static List<PsiClass> getExtendsClasses(PsiClass psiClass, int lowDepth, int currentDepth){ List<PsiClass> list = new ArrayList<>(); for(PsiClassType type : psiClass.getExtendsListTypes()) { PsiClass superPsiClass = type.resolve(); if(superPsiClass != null){ if(currentDepth + 1 >= lowDepth) { list.add(superPsiClass); } list.addAll(getExtendsClasses(superPsiClass, lowDepth, currentDepth + 1)); } } return list; }
Example 5
Source File: PsiUtils.java From data-mediator with Apache License 2.0 | 5 votes |
static boolean hasSelectable(PsiClass psiClass){ PsiClassType[] listTypes = psiClass.getExtendsListTypes(); for(PsiClassType type : listTypes){ PsiClass superPsiClass = type.resolve(); if (superPsiClass != null && NAME_SELECTABLE.equals(superPsiClass.getQualifiedName())) { return true; } } return false; }
Example 6
Source File: PsiUtils.java From data-mediator with Apache License 2.0 | 5 votes |
public static String getNonGenericType(PsiType type) { if (type instanceof PsiClassType) { PsiClassType pct = (PsiClassType) type; final PsiClass psiClass = pct.resolve(); return psiClass != null ? psiClass.getQualifiedName() : null; } return type.getCanonicalText(); }
Example 7
Source File: JavaPsiUtil.java From idea-android-studio-plugin with GNU General Public License v2.0 | 5 votes |
public static boolean isInstanceOf(PsiClass instance, PsiClass interfaceExtendsClass) { String className = interfaceExtendsClass.getQualifiedName(); if(className == null) { return true; } if(className.equals(instance.getQualifiedName())) { return true; } for(PsiClassType psiClassType: PsiClassImplUtil.getExtendsListTypes(instance)) { PsiClass resolve = psiClassType.resolve(); if(resolve != null) { if(className.equals(resolve.getQualifiedName())) { return true; } } } for(PsiClass psiInterface: PsiClassImplUtil.getInterfaces(instance)) { if(className.equals(psiInterface.getQualifiedName())) { return true; } } return false; }
Example 8
Source File: DebugLintIssue.java From Debug with Apache License 2.0 | 5 votes |
private static boolean isSubclassOf( @NonNull JavaContext context, @NonNull UExpression expression, @NonNull Class<?> cls) { final PsiType expressionType = expression.getExpressionType(); if (!(expressionType instanceof PsiClassType)) { return false; } final PsiClassType classType = (PsiClassType) expressionType; final PsiClass resolvedClass = classType.resolve(); return context.getEvaluator().extendsClass(resolvedClass, cls.getName(), false); }
Example 9
Source File: PsiConsultantImpl.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
/** * Return the appropriate return class for a given method element. * * @param psiMethod the method to get the return class from. * @param expandType set this to true if return types annotated with @Provides(type=?) * should be expanded to the appropriate collection type. * @return the appropriate return class for the provided method element. */ public static PsiClass getReturnClassFromMethod(PsiMethod psiMethod, boolean expandType) { if (psiMethod.isConstructor()) { return psiMethod.getContainingClass(); } PsiClassType returnType = ((PsiClassType) psiMethod.getReturnType()); if (returnType != null) { // Check if has @Provides annotation and specified type if (expandType) { PsiAnnotationMemberValue attribValue = findTypeAttributeOfProvidesAnnotation(psiMethod); if (attribValue != null) { if (attribValue.textMatches(SET_TYPE)) { String typeName = "java.util.Set<" + returnType.getCanonicalText() + ">"; returnType = ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject()) .createTypeFromText(typeName, psiMethod)); } else if (attribValue.textMatches(MAP_TYPE)) { // TODO(radford): Supporting map will require fetching the key type and also validating // the qualifier for the provided key. // // String typeName = "java.util.Map<String, " + returnType.getCanonicalText() + ">"; // returnType = ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject()) // .createTypeFromText(typeName, psiMethod)); } } } return returnType.resolve(); } return null; }
Example 10
Source File: PsiUtils.java From android-parcelable-intellij-plugin with Apache License 2.0 | 5 votes |
public static String getNonGenericType(PsiType type) { if (type instanceof PsiClassType) { PsiClassType pct = (PsiClassType) type; final PsiClass psiClass = pct.resolve(); return psiClass != null ? psiClass.getQualifiedName() : null; } return type.getCanonicalText(); }