本文整理汇总了Java中com.intellij.psi.impl.source.resolve.JavaResolveUtil类的典型用法代码示例。如果您正苦于以下问题:Java JavaResolveUtil类的具体用法?Java JavaResolveUtil怎么用?Java JavaResolveUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaResolveUtil类属于com.intellij.psi.impl.source.resolve包,在下文中一共展示了JavaResolveUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, boolean staticProblem) {
final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(),
myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
!isShadowed(method);
if (isAccepted(method) && !(isInterfaceStaticMethodAccessibleThroughInheritance(method) && ImportsUtil.hasStaticImportOn(myPlace, method, true))) {
if (!staticProblem && myAccessClass != null && method.hasModifierProperty(PsiModifier.STATIC)) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null &&
containingClass.isInterface() &&
!(myAccessClass instanceof PsiTypeParameter) &&
!containingClass.equals(myAccessClass)) {
staticProblem = true;
}
}
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, false));
if (acceptVarargs() && method.isVarArgs() && PsiUtil.isLanguageLevel8OrHigher(myPlace)) {
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, true));
}
myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
}
}
示例2: resolve
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode) {
PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl)ref;
int kind = referenceElement.getKind(containingFile);
JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);
if (incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND) {
VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, true);
result = processor.getResult();
if (result.length == 0 && kind == CLASS_NAME_KIND) {
result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
}
}
JavaResolveUtil.substituteResults(referenceElement, result);
return result;
}
示例3: getScope
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@Nullable
private PsiClass getScope(){
if (getFirstChildNode().getElementType() == JavaDocElementType.DOC_REFERENCE_HOLDER) {
final PsiElement firstChildPsi = SourceTreeToPsiMap.treeElementToPsi(getFirstChildNode().getFirstChildNode());
if (firstChildPsi instanceof PsiJavaCodeReferenceElement) {
PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)firstChildPsi;
final PsiElement referencedElement = referenceElement.resolve();
if (referencedElement instanceof PsiClass) return (PsiClass)referencedElement;
return null;
}
else if (firstChildPsi instanceof PsiKeyword) {
final PsiKeyword keyword = (PsiKeyword)firstChildPsi;
if (keyword.getTokenType().equals(THIS_KEYWORD)) {
return JavaResolveUtil.getContextClass(this);
} else if (keyword.getTokenType().equals(SUPER_KEYWORD)) {
final PsiClass contextClass = JavaResolveUtil.getContextClass(this);
if (contextClass != null) return contextClass.getSuperClass();
return null;
}
}
}
return JavaResolveUtil.getContextClass(this);
}
示例4: processDeclarations
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
final NameHint nameHint = processor.getHint(NameHint.KEY);
final String name = nameHint != null ? nameHint.getName(state) : null;
//"pseudo-imports"
if (name != null) {
PsiClass imported = myPseudoImports.get(name);
if (imported != null) {
if (!processor.execute(imported, state)) return false;
}
} else {
for (PsiClass aClass : myPseudoImports.values()) {
if (!processor.execute(aClass, state)) return false;
}
}
if (myContext == null) {
if (!JavaResolveUtil.processImplicitlyImportedPackages(processor, state, place, getManager())) return false;
}
}
return true;
}
示例5: validate
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
private static void validate(@NotNull PsiElement reference, @Nullable PsiMember member, ProblemsHolder h) {
if (member == null || !isAnnotatedAsTestOnly(member)) return;
if (isInsideTestOnlyMethod(reference)) return;
if (isInsideTestClass(reference)) return;
if (isUnderTestSources(reference)) return;
PsiAnnotation anno = findVisibleForTestingAnnotation(member);
if (anno != null) {
String modifier = getAccessModifierWithoutTesting(anno);
if (modifier == null) {
modifier = member.hasModifierProperty(PsiModifier.PUBLIC) ? PsiModifier.PROTECTED :
member.hasModifierProperty(PsiModifier.PROTECTED) ? PsiModifier.PACKAGE_LOCAL :
PsiModifier.PRIVATE;
}
LightModifierList modList = new LightModifierList(member.getManager(), JavaLanguage.INSTANCE, modifier);
if (JavaResolveUtil.isAccessible(member, member.getContainingClass(), modList, reference, null, null)) {
return;
}
}
reportProblem(reference, member, h);
}
示例6: resolve
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@NotNull
@Override
public JavaResolveResult[] resolve(@NotNull PsiJavaReference ref, boolean incompleteCode) {
PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl)ref;
int kind = referenceElement.getKind();
PsiFile containingFile = referenceElement.getContainingFile();
JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);
if (incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND) {
VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, incompleteCode);
result = processor.getResult();
if (result.length == 0 && kind == CLASS_NAME_KIND) {
result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
}
}
JavaResolveUtil.substituteResults((PsiJavaCodeReferenceElement)ref, result);
return result;
}
示例7: getScope
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@Nullable
private PsiClass getScope(){
if (getFirstChildNode().getElementType() == ElementType.DOC_REFERENCE_HOLDER) {
final PsiElement firstChildPsi = SourceTreeToPsiMap.treeElementToPsi(getFirstChildNode().getFirstChildNode());
if (firstChildPsi instanceof PsiJavaCodeReferenceElement) {
PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)firstChildPsi;
final PsiElement referencedElement = referenceElement.resolve();
if (referencedElement instanceof PsiClass) return (PsiClass)referencedElement;
return null;
}
else if (firstChildPsi instanceof PsiKeyword) {
final PsiKeyword keyword = (PsiKeyword)firstChildPsi;
if (keyword.getTokenType().equals(THIS_KEYWORD)) {
return JavaResolveUtil.getContextClass(this);
} else if (keyword.getTokenType().equals(SUPER_KEYWORD)) {
final PsiClass contextClass = JavaResolveUtil.getContextClass(this);
if (contextClass != null) return contextClass.getSuperClass();
return null;
}
}
}
return JavaResolveUtil.getContextClass(this);
}
示例8: validate
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
private static void validate(PsiCallExpression e, ProblemsHolder h) {
PsiMethod method = e.resolveMethod();
if (method == null || !isAnnotatedAsTestOnly(method)) return;
if (isInsideTestOnlyMethod(e)) return;
if (isInsideTestClass(e)) return;
if (isUnderTestSources(e)) return;
PsiAnnotation anno = findVisibleForTestingAnnotation(method);
if (anno != null) {
LightModifierList modList = new LightModifierList(method.getManager(), JavaLanguage.INSTANCE, getAccessModifierWithoutTesting(anno));
if (JavaResolveUtil.isAccessible(method, method.getContainingClass(), modList, e, null, null)) {
return;
}
}
reportProblem(e, h);
}
示例9: addMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, boolean staticProblem)
{
final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(), myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
!isShadowed(method);
if(isAccepted(method) && !(isInterfaceStaticMethodAccessibleThroughInheritance(method) && ImportsUtil.hasStaticImportOn(myPlace, method, true)))
{
if(!staticProblem && myAccessClass != null && method.hasModifierProperty(PsiModifier.STATIC))
{
final PsiClass containingClass = method.getContainingClass();
if(containingClass != null &&
containingClass.isInterface() &&
!(myAccessClass instanceof PsiTypeParameter) &&
!containingClass.equals(myAccessClass))
{
staticProblem = true;
}
}
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, false));
if(acceptVarargs() && method.isVarArgs() && PsiUtil.isLanguageLevel8OrHigher(myPlace))
{
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, true));
}
myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
}
}
示例10: resolve
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode)
{
PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl) ref;
int kind = referenceElement.getKind(containingFile);
JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);
if(incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND)
{
VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, true);
result = processor.getResult();
if(result.length == 0 && kind == CLASS_NAME_KIND)
{
result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
}
}
JavaResolveUtil.substituteResults(referenceElement, result);
return result;
}
示例11: resolve
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode)
{
PsiReferenceExpressionImpl expression = (PsiReferenceExpressionImpl) ref;
CompositeElement treeParent = expression.getTreeParent();
IElementType parentType = treeParent == null ? null : treeParent.getElementType();
List<ResolveResult[]> qualifiers = resolveAllQualifiers(expression, containingFile);
JavaResolveResult[] result = expression.resolve(parentType, containingFile);
if(result.length == 0 && incompleteCode && parentType != JavaElementType.REFERENCE_EXPRESSION)
{
result = expression.resolve(JavaElementType.REFERENCE_EXPRESSION, containingFile);
}
JavaResolveUtil.substituteResults(expression, result);
qualifiers.clear(); // hold qualifier target list until this moment to avoid psi elements inside to GC
return result;
}
示例12: resolveOptimised
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@Nullable
private JavaResolveResult resolveOptimised(@NotNull PsiJavaCodeReferenceElement ref)
{
try
{
if(ref instanceof PsiReferenceExpressionImpl)
{
PsiReferenceExpressionImpl.OurGenericsResolver resolver = PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE;
JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(ref, resolver, true, true, myFile);
return results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
else
{
return ref.advancedResolve(true);
}
}
catch(IndexNotReadyException e)
{
return null;
}
}
示例13: resolveOptimised
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
@NotNull
private JavaResolveResult resolveOptimised(@NotNull PsiJavaCodeReferenceElement ref) {
JavaResolveResult result;
if (ref instanceof PsiReferenceExpressionImpl) {
JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(ref,
PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE,
true, true,
myFile);
result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
else {
result = ref.advancedResolve(true);
}
return result;
}
示例14: suggestFunctionalInterfaces
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
private static <T extends PsiElement> Collection<? extends PsiType> suggestFunctionalInterfaces(final @NotNull T element, final NullableFunction<PsiClass, PsiType> acceptanceChecker) {
final Project project = element.getProject();
final Set<PsiType> types = new HashSet<PsiType>();
final Processor<PsiMember> consumer = new Processor<PsiMember>() {
@Override
public boolean process(PsiMember member) {
if (member instanceof PsiClass && !Java15APIUsageInspectionBase.isForbiddenApiUsage(member, PsiUtil.getLanguageLevel(element))) {
if (!JavaResolveUtil.isAccessible(member, null, member.getModifierList(), element, null, null)) {
return true;
}
ContainerUtil.addIfNotNull(types, acceptanceChecker.fun((PsiClass)member));
}
return true;
}
};
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
final PsiClass functionalInterfaceClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, allScope);
if (functionalInterfaceClass != null) {
AnnotatedMembersSearch.search(functionalInterfaceClass, element.getResolveScope()).forEach(consumer);
}
for (String functionalInterface : FUNCTIONAL_INTERFACES) {
final PsiClass aClass = psiFacade.findClass(functionalInterface, allScope);
if (aClass != null) {
consumer.process(aClass);
}
}
final ArrayList<PsiType> typesToSuggest = new ArrayList<PsiType>(types);
Collections.sort(typesToSuggest, new Comparator<PsiType>() {
@Override
public int compare(PsiType o1, PsiType o2) {
return o1.getCanonicalText().compareTo(o2.getCanonicalText());
}
});
return typesToSuggest;
}
示例15: isAccessible
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入依赖的package包/类
protected boolean isAccessible(final PsiElement element) {
if (element instanceof PsiMember) {
final PsiMember member = (PsiMember)element;
return JavaResolveUtil.isAccessible(member, member.getContainingClass(), member.getModifierList(), this, null, null);
}
return true;
}