mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] update expressionTypeCalculator implementations to use new API
This commit is contained in:
+6
-2
@@ -92,7 +92,10 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.javaView.GroovyClassFinder;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.search.GrPrivateFieldScopeEnlarger;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.smartPointers.GrClassReferenceTypePointerFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.DefaultCallExpressionTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrDGMTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrDescriptorReturnTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrWithTraitTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.index.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyConstantExpressionEvaluator;
|
||||
@@ -108,6 +111,7 @@ import org.jetbrains.plugins.groovy.lang.resolve.ast.builder.strategy.SimpleBuil
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.noncode.GrCollectionTypeMembersProvider;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.noncode.MixinMemberContributor;
|
||||
import org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache;
|
||||
import org.jetbrains.plugins.groovy.lang.typing.GrClosureDelegateTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.typing.GrTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.typing.MethodCallTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.typing.ReferenceExpressionTypeCalculator;
|
||||
@@ -224,7 +228,6 @@ public class GroovyCoreEnvironment {
|
||||
appEnvironment.addExtension(GrCallExpressionTypeCalculator.EP_NAME, new GrWithTraitTypeCalculator());
|
||||
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), GrExpressionTypeCalculator.EP_NAME, GrExpressionTypeCalculator.class);
|
||||
appEnvironment.addExtension(GrExpressionTypeCalculator.EP_NAME, new GrClosureDelegateTypeCalculator());
|
||||
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), GroovyClassDescriptor.EP_NAME,
|
||||
GroovyClassDescriptor.class);
|
||||
@@ -349,6 +352,7 @@ public class GroovyCoreEnvironment {
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ReadWriteAccessDetector.EP_NAME, ReadWriteAccessDetector.class);
|
||||
appEnvironment.addExtension(ReadWriteAccessDetector.EP_NAME, new GroovyReadWriteAccessDetector());
|
||||
|
||||
appEnvironment.addExplicitExtension(GrTypeCalculator.EP, GrReferenceExpression.class, new GrClosureDelegateTypeCalculator());
|
||||
appEnvironment.addExplicitExtension(GrTypeCalculator.EP, GrReferenceExpression.class, new ReferenceExpressionTypeCalculator());
|
||||
appEnvironment.addExplicitExtension(GrTypeCalculator.EP, GrMethodCall.class, new MethodCallTypeCalculator());
|
||||
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.GrExpressionTypeCalculator;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DelegatesToInfo;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.GrDelegatesToUtilKt;
|
||||
|
||||
public class GrClosureDelegateTypeCalculator extends GrExpressionTypeCalculator {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType calculateType(@NotNull GrExpression expression, @Nullable PsiElement resolved) {
|
||||
if (expression instanceof GrReferenceExpression && resolved instanceof PsiMethod) {
|
||||
return calculateType(expression, (PsiMethod)resolved);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PsiType calculateType(@NotNull GrExpression expression, @NotNull PsiMethod method) {
|
||||
if (!"getDelegate".equals(method.getName()) || method.getParameterList().getParametersCount() != 0) return null;
|
||||
|
||||
final GrClosableBlock closure = PsiTreeUtil.getParentOfType(expression, GrClosableBlock.class);
|
||||
if (closure == null) return null;
|
||||
|
||||
final PsiClass closureClass = JavaPsiFacade.getInstance(expression.getProject()).findClass(
|
||||
GroovyCommonClassNames.GROOVY_LANG_CLOSURE, expression.getResolveScope()
|
||||
);
|
||||
if (closureClass == null || !closureClass.equals(method.getContainingClass())) return null;
|
||||
|
||||
final DelegatesToInfo info = GrDelegatesToUtilKt.getDelegatesToInfo(closure);
|
||||
if (info == null) return null;
|
||||
|
||||
return info.getTypeToDelegate();
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.typing
|
||||
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_LANG_CLOSURE
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.getDelegatesToInfo
|
||||
|
||||
class GrClosureDelegateTypeCalculator : GrTypeCalculator<GrReferenceExpression> {
|
||||
|
||||
override fun getType(expression: GrReferenceExpression): PsiType? {
|
||||
val method = expression.resolve() as? PsiMethod ?: return null
|
||||
if ("getDelegate" != method.name || method.parameterList.parametersCount != 0) return null
|
||||
|
||||
val closureClass = JavaPsiFacade.getInstance(expression.project).findClass(GROOVY_LANG_CLOSURE, expression.resolveScope)
|
||||
if (closureClass == null || closureClass != method.containingClass) return null
|
||||
|
||||
val closure = PsiTreeUtil.getParentOfType(expression, GrClosableBlock::class.java) ?: return null
|
||||
return getDelegatesToInfo(closure)?.typeToDelegate
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,8 @@
|
||||
implementation="org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrDescriptorReturnTypeCalculator"/>
|
||||
<callExpressionTypeCalculator
|
||||
implementation="org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrDGMTypeCalculator"/>
|
||||
<expressionTypeCalculator
|
||||
implementation="org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrClosureDelegateTypeCalculator"/>
|
||||
<typeCalculator forClass="org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression"
|
||||
implementationClass="org.jetbrains.plugins.groovy.lang.typing.GrClosureDelegateTypeCalculator"/>
|
||||
<typeCalculator forClass="org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression"
|
||||
implementationClass="org.jetbrains.plugins.groovy.lang.typing.ReferenceExpressionTypeCalculator"
|
||||
order="last"/>
|
||||
|
||||
Reference in New Issue
Block a user