use of org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType in project intellij-community by JetBrains.
the class MapKeysCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
GrReferenceExpression expression = (GrReferenceExpression) element.getParent();
GrExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression == null)
return;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return;
}
PsiElement resolve = null;
if (qualifierExpression instanceof GrMethodCall) {
resolve = ((GrMethodCall) qualifierExpression).resolveMethod();
} else if (qualifierExpression instanceof GrReferenceExpression) {
resolve = ((GrReferenceExpression) qualifierExpression).resolve();
}
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
GroovyMapCompletionUtil.addKeyVariants(provider, qualifierExpression, resolve, result);
}
if (mapType instanceof GrMapType) {
for (String key : ((GrMapType) mapType).getStringKeys()) {
LookupElement lookup = LookupElementBuilder.create(key);
lookup = PrioritizedLookupElement.withPriority(lookup, 1);
result.addElement(lookup);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType in project intellij-community by JetBrains.
the class GroovyMapValueTypeEnhancer method getReferenceType.
@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
if (resolved != null)
return null;
GrExpression qualifierExpression = ref.getQualifierExpression();
if (qualifierExpression == null)
return null;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return null;
}
PsiElement qResolved;
if (qualifierExpression instanceof GrReferenceExpression) {
qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
} else if (qualifierExpression instanceof GrMethodCall) {
qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
} else {
return null;
}
String key = ref.getReferenceName();
if (key == null)
return null;
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
if (type != null) {
return type;
}
}
if (mapType instanceof GrMapType) {
return ((GrMapType) mapType).getTypeByStringKey(key);
}
return null;
}
Aggregations