use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference in project intellij-community by JetBrains.
the class GroovyDocCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
final PsiElement position = parameters.getPosition();
GrDocMemberReference reference = PsiTreeUtil.getParentOfType(position, GrDocMemberReference.class);
if (reference == null)
return;
GrDocReferenceElement holder = reference.getReferenceHolder();
PsiElement resolved;
if (holder != null) {
GrCodeReferenceElement referenceElement = holder.getReferenceElement();
resolved = referenceElement != null ? referenceElement.resolve() : null;
} else {
resolved = PsiUtil.getContextClass(reference);
}
if (resolved instanceof PsiClass) {
ResolverProcessor propertyProcessor = CompletionProcessor.createPropertyCompletionProcessor(reference);
resolved.processDeclarations(propertyProcessor, ResolveState.initial(), null, reference);
PsiElement[] propertyCandidates = ResolveUtil.mapToElements(propertyProcessor.getCandidates());
ResolverProcessor methodProcessor = CompletionProcessor.createPropertyCompletionProcessor(reference);
resolved.processDeclarations(methodProcessor, ResolveState.initial(), null, reference);
PsiElement[] methodCandidates = ResolveUtil.mapToElements(methodProcessor.getCandidates());
PsiElement[] elements = ArrayUtil.mergeArrays(propertyCandidates, methodCandidates);
for (PsiElement psiElement : elements) {
LookupElement element = GroovyCompletionUtil.createLookupElement((PsiNamedElement) psiElement);
if (psiElement instanceof PsiMethod) {
element = ((LookupElementBuilder) element).withInsertHandler(new GroovyMethodSignatureInsertHandler());
}
result.addElement(element);
}
}
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference in project intellij-community by JetBrains.
the class GroovyMethodSignatureInsertHandler method shortenReferences.
private static void shortenReferences(final Project project, final Editor editor, InsertionContext context, int offset) {
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
final PsiElement element = context.getFile().findElementAt(offset);
final GrDocMemberReference tagValue = PsiTreeUtil.getParentOfType(element, GrDocMemberReference.class);
if (tagValue != null) {
try {
JavaCodeStyleManager.getInstance(project).shortenClassReferences(tagValue);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference in project intellij-community by JetBrains.
the class GrDocMemberReferenceImpl method bindToElement.
@Override
@Nullable
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (isReferenceTo(element))
return this;
if (element instanceof PsiClass) {
GrDocReferenceElement holder = getReferenceHolder();
if (holder != null) {
return replace(holder.getReferenceElement().bindToElement(element).getParent());
}
GrDocReferenceElement ref = GroovyPsiElementFactory.getInstance(getProject()).createDocReferenceElementFromFQN(((PsiClass) element).getQualifiedName());
return replace(ref);
} else if (element instanceof PsiMember) {
PsiClass clazz = ((PsiMember) element).getContainingClass();
if (clazz == null)
return null;
String qName = clazz.getQualifiedName();
String memberRefText;
if (element instanceof PsiField) {
memberRefText = ((PsiField) element).getName();
} else if (element instanceof PsiMethod) {
PsiParameterList list = ((PsiMethod) element).getParameterList();
StringBuilder builder = new StringBuilder();
builder.append(((PsiMethod) element).getName()).append("(");
PsiParameter[] params = list.getParameters();
for (int i = 0; i < params.length; i++) {
PsiParameter parameter = params[i];
PsiType type = parameter.getType();
if (i > 0)
builder.append(", ");
builder.append(type.getPresentableText());
}
builder.append(")");
memberRefText = builder.toString();
} else {
return null;
}
GrDocMemberReference ref = GroovyPsiElementFactory.getInstance(getProject()).createDocMemberReferenceFromText(qName, memberRefText);
return replace(ref);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference in project intellij-community by JetBrains.
the class GroovyPsiElementFactoryImpl method createDocMemberReferenceNameFromText.
@NotNull
@Override
public PsiElement createDocMemberReferenceNameFromText(@NotNull String idText) {
GrDocMemberReference reference = createDocMemberReferenceFromText("Foo", idText);
LOG.assertTrue(reference != null, idText);
return reference.getReferenceNameElement();
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference in project intellij-community by JetBrains.
the class GroovyDocCheckInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitDocMethodReference(@NotNull GrDocMethodReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitDocFieldReference(@NotNull GrDocFieldReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement refElement) {
GroovyResolveResult resolveResult = refElement.advancedResolve();
if (refElement.getReferenceName() == null)
return;
if (PsiTreeUtil.getParentOfType(refElement, GroovyDocPsiElement.class, true, GrMember.class, GrCodeBlock.class) == null)
return;
final PsiElement resolved = resolveResult.getElement();
if (resolved != null)
return;
final PsiElement toHighlight = refElement.getReferenceNameElement();
registerError(toHighlight, GroovyBundle.message("cannot.resolve", refElement.getReferenceName()));
}
private void checkGrDocMemberReference(final GrDocMemberReference reference) {
if (reference.resolve() != null)
return;
registerError(reference.getReferenceNameElement(), GroovyBundle.message("cannot.resolve", reference.getReferenceName()));
}
};
}
Aggregations