use of org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider 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.extensions.GroovyMapContentProvider 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;
}
use of org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider in project intellij-community by JetBrains.
the class NamedDomainObjectCollectionTypeEnhancer 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 namedDomainCollectionType = GradleResolverUtil.getTypeOf(qualifierExpression);
if (!InheritanceUtil.isInheritor(namedDomainCollectionType, GradleCommonClassNames.GRADLE_API_NAMED_DOMAIN_OBJECT_COLLECTION)) {
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 (namedDomainCollectionType instanceof PsiClassReferenceType) {
final PsiClassReferenceType referenceType = (PsiClassReferenceType) namedDomainCollectionType;
final String fqName = TypesUtil.getQualifiedName(referenceType);
if (GradleCommonClassNames.GRADLE_API_SOURCE_SET_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_SOURCE_SET, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_CONFIGURATION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_CONFIGURATION, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_TASK_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_TASK, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_DISTRIBUTION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_DISTRIBUTION, ref.getResolveScope());
} else {
GradleExtensionsSettings.GradleExtensionsData extensionsData = GradleExtensionsContributor.Companion.getExtensionsFor(ref);
if (extensionsData != null) {
for (GradleExtensionsSettings.GradleExtension extension : extensionsData.extensions) {
if (StringUtil.isNotEmpty(extension.namedObjectTypeFqn) && extension.rootTypeFqn.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(extension.namedObjectTypeFqn, ref.getResolveScope());
}
}
}
}
}
return null;
}
Aggregations