use of com.intellij.codeInsight.editorActions.ReferenceData in project intellij-community by JetBrains.
the class GroovyReferenceCopyPasteProcessor method findReferencesToRestore.
@NotNull
@Override
protected GrReferenceElement[] findReferencesToRestore(PsiFile file, RangeMarker bounds, ReferenceData[] referenceData) {
PsiManager manager = file.getManager();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
PsiResolveHelper helper = facade.getResolveHelper();
GrReferenceElement[] refs = new GrReferenceElement[referenceData.length];
for (int i = 0; i < referenceData.length; i++) {
ReferenceData data = referenceData[i];
PsiClass refClass = facade.findClass(data.qClassName, file.getResolveScope());
if (refClass == null)
continue;
int startOffset = data.startOffset + bounds.getStartOffset();
int endOffset = data.endOffset + bounds.getStartOffset();
PsiElement element = file.findElementAt(startOffset);
if (element != null && element.getParent() instanceof GrReferenceElement && !PsiUtil.isThisOrSuperRef(element.getParent())) {
GrReferenceElement reference = (GrReferenceElement) element.getParent();
TextRange range = reference.getTextRange();
if (range.getStartOffset() == startOffset && range.getEndOffset() == endOffset) {
if (data.staticMemberName == null) {
PsiClass refClass1 = helper.resolveReferencedClass(reference.getText(), reference);
if (refClass1 == null || !manager.areElementsEquivalent(refClass, refClass1)) {
refs[i] = reference;
}
} else {
if (reference instanceof GrReferenceExpression) {
PsiElement referent = resolveReferenceIgnoreOverriding(reference);
if (!(referent instanceof PsiNamedElement) || !data.staticMemberName.equals(((PsiNamedElement) referent).getName()) || !(referent instanceof PsiMember) || ((PsiMember) referent).getContainingClass() == null || !data.qClassName.equals(((PsiMember) referent).getContainingClass().getQualifiedName())) {
refs[i] = reference;
}
}
}
}
}
}
return refs;
}
use of com.intellij.codeInsight.editorActions.ReferenceData in project intellij-community by JetBrains.
the class GroovyReferenceCopyPasteProcessor method restoreReferences.
@Override
protected void restoreReferences(ReferenceData[] referenceData, GrReferenceElement[] refs) {
for (int i = 0; i < refs.length; i++) {
GrReferenceElement reference = refs[i];
if (reference == null)
continue;
try {
PsiManager manager = reference.getManager();
ReferenceData refData = referenceData[i];
PsiClass refClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(refData.qClassName, reference.getResolveScope());
if (refClass != null) {
if (refData.staticMemberName == null) {
reference.bindToElement(refClass);
} else {
LOG.assertTrue(reference instanceof GrReferenceExpression);
PsiMember member = findMember(refData, refClass);
if (member != null) {
((GrReferenceExpression) reference).bindToElementViaStaticImport(member);
}
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
Aggregations