[by max medvedev]: eliminating TopLevelParentClassProvider extension point and moving its functionality to GroovyPositionManager

This commit is contained in:
Eugene Zhuravlev
2013-10-23 19:27:02 +02:00
parent cce9bd8983
commit 520bb4b6bb
5 changed files with 10 additions and 109 deletions
@@ -1,47 +0,0 @@
/*
* Copyright 2000-2011 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 com.intellij.debugger.engine;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
/**
* @author Max Medvedev
*/
public abstract class TopLevelParentClassProvider {
private static final ExtensionPointName<TopLevelParentClassProvider> EP_NAME =
ExtensionPointName.create("com.intellij.topLevelClassProvider");
public static PsiClass getTopLevelParentClass(PsiClass psiClass) {
for (TopLevelParentClassProvider provider : EP_NAME.getExtensions()) {
final PsiClass custom = provider.getCustomTopLevelParentClass(psiClass);
if (custom != null) return custom;
}
PsiClass enclosing = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class, true);
while (enclosing != null) {
psiClass = enclosing;
enclosing = PsiTreeUtil.getParentOfType(enclosing, PsiClass.class, true);
}
return psiClass;
}
@Nullable
protected abstract PsiClass getCustomTopLevelParentClass(PsiClass psiClass);
}
-2
View File
@@ -393,8 +393,6 @@
<weigher key="proximity" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrReferenceListWeigher"
id="groovyReferenceListWeigher" order="before openedInEditor"/>
<topLevelClassProvider implementation="org.jetbrains.plugins.groovy.debugger.GroovyTopLevelParentClassProvider"/>
<debuggerClassFilterProvider implementation="org.jetbrains.plugins.groovy.debugger.filters.GroovyDebuggerClassFilterProvider"/>
<useScopeEnlarger implementation="org.jetbrains.plugins.groovy.lang.psi.impl.search.GrPrivateFieldScopeEnlarger"/>
@@ -53,7 +53,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefini
import org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class GroovyPositionManager implements PositionManager {
@@ -94,13 +93,16 @@ public class GroovyPositionManager implements PositionManager {
}
@Nullable
private static GrTypeDefinition findEnclosingTypeDefinition(SourcePosition position) {
private static PsiClass findEnclosingTypeDefinition(SourcePosition position) {
PsiFile file = position.getFile();
if (!(file instanceof GroovyFileBase)) return null;
PsiElement element = file.findElementAt(position.getOffset());
while (true) {
element = PsiTreeUtil.getParentOfType(element, GrTypeDefinition.class);
if (element == null || !((GrTypeDefinition)element).isAnonymous()) {
element = PsiTreeUtil.getParentOfType(element, GrTypeDefinition.class, GroovyFileBase.class);
if (element instanceof GroovyFileBase) {
return ((GroovyFileBase)element).getScriptClass();
}
else if (element instanceof GrTypeDefinition && !((GrTypeDefinition)element).isAnonymous()) {
return (GrTypeDefinition)element;
}
}
@@ -132,7 +134,7 @@ public class GroovyPositionManager implements PositionManager {
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
GrTypeDefinition typeDefinition = findEnclosingTypeDefinition(position);
PsiClass typeDefinition = findEnclosingTypeDefinition(position);
if (typeDefinition != null) {
return getClassNameForJvm(typeDefinition);
}
@@ -284,7 +286,7 @@ public class GroovyPositionManager implements PositionManager {
}
else {
String enclosingName = findEnclosingName(position);
if (enclosingName == null) return Collections.emptyList();
if (enclosingName == null) return null;
final List<ReferenceType> outers = myDebugProcess.getVirtualMachineProxy().classesByName(enclosingName);
final List<ReferenceType> result = new ArrayList<ReferenceType>(outers.size());
@@ -296,11 +298,11 @@ public class GroovyPositionManager implements PositionManager {
}
return result;
}
return Collections.emptyList();
return null;
}
});
if (result == null || result.isEmpty()) throw new NoDataException();
if (result == null) throw new NoDataException();
return result;
}
@@ -1,51 +0,0 @@
/*
* Copyright 2000-2011 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.debugger;
import com.intellij.debugger.engine.TopLevelParentClassProvider;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
/**
* @author Max Medvedev
*/
public class GroovyTopLevelParentClassProvider extends TopLevelParentClassProvider {
@Nullable
@Override
protected PsiClass getCustomTopLevelParentClass(PsiClass psiClass) {
if (!(psiClass instanceof GrTypeDefinition)) return null;
PsiClass enclosing = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class, true);
while (enclosing != null) {
psiClass = enclosing;
enclosing = PsiTreeUtil.getParentOfType(enclosing, PsiClass.class, true);
}
if (psiClass instanceof PsiAnonymousClass) {
final PsiFile file = psiClass.getContainingFile();
if (file instanceof GroovyFile) {
return ((GroovyFile)file).getScriptClass();
}
}
return psiClass;
}
}
-1
View File
@@ -144,7 +144,6 @@
<extensionPoint name="importFilter" interface="com.intellij.codeInsight.ImportFilter"/>
<extensionPoint name="debuggerClassFilterProvider" interface="com.intellij.ui.classFilter.DebuggerClassFilterProvider"/>
<extensionPoint name="topLevelClassProvider" interface="com.intellij.debugger.engine.TopLevelParentClassProvider"/>
<extensionPoint name="debuggerEditorTextProvider" beanClass="com.intellij.lang.LanguageExtensionPoint" >
<with attribute="implementationClass" implements="com.intellij.debugger.impl.EditorTextProvider"/>