use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrThrowsClauseImpl method add.
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
if (element instanceof GrCodeReferenceElement || element instanceof PsiJavaCodeReferenceElement) {
if (findChildByClass(GrCodeReferenceElement.class) == null) {
getNode().addLeaf(GroovyTokenTypes.kTHROWS, "throws", null);
} else {
PsiElement lastChild = getLastChild();
lastChild = PsiUtil.skipWhitespacesAndComments(lastChild, false);
if (!lastChild.getNode().getElementType().equals(GroovyTokenTypes.mCOMMA)) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", null);
}
}
if (element instanceof PsiJavaCodeReferenceElement) {
element = GroovyPsiElementFactory.getInstance(getProject()).createCodeReferenceElementFromText(element.getText());
}
}
return super.add(element);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrAnnotationNameValuePairImpl method multiResolve.
@NotNull
@Override
public GroovyResolveResult[] multiResolve(boolean incompleteCode) {
GrAnnotation annotation = PsiImplUtil.getAnnotation(this);
if (annotation != null) {
GrCodeReferenceElement ref = annotation.getClassReference();
PsiElement resolved = ref.resolve();
String declaredName = getName();
String name = declaredName == null ? PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME : declaredName;
if (resolved instanceof PsiClass) {
final PsiAnnotation collector = GrAnnotationCollector.findAnnotationCollector((PsiClass) resolved);
if (collector != null) {
return multiResolveFromAlias(annotation, name, collector);
}
if (((PsiClass) resolved).isAnnotationType()) {
return multiResolveFromAnnotationType((PsiClass) resolved, name);
}
}
}
return GroovyResolveResult.EMPTY_ARRAY;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrAnnotationCollector method findAnnotationCollector.
@Nullable
public static PsiAnnotation findAnnotationCollector(@NotNull GrAnnotation annotation) {
final GrCodeReferenceElement ref = annotation.getClassReference();
final PsiElement resolved = ref.resolve();
if (resolved instanceof PsiClass) {
return findAnnotationCollector((PsiClass) resolved);
} else {
return null;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrNewExpressionImpl method resolveImpl.
private GroovyResolveResult[] resolveImpl(boolean incompleteCode) {
GrCodeReferenceElement ref = getReferenceElement();
if (ref == null)
return GroovyResolveResult.EMPTY_ARRAY;
GroovyResolveResult classCandidate = inferClassCandidate(ref);
if (classCandidate == null)
return GroovyResolveResult.EMPTY_ARRAY;
assert classCandidate.getElement() instanceof PsiClass;
if (incompleteCode) {
return PsiUtil.getConstructorCandidates(ref, classCandidate, null);
}
final GrArgumentList argumentList = getArgumentList();
if (argumentList == null)
return GroovyResolveResult.EMPTY_ARRAY;
if (argumentList.getNamedArguments().length > 0 && argumentList.getExpressionArguments().length == 0) {
PsiType mapType = GrMapType.createFromNamedArgs(argumentList, getNamedArguments());
//one Map parameter, actually
GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classCandidate, new PsiType[] { mapType });
for (GroovyResolveResult result : constructorResults) {
final PsiElement resolved = result.getElement();
if (resolved instanceof PsiMethod) {
PsiMethod constructor = (PsiMethod) resolved;
final PsiParameter[] parameters = constructor.getParameterList().getParameters();
if (parameters.length == 1 && InheritanceUtil.isInheritor(parameters[0].getType(), CommonClassNames.JAVA_UTIL_MAP)) {
return constructorResults;
}
}
}
final GroovyResolveResult[] emptyConstructors = PsiUtil.getConstructorCandidates(ref, classCandidate, PsiType.EMPTY_ARRAY);
if (emptyConstructors.length > 0) {
return emptyConstructors;
}
}
PsiType[] types = PsiUtil.getArgumentTypes(ref, true);
if (types != null) {
types = GrInnerClassConstructorUtil.addEnclosingArgIfNeeded(types, this, (PsiClass) classCandidate.getElement());
}
return PsiUtil.getConstructorCandidates(ref, classCandidate, types);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrReferenceListImpl method getReferenceElementsGroovy.
@Override
@NotNull
public GrCodeReferenceElement[] getReferenceElementsGroovy() {
final GrReferenceListStub stub = getStub();
if (stub != null) {
final String[] baseClasses = stub.getBaseClasses();
final GrCodeReferenceElement[] result = new GrCodeReferenceElement[baseClasses.length];
for (int i = 0; i < baseClasses.length; i++) {
result[i] = GroovyPsiElementFactory.getInstance(getProject()).createReferenceElementFromText(baseClasses[i], this);
}
return result;
}
return findChildrenByClass(GrCodeReferenceElement.class);
}
Aggregations