use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement in project intellij-community by JetBrains.
the class JavaSafeDeleteDelegateForGroovy method createUsageInfoForParameter.
@Override
public void createUsageInfoForParameter(PsiReference reference, List<UsageInfo> usages, final PsiParameter parameter, final PsiMethod method) {
int index = method.getParameterList().getParameterIndex(parameter);
final PsiElement element = reference.getElement();
GrCall call = null;
if (element instanceof GrCall) {
call = (GrCall) element;
} else if (element.getParent() instanceof GrCall) {
call = (GrCall) element.getParent();
}
if (call != null) {
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(call);
//todo ???
if (signature == null)
return;
GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, call);
//todo???
if (argInfos == null)
return;
for (PsiElement arg : argInfos[index].args) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(arg, parameter, true));
}
} else if (element instanceof GrDocMethodReference) {
@NonNls final StringBuilder newText = new StringBuilder();
newText.append("/** @see ");
GrDocReferenceElement holder = ((GrDocMethodReference) element).getReferenceHolder();
if (holder != null) {
newText.append(holder.getText());
}
newText.append('#');
newText.append(method.getName());
newText.append('(');
final List<PsiParameter> parameters = new ArrayList<>(Arrays.asList(method.getParameterList().getParameters()));
parameters.remove(parameter);
newText.append(StringUtil.join(parameters, psiParameter -> parameter.getType().getCanonicalText(), ","));
newText.append(")*/");
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
@Override
public void deleteElement() throws IncorrectOperationException {
((GrDocMethodReference) element).bindToText(method.getProject(), newText.toString());
}
});
}
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement 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.GrDocReferenceElement 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.GrDocReferenceElement in project intellij-community by JetBrains.
the class GrDocMethodParamsImpl method getParameterTypes.
@Override
public PsiType[] getParameterTypes() {
ArrayList<PsiType> types = new ArrayList<>();
PsiManagerEx manager = getManager();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
for (GrDocMethodParameter parameter : getParameters()) {
GrDocReferenceElement typeElement = parameter.getTypeElement();
try {
PsiType type = factory.createTypeFromText(typeElement.getText(), this);
type = TypesUtil.boxPrimitiveType(type, manager, scope);
types.add(type);
} catch (IncorrectOperationException e) {
LOG.info(e);
types.add(null);
}
}
return types.toArray(PsiType.createArray(types.size()));
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement in project intellij-community by JetBrains.
the class GrDocFieldReferenceImpl method multiResolveImpl.
@Override
protected ResolveResult[] multiResolveImpl() {
String name = getReferenceName();
GrDocReferenceElement holder = getReferenceHolder();
PsiElement resolved;
if (holder != null) {
GrCodeReferenceElement referenceElement = holder.getReferenceElement();
resolved = referenceElement != null ? referenceElement.resolve() : null;
} else {
resolved = PsiUtil.getContextClass(GrDocCommentUtil.findDocOwner(this));
}
if (resolved instanceof PsiClass) {
PropertyResolverProcessor processor = new PropertyResolverProcessor(name, this);
resolved.processDeclarations(processor, ResolveState.initial(), resolved, this);
GroovyResolveResult[] candidates = processor.getCandidates();
if (candidates.length == 0) {
PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
MethodResolverProcessor methodProcessor = new MethodResolverProcessor(name, this, false, thisType, null, PsiType.EMPTY_ARRAY);
MethodResolverProcessor constructorProcessor = new MethodResolverProcessor(name, this, true, thisType, null, PsiType.EMPTY_ARRAY);
resolved.processDeclarations(methodProcessor, ResolveState.initial(), resolved, this);
resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this);
candidates = ArrayUtil.mergeArrays(methodProcessor.getCandidates(), constructorProcessor.getCandidates());
if (candidates.length > 0) {
candidates = new GroovyResolveResult[] { candidates[0] };
}
}
return candidates;
}
return ResolveResult.EMPTY_ARRAY;
}
Aggregations