Delete OBJECT_DECLARATION_NAME slice and relevant usages

JetObjectDeclarationName is almost useless now, since properties aren't created
for objects anymore
This commit is contained in:
Alexander Udalov
2013-11-15 18:24:18 +04:00
parent 0792af5f85
commit 90490b5c0c
8 changed files with 9 additions and 65 deletions
@@ -195,19 +195,6 @@ public class JetPsiUtil {
@Nullable
public static FqName getFQName(@NotNull JetNamedDeclaration namedDeclaration) {
if (namedDeclaration instanceof JetObjectDeclarationName) {
JetNamedDeclaration objectDeclaration = PsiTreeUtil.getParentOfType(namedDeclaration, JetObjectDeclaration.class);
if (objectDeclaration == null) {
objectDeclaration = PsiTreeUtil.getParentOfType(namedDeclaration, JetEnumEntry.class);
}
if (objectDeclaration == null) {
return null;
}
return getFQName(objectDeclaration);
}
Name name = namedDeclaration.getNameAsName();
if (name == null) {
return null;
@@ -224,20 +224,15 @@ public interface BindingContext {
WritableSlice<PsiElement, PropertyDescriptor> PRIMARY_CONSTRUCTOR_PARAMETER =
Slices.<PsiElement, PropertyDescriptor>sliceBuilder().setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION)
.build();
WritableSlice<JetObjectDeclarationName, PropertyDescriptor> OBJECT_DECLARATION =
Slices.<JetObjectDeclarationName, PropertyDescriptor>sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
WritableSlice[] DECLARATIONS_TO_DESCRIPTORS = new WritableSlice[] {
NAMESPACE, CLASS, TYPE_PARAMETER, FUNCTION, CONSTRUCTOR, VARIABLE, VALUE_PARAMETER, PROPERTY_ACCESSOR,
PRIMARY_CONSTRUCTOR_PARAMETER, OBJECT_DECLARATION
PRIMARY_CONSTRUCTOR_PARAMETER
};
ReadOnlySlice<PsiElement, DeclarationDescriptor> DECLARATION_TO_DESCRIPTOR = Slices.<PsiElement, DeclarationDescriptor>sliceBuilder()
.setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS).build();
WritableSlice<PsiElement, FunctionDescriptor> CALLABLE_REFERENCE = Slices.createSimpleSlice();
WritableSlice<JetReferenceExpression, PsiElement> LABEL_TARGET = Slices.<JetReferenceExpression, PsiElement>sliceBuilder().build();
WritableSlice<JetReferenceExpression, Collection<? extends PsiElement>> AMBIGUOUS_LABEL_TARGET =
Slices.<JetReferenceExpression, Collection<? extends PsiElement>>sliceBuilder().build();
@@ -142,14 +142,6 @@ public class MoveDeclarationsOutHelper {
element instanceof JetClassOrObject ||
element instanceof JetFunction) {
// Descriptor for local object is linked with JetObjectNameDeclaration
if (element instanceof JetObjectDeclaration) {
JetObjectDeclarationName declarationName = ((JetObjectDeclaration) element).getNameAsDeclaration();
if (declarationName != null) {
element = declarationName;
}
}
PsiReference[] refs = ReferencesSearch.search(element, scope, false).toArray(PsiReference.EMPTY_ARRAY);
if (refs.length > 0) {
PsiReference lastRef = refs[refs.length - 1];
@@ -28,7 +28,7 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
public override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
fun elementKind() = when (element) {
is JetClass -> if (element.isTrait()) "Trait" else "Class"
is JetObjectDeclaration, is JetObjectDeclarationName -> "Object"
is JetObjectDeclaration -> "Object"
is JetNamedFunction -> "Function"
is JetProperty -> "Property"
is JetTypeParameter -> "Type parameter"
@@ -58,7 +58,6 @@ import java.util.*;
public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
public static boolean canDeleteElement(@NotNull PsiElement element) {
return element instanceof JetClassOrObject
|| element instanceof JetObjectDeclarationName
|| element instanceof JetNamedFunction
|| element instanceof PsiMethod
|| element instanceof JetProperty
@@ -101,10 +100,6 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
if (element instanceof JetClassOrObject) {
return findClassOrObjectUsages(element, (JetClassOrObject) element, allElementsToDelete, result);
}
if (element instanceof JetObjectDeclarationName) {
PsiElement parent = getObjectDeclarationOrFail(element);
return findClassOrObjectUsages(element, (JetObjectDeclaration) parent, allElementsToDelete, result);
}
if (element instanceof JetNamedFunction) {
return findFunctionUsages((JetNamedFunction) element, allElementsToDelete, result);
}
@@ -136,13 +131,6 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
return getSearchInfo(element, allElementsToDelete);
}
@NotNull
private static PsiElement getObjectDeclarationOrFail(@NotNull PsiElement element) {
PsiElement parent = element.getParent();
assert parent instanceof JetObjectDeclaration;
return parent;
}
@SuppressWarnings("MethodOverridesPrivateMethodOfSuperclass")
protected static boolean isInside(@NotNull PsiElement place, @NotNull PsiElement[] ancestors) {
return isInside(place, Arrays.asList(ancestors));
@@ -866,15 +854,4 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
result.add(method.getParameterList().getParameters()[parameterIndex]);
}
}
@Nullable
@Override
public Collection<PsiElement> getAdditionalElementsToDelete(
@NotNull PsiElement element, @NotNull Collection<PsiElement> allElementsToDelete, boolean askUser
) {
if (element instanceof JetObjectDeclarationName) {
return Arrays.asList(getObjectDeclarationOrFail(element));
}
return super.getAdditionalElementsToDelete(element, allElementsToDelete, askUser);
}
}
@@ -47,10 +47,7 @@ public class SafeDeleteImportDirectiveUsageInfo extends SafeDeleteReferenceSimpl
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) declaration.getContainingFile()).getBindingContext();
DeclarationDescriptor referenceDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, importReference);
DeclarationDescriptor declarationDescriptor = declaration instanceof JetObjectDeclaration
? bindingContext.get(BindingContext.OBJECT_DECLARATION, ((JetObjectDeclaration) declaration).getNameAsDeclaration())
: bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
return referenceDescriptor == declarationDescriptor;
}
@@ -27,7 +27,9 @@ import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.asJava.LightClassUtil;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.plugin.JetPluginUtil;
public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
@@ -54,8 +56,8 @@ public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, Re
if (!JetPluginUtil.isInSource(element) || JetPluginUtil.isKtFileInGradleProjectInWrongFolder(element)) {
return;
}
if (element instanceof JetClass) {
processJetClassOrObject((JetClass) element, queryParameters);
if (element instanceof JetClassOrObject) {
processJetClassOrObject((JetClassOrObject) element, queryParameters);
}
else if (element instanceof JetNamedFunction) {
final JetNamedFunction function = (JetNamedFunction) element;
@@ -83,12 +85,6 @@ public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, Re
searchMethod(queryParameters, propertyMethods.getGetter());
searchMethod(queryParameters, propertyMethods.getSetter());
}
else if (element instanceof JetObjectDeclarationName) {
PsiElement parent = element.getParent();
if (parent instanceof JetObjectDeclaration) {
processJetClassOrObject((JetObjectDeclaration)parent, queryParameters);
}
}
}
private static void searchMethod(ReferencesSearch.SearchParameters queryParameters, PsiMethod method) {
@@ -55,7 +55,7 @@ public abstract class AbstractJetSafeDeleteTest extends LightCodeInsightFixtureT
}
public void doObjectTest(@NotNull String path) throws Exception {
doTest(path, JetObjectDeclarationName.class, false);
doTest(path, JetObjectDeclaration.class, false);
}
public void doFunctionTest(@NotNull String path) throws Exception {