From 40b9daec87412cd1a7b874c13c32ff6500c6544c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 3 May 2013 20:27:31 +0200 Subject: [PATCH] Dead code dropped --- .../src/com/intellij/extapi/psi/StubPath.java | 72 --------- .../intellij/extapi/psi/StubPathBuilder.java | 147 ------------------ 2 files changed, 219 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/extapi/psi/StubPath.java delete mode 100644 platform/lang-impl/src/com/intellij/extapi/psi/StubPathBuilder.java diff --git a/platform/lang-impl/src/com/intellij/extapi/psi/StubPath.java b/platform/lang-impl/src/com/intellij/extapi/psi/StubPath.java deleted file mode 100644 index 0ebd2584561d..000000000000 --- a/platform/lang-impl/src/com/intellij/extapi/psi/StubPath.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2009 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. - */ - -/* - * @author max - */ -package com.intellij.extapi.psi; - -import com.intellij.psi.tree.IElementType; - -public class StubPath { - private final StubPath myParentPath; - private final String myId; - private final IElementType myType; - - - public StubPath(final StubPath parentPath, final String id, final IElementType type) { - myParentPath = parentPath; - myId = id; - myType = type; - } - - public StubPath getParentPath() { - return myParentPath; - } - - - public String getId() { - return myId; - } - - public IElementType getType() { - return myType; - } - - public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof StubPath)) return false; - - final StubPath stubPath = (StubPath)o; - - if (!myId.equals(stubPath.myId)) return false; - if (myParentPath != null ? !myParentPath.equals(stubPath.myParentPath) : stubPath.myParentPath != null) return false; - if (!myType.equals(stubPath.myType)) return false; - - return true; - } - - public int hashCode() { - int result = (myParentPath != null ? myParentPath.hashCode() : 0); - result = 31 * result + myId.hashCode(); - result = 31 * result + myType.hashCode(); - return result; - } - - public String toString() { - return (myParentPath != null ? myParentPath.toString() : "") + "::(" + myType.toString() + ":" + myId + ")"; - } -} diff --git a/platform/lang-impl/src/com/intellij/extapi/psi/StubPathBuilder.java b/platform/lang-impl/src/com/intellij/extapi/psi/StubPathBuilder.java deleted file mode 100644 index e2a74294e319..000000000000 --- a/platform/lang-impl/src/com/intellij/extapi/psi/StubPathBuilder.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2000-2009 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. - */ - -/* - * @author max - */ -package com.intellij.extapi.psi; - -import com.intellij.lang.ASTNode; -import com.intellij.openapi.util.Pair; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.StubBasedPsiElement; -import com.intellij.psi.impl.source.PsiFileImpl; -import com.intellij.psi.stubs.*; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class StubPathBuilder { - private StubPathBuilder() { - } - - public static StubPath build(StubBasedPsiElement psi) { - if (psi instanceof PsiFile) { - return null; - } - - final StubElement liveStub = psi.getStub(); - if (liveStub != null) { - return build(liveStub); - } - - return buildForPsi(psi, ((PsiFileImpl)psi.getContainingFile()).calcStubTree()).getFirst(); - } - - - public static StubPath build(StubElement stub) { - if (stub instanceof PsiFileStub || stub == null) { - return null; - } - - final IStubElementType type = stub.getStubType(); - return new StubPath(build(stub.getParentStub()), type.getId(stub), type); - } - - private static Pair buildForPsi(PsiElement psi, StubTree tree) { - if (psi instanceof PsiFile) { - return new Pair(null, tree.getRoot()); - } - - if (psi instanceof StubBasedPsiElement) { - final IStubElementType type = ((StubBasedPsiElement)psi).getElementType(); - if (type.shouldCreateStub(psi.getNode())) { - final Pair parentPair = buildForPsi(psi.getParent(), tree); - - final StubElement parentStub = parentPair.getSecond(); - final List childrenStubs = parentStub.getChildrenStubs(); - for (StubElement childStub : childrenStubs) { - if (childStub.getPsi() == psi) { - final IStubElementType type1 = childStub.getStubType(); - return new Pair(new StubPath(parentPair.getFirst(), type1.getId(childStub), type1), childStub); - } - } - - return new Pair(null, null); - } - } - - return buildForPsi(psi.getParent(), tree); - } - - @Nullable - public static PsiElement resolve(PsiFile file, StubPath path) { - PsiFileImpl fileImpl = (PsiFileImpl)file; - StubTree tree = fileImpl.getStubTree(); - - boolean foreign = (tree == null); - if (foreign) { - tree = fileImpl.calcStubTree(); - } - - StubElement stub = resolveStub(tree, path); - - if (foreign) { - final PsiElement cachedPsi = ((StubBase)stub).getCachedPsi(); - if (cachedPsi != null) return cachedPsi; - - final ASTNode ast = fileImpl.findTreeForStub(tree, stub); - return ast != null ? ast.getPsi() : null; - } - else { - return stub != null ? stub.getPsi() : null; - } - } - - @Nullable - public static StubElement resolveStub(StubTree tree, StubPath path) { - if (path == null) { - return tree.getRoot(); - } - - StubElement parentStub = resolveStub(tree, path.getParentPath()); - if (parentStub == null) { - return null; - } - - final String id = path.getId(); - final IStubElementType type = (IStubElementType)path.getType(); - final List children = parentStub.getChildrenStubs(); - - if (id.startsWith("#")) { - int count = Integer.parseInt(id.substring(1)); - - for (StubElement child : children) { - if (child.getStubType() == type) { - count--; - if (count == 0) { - return child; - } - } - } - return null; - } - - for (StubElement child : children) { - if (child.getStubType() == type && id.equals(type.getId(child))) { - return child; - } - } - - return null; - } -} \ No newline at end of file