mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] add GrReferenceElement.getQualifiedReferenceName
This commit is contained in:
+4
-15
@@ -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-2017 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.lang.psi;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -31,6 +17,9 @@ public interface GrReferenceElement<Q extends PsiElement> extends GroovyPsiEleme
|
||||
@Nullable
|
||||
String getReferenceName();
|
||||
|
||||
@Nullable
|
||||
String getQualifiedReferenceName();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default PsiElement resolve() {
|
||||
|
||||
+17
-15
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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-2017 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.lang.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
@@ -32,6 +18,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
* @author ven
|
||||
*/
|
||||
public abstract class GrReferenceElementImpl<Q extends PsiElement> extends GroovyPsiElementImpl implements GrReferenceElement<Q> {
|
||||
|
||||
private static final String DUMMY_FQN = "05ab655a-0e15-4f35-909d-9dff5e757f63";
|
||||
|
||||
private volatile String myQualifiedReferenceName = DUMMY_FQN;
|
||||
private volatile String myCachedQName;
|
||||
private volatile String myCachedTextSkipWhiteSpaceAndComments;
|
||||
|
||||
@@ -46,6 +36,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
|
||||
@Override
|
||||
public void subtreeChanged() {
|
||||
myQualifiedReferenceName = DUMMY_FQN;
|
||||
myCachedQName = null;
|
||||
myCachedTextSkipWhiteSpaceAndComments = null;
|
||||
super.subtreeChanged();
|
||||
@@ -60,6 +51,17 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getQualifiedReferenceName() {
|
||||
String qualifiedReferenceName = myQualifiedReferenceName;
|
||||
if (qualifiedReferenceName == DUMMY_FQN) {
|
||||
qualifiedReferenceName = PsiImplUtilKt.getQualifiedReferenceName(this);
|
||||
myQualifiedReferenceName = qualifiedReferenceName;
|
||||
}
|
||||
return qualifiedReferenceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return this;
|
||||
|
||||
+14
@@ -9,6 +9,7 @@ import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValueProvider.Result
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod
|
||||
@@ -67,3 +68,16 @@ fun GrCodeReferenceElement.doGetKind(): CodeReferenceKind {
|
||||
else -> CodeReferenceKind.REFERENCE
|
||||
}
|
||||
}
|
||||
|
||||
fun getQualifiedReferenceName(reference: GrReferenceElement<*>): String? {
|
||||
val parts = mutableListOf<String>()
|
||||
var current = reference
|
||||
while (true) {
|
||||
val name = current.referenceName ?: return null
|
||||
parts.add(name)
|
||||
val qualifier = current.qualifier ?: break
|
||||
qualifier as? GrReferenceElement<*> ?: return null
|
||||
current = qualifier
|
||||
}
|
||||
return parts.reversed().joinToString(separator = ".")
|
||||
}
|
||||
|
||||
+6
@@ -44,6 +44,12 @@ public class GrLightClassReferenceElement extends LightElement implements GrCode
|
||||
return myClassName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getQualifiedReferenceName() {
|
||||
return myClassName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GroovyResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrCodeReferencePolyVariantResolver;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtilKt.doGetKind;
|
||||
import static org.jetbrains.plugins.groovy.lang.resolve.ReferencesKt.getQualifiedReferenceName;
|
||||
|
||||
/**
|
||||
* @author: Dmitry.Krasilschikov
|
||||
@@ -144,7 +143,7 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
return true;
|
||||
}
|
||||
else if (resolved instanceof PsiClass) {
|
||||
final String qualifiedReferenceName = getQualifiedReferenceName(this);
|
||||
final String qualifiedReferenceName = getQualifiedReferenceName();
|
||||
if (qualifiedReferenceName == null) return false;
|
||||
final String classFqn = ((PsiClass)resolved).getQualifiedName();
|
||||
if (classFqn == null) return false;
|
||||
|
||||
-1
@@ -5,7 +5,6 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.utils
|
||||
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.imports.*
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.qualifiedReferenceName
|
||||
|
||||
internal fun GrImportStatement.createImportFromStatement(): GroovyImport? {
|
||||
val reference = importReference ?: return null
|
||||
|
||||
@@ -5,20 +5,6 @@ import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement
|
||||
|
||||
val GrReferenceElement<*>.qualifiedReferenceName: String?
|
||||
get() {
|
||||
val parts = mutableListOf<String>()
|
||||
var current = this
|
||||
while (true) {
|
||||
val name = current.referenceName ?: return null
|
||||
parts.add(name)
|
||||
val qualifier = current.qualifier ?: break
|
||||
qualifier as? GrReferenceElement<*> ?: return null
|
||||
current = qualifier
|
||||
}
|
||||
return parts.reversed().joinToString(separator = ".")
|
||||
}
|
||||
|
||||
fun GrReferenceElement<*>.resolveClassFqn(): PsiClass? {
|
||||
val fqn = qualifiedReferenceName ?: return null
|
||||
return JavaPsiFacade.getInstance(project).findClass(fqn, resolveScope)
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ import org.jetbrains.plugins.groovy.lang.resolve.processClasses
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.GrDelegatingScopeProcessorWithHints
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.GroovyResolveKind
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.StaticMembersFilteringProcessor
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.qualifiedReferenceName
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.resolveClassFqn
|
||||
import org.jetbrains.plugins.groovy.util.consumeAll
|
||||
|
||||
|
||||
Reference in New Issue
Block a user