public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { if (isReferenceTo(element)) return getElement(); final String newName; if (element instanceof PsiClass) { PsiClass psiClass = (PsiClass) element; final boolean jvmFormat = Boolean.TRUE.equals(JavaClassReferenceProvider.JVM_FORMAT.getValue(getOptions())); newName = jvmFormat ? ClassUtil.getJVMClassName(psiClass) : psiClass.getQualifiedName(); } else if (element instanceof PsiPackage) { PsiPackage psiPackage = (PsiPackage) element; newName = psiPackage.getQualifiedName(); } else { throw new IncorrectOperationException("Cannot bind to " + element); } assert newName != null; TextRange range = new TextRange( myJavaClassReferenceSet.getReference(0).getRangeInElement().getStartOffset(), getRangeInElement().getEndOffset()); final ElementManipulator<PsiElement> manipulator = getManipulator(getElement()); if (manipulator != null) { final PsiElement finalElement = manipulator.handleContentChange(getElement(), range, newName); range = new TextRange(range.getStartOffset(), range.getStartOffset() + newName.length()); myJavaClassReferenceSet.reparse(finalElement, range); return finalElement; } return element; }
private JavaResolveResult doAdvancedResolve() { final PsiElement psiElement = getElement(); if (!psiElement.isValid()) return JavaResolveResult.EMPTY; final String elementText = psiElement.getText(); final PsiElement context = getContext(); if (context instanceof PsiClass) { if (isStaticClassReference(elementText, false)) { final PsiClass psiClass = ((PsiClass) context).findInnerClassByName(getCanonicalText(), false); if (psiClass != null) return new ClassCandidateInfo(psiClass, PsiSubstitutor.EMPTY, false, psiElement); PsiElement member = doResolveMember((PsiClass) context, myText); return member == null ? JavaResolveResult.EMPTY : new CandidateInfo(member, PsiSubstitutor.EMPTY, false, false, psiElement); } else if (!myInStaticImport && myJavaClassReferenceSet.isAllowDollarInNames()) { return JavaResolveResult.EMPTY; } } final int endOffset = getRangeInElement().getEndOffset(); LOG.assertTrue(endOffset <= elementText.length(), elementText); final int startOffset = myJavaClassReferenceSet.getReference(0).getRangeInElement().getStartOffset(); final String qName = elementText.substring(startOffset, endOffset); if (!qName.contains(".")) { final String defaultPackage = JavaClassReferenceProvider.DEFAULT_PACKAGE.getValue(getOptions()); if (StringUtil.isNotEmpty(defaultPackage)) { final JavaResolveResult resolveResult = advancedResolveInner(psiElement, defaultPackage + "." + qName); if (resolveResult != JavaResolveResult.EMPTY) { return resolveResult; } } } return advancedResolveInner(psiElement, qName); }
@Nullable public PsiReference getContextReference() { return myIndex > 0 ? myJavaClassReferenceSet.getReference(myIndex - 1) : null; }