[groovy] resolve to class only statically

After the change the reference could be resolved to a class only if it
is a part on fqn. This case is handled before resolver processor is even
created.
This commit is contained in:
Daniil Ovchinnikov
2018-03-12 22:48:34 +03:00
parent 018667b876
commit 0ecc225dd3
6 changed files with 6 additions and 53 deletions
@@ -907,17 +907,6 @@ public class ResolveUtil {
}
}
public static boolean canBeClass(final GrReferenceExpression ref) {
GrExpression qualifier = ref.getQualifier();
if (qualifier instanceof GrReferenceExpression) {
final PsiElement resolvedQualifier = ((GrReferenceExpression)qualifier).resolve();
return resolvedQualifier instanceof PsiClass || resolvedQualifier instanceof PsiPackage;
}
else {
return qualifier == null;
}
}
public static boolean canBeClassOrPackage(final GrReferenceExpression ref) {
GrExpression qualifier = ref.getQualifier();
if (qualifier instanceof GrReferenceExpression) {
@@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
import java.util.EnumSet;
@@ -63,9 +62,9 @@ public final class GroovyResolverProcessorBuilder {
if (ref.hasMemberPointer()) return EnumSet.of(METHOD);
final EnumSet<GroovyResolveKind> result = EnumSet.allOf(GroovyResolveKind.class);
result.remove(CLASS);
result.remove(PACKAGE);
if (!ResolveUtil.canBeClass(ref)) result.remove(CLASS);
if (ref.isQualified()) result.remove(BINDING);
if (!(ref.getParent() instanceof GrMethodCall)) result.remove(METHOD);
@@ -52,11 +52,6 @@ class GroovyResolverProcessorImpl extends GroovyResolverProcessor implements GrM
return candidates;
}
candidates = getCandidates(GroovyResolveKind.CLASS);
if (!candidates.isEmpty()) {
return candidates;
}
candidates = getCandidates(GroovyResolveKind.PROPERTY);
if (!candidates.isEmpty()) {
return candidates;
@@ -1,21 +1,6 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.ext.newify
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiMethod
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.annotations.NotNull
@@ -122,8 +107,7 @@ class B {
@Newify
def a (){ return A<caret>a(name :"bar")}
}
""", PsiClass
"""
}
void checkResolve(@NotNull String text, @Nullable Class<?> refType = null, @Nullable String returnType = null) {
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.ext.newify
import com.intellij.testFramework.LightProjectDescriptor
@@ -179,7 +165,7 @@ class B {
testHighlighting """
class B {
@Newify
def a (){ return A<warning>()</warning>}
def a (){ return <warning descr="Cannot resolve symbol 'A'">A</warning>()}
}
"""
}
@@ -3,6 +3,6 @@ class BitImage {
int width
int getHeight() {
Math(data.length / width)
java.lang.Math(data.length / width)
}
}