From d4277c4ab3423eaafe363b796ac7d3590b673a6f Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 15 May 2017 15:50:46 +0300 Subject: [PATCH] cleanup: rename --- ...ChainsSearcher.java => ChainSearcher.java} | 87 +++++++++---------- .../{MethodsChain.java => MethodChain.java} | 30 +++---- .../MethodsChainLookupRangingHelper.java | 2 +- .../chainsSearch/SearchInitializer.java | 22 ++--- ... => MethodChainCompletionContributor.java} | 24 ++--- ...nsWeigher.java => MethodChainWeigher.java} | 2 +- .../MethodChainsCompletionTest.java | 6 +- resources/src/META-INF/IdeaPlugin.xml | 4 +- 8 files changed, 87 insertions(+), 90 deletions(-) rename java/compiler/impl/src/com/intellij/compiler/chainsSearch/{ChainsSearcher.java => ChainSearcher.java} (73%) rename java/compiler/impl/src/com/intellij/compiler/chainsSearch/{MethodsChain.java => MethodChain.java} (86%) rename java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/{MethodsChainsCompletionContributor.java => MethodChainCompletionContributor.java} (91%) rename java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/{MethodsChainsWeigher.java => MethodChainWeigher.java} (95%) diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainsSearcher.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainSearcher.java similarity index 73% rename from java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainsSearcher.java rename to java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainSearcher.java index 9aa058b7cb80..210ab0bbf82c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainsSearcher.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/ChainSearcher.java @@ -29,21 +29,18 @@ import org.jetbrains.jps.backwardRefs.SignatureData; import java.util.*; import java.util.stream.Collectors; -/** - * @author Dmitry Batkovich - */ -public class ChainsSearcher { - private static final Logger LOG = Logger.getInstance(ChainsSearcher.class); +public class ChainSearcher { + private static final Logger LOG = Logger.getInstance(ChainSearcher.class); - private ChainsSearcher() { + private ChainSearcher() { } @NotNull - public static List search(int pathMaximalLength, - ChainSearchTarget searchTarget, - int maxResultSize, - ChainCompletionContext context, - CompilerReferenceServiceEx compilerReferenceServiceEx) { + public static List search(int pathMaximalLength, + ChainSearchTarget searchTarget, + int maxResultSize, + ChainCompletionContext context, + CompilerReferenceServiceEx compilerReferenceServiceEx) { SearchInitializer initializer = createInitializer(searchTarget, compilerReferenceServiceEx, context); return search(compilerReferenceServiceEx, initializer, @@ -70,20 +67,20 @@ public class ChainsSearcher { } @NotNull - private static List search(CompilerReferenceServiceEx indexReader, - SearchInitializer initializer, - int pathMaximalLength, - int maxResultSize, - ChainCompletionContext context) { + private static List search(CompilerReferenceServiceEx indexReader, + SearchInitializer initializer, + int pathMaximalLength, + int maxResultSize, + ChainCompletionContext context) { SearchInitializer.InitResult initResult = initializer.init(Collections.emptySet()); - Map knownDistance = initResult.getChains(); + Map knownDistance = initResult.getChains(); - LinkedList> q = initResult + LinkedList> q = initResult .getVertices() .stream() .map( - signAndWeight -> new OccurrencesAware<>(MethodsChain.create(signAndWeight.getUnderlying(), signAndWeight.getOccurrences(), context), + signAndWeight -> new OccurrencesAware<>(MethodChain.create(signAndWeight.getUnderlying(), signAndWeight.getOccurrences(), context), signAndWeight.getOccurrences())) .filter(Objects::nonNull) .collect(Collectors.toCollection(LinkedList::new)); @@ -91,12 +88,12 @@ public class ChainsSearcher { ResultHolder result = new ResultHolder(); while (!q.isEmpty()) { ProgressManager.checkCanceled(); - OccurrencesAware currentVertex = q.poll(); + OccurrencesAware currentVertex = q.poll(); int currentVertexDistance = currentVertex.getOccurrences(); - MethodsChain currentChain = currentVertex.getUnderlying(); + MethodChain currentChain = currentVertex.getUnderlying(); MethodIncompleteSignature headSignature = currentChain.getHeadSignature(); - MethodsChain currentVertexMethodsChain = knownDistance.get(headSignature); - if (currentVertexDistance != currentVertexMethodsChain.getChainWeight()) { + MethodChain currentVertexMethodChain = knownDistance.get(headSignature); + if (currentVertexDistance != currentVertexMethodChain.getChainWeight()) { continue; } if (headSignature.isStatic() || context.hasQualifier(context.resolveQualifierClass(headSignature))) { @@ -113,16 +110,16 @@ public class ChainsSearcher { int occurrences = indexValue.getOccurrences(); if (vertex.isStatic() || !vertex.getOwner().equals(targetQName)) { int vertexDistance = Math.min(currentVertexDistance, occurrences); - MethodsChain knownVertexMethodsChain = knownDistance.get(vertex); - if ((knownVertexMethodsChain == null || knownVertexMethodsChain.getChainWeight() < vertexDistance)) { + MethodChain knownVertexMethodChain = knownDistance.get(vertex); + if ((knownVertexMethodChain == null || knownVertexMethodChain.getChainWeight() < vertexDistance)) { if (currentSignatures.isEmpty() || currentSignatures.last().getOccurrences() < vertexDistance) { - if (currentVertexMethodsChain.size() < pathMaximalLength - 1) { - MethodsChain newBestMethodsChain = - currentVertexMethodsChain.continuation(indexValue.getUnderlying(), vertexDistance, context); - if (newBestMethodsChain != null) { + if (currentVertexMethodChain.size() < pathMaximalLength - 1) { + MethodChain newBestMethodChain = + currentVertexMethodChain.continuation(indexValue.getUnderlying(), vertexDistance, context); + if (newBestMethodChain != null) { currentSignatures .add(new OccurrencesAware<>(indexValue.getUnderlying(), vertexDistance)); - knownDistance.put(vertex, newBestMethodsChain); + knownDistance.put(vertex, newBestMethodChain); } } } @@ -141,7 +138,7 @@ public class ChainsSearcher { boolean stopChain = sign.getUnderlying().isStatic() || context.hasQualifier(context.resolveQualifierClass(sign.getUnderlying())); if (stopChain) { updated = true; - MethodsChain continuation = currentChain.continuation(sign.getUnderlying(), sign.getOccurrences(), context); + MethodChain continuation = currentChain.continuation(sign.getUnderlying(), sign.getOccurrences(), context); if (continuation != null) { result.add(continuation); } @@ -149,10 +146,10 @@ public class ChainsSearcher { } else { updated = true; - MethodsChain methodsChain = + MethodChain methodChain = currentChain.continuation(sign.getUnderlying(), sign.getOccurrences(), context); - if (methodsChain != null) { - q.addFirst(new OccurrencesAware<>(methodsChain, sign.getOccurrences())); + if (methodChain != null) { + q.addFirst(new OccurrencesAware<>(methodChain, sign.getOccurrences())); continue; } } @@ -173,19 +170,19 @@ public class ChainsSearcher { return result.getResult(); } - private static MethodsChain createChainFromFirstElement(MethodsChain chain, PsiClass newQualifierClass) { + private static MethodChain createChainFromFirstElement(MethodChain chain, PsiClass newQualifierClass) { //TODO - return new MethodsChain(newQualifierClass, Collections.singletonList(chain.getFirst()), null, chain.getChainWeight()); + return new MethodChain(newQualifierClass, Collections.singletonList(chain.getFirst()), null, chain.getChainWeight()); } private static class ResultHolder { - private final List myResult; + private final List myResult; private ResultHolder() { myResult = new ArrayList<>(); } - public void add(MethodsChain newChain) { + public void add(MethodChain newChain) { if (myResult.isEmpty()) { myResult.add(newChain); return; @@ -193,9 +190,9 @@ public class ChainsSearcher { boolean doAdd = true; Stack indexesToRemove = new Stack<>(); for (int i = 0; i < myResult.size(); i++) { - MethodsChain chain = myResult.get(i); + MethodChain chain = myResult.get(i); // - MethodsChain.CompareResult r = MethodsChain.compare(chain, newChain); + MethodChain.CompareResult r = MethodChain.compare(chain, newChain); switch (r) { case LEFT_CONTAINS_RIGHT: indexesToRemove.add(i); @@ -216,11 +213,11 @@ public class ChainsSearcher { } } - public List getRawResult() { + public List getRawResult() { return myResult; } - public List getResult() { + public List getResult() { return findSimilar(reduceChainsSize(myResult)); } @@ -228,7 +225,7 @@ public class ChainsSearcher { return myResult.size(); } - private static List reduceChainsSize(List chains) { + private static List reduceChainsSize(List chains) { return ContainerUtil.map(chains, chain -> { Iterator chainIterator = chain.iterator(); if (!chainIterator.hasNext()) { @@ -268,9 +265,9 @@ public class ChainsSearcher { }); } - private static List findSimilar(List chains) { + private static List findSimilar(List chains) { ResultHolder resultHolder = new ResultHolder(); - for (MethodsChain chain : chains) { + for (MethodChain chain : chains) { resultHolder.add(chain); } return resultHolder.getRawResult(); diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChain.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodChain.java similarity index 86% rename from java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChain.java rename to java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodChain.java index d57f234166f8..000a0fc81886 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChain.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodChain.java @@ -30,16 +30,16 @@ import java.util.stream.Collectors; import static com.intellij.util.containers.ContainerUtil.newArrayList; import static com.intellij.util.containers.ContainerUtil.reverse; -public class MethodsChain { +public class MethodChain { private final List myRevertedPath; private final MethodIncompleteSignature mySignature; private final int myWeight; private final PsiClass myQualifierClass; @Nullable - public static MethodsChain create(@NotNull MethodIncompleteSignature signature, - int weight, - @NotNull ChainCompletionContext context) { + public static MethodChain create(@NotNull MethodIncompleteSignature signature, + int weight, + @NotNull ChainCompletionContext context) { PsiClass qualifier = context.resolveQualifierClass(signature); if (qualifier == null || (!signature.isStatic() && InheritanceUtil.isInheritorOrSelf(context.getTarget().getTargetClass(), qualifier, true))) { return null; @@ -55,13 +55,13 @@ public class MethodsChain { return null; } classes.add(contextClass); - return new MethodsChain(qualifier, Collections.singletonList(methods), signature, weight); + return new MethodChain(qualifier, Collections.singletonList(methods), signature, weight); } - public MethodsChain(@NotNull PsiClass qualifierClass, - @NotNull List revertedPath, - MethodIncompleteSignature signature, - int weight) { + public MethodChain(@NotNull PsiClass qualifierClass, + @NotNull List revertedPath, + MethodIncompleteSignature signature, + int weight) { myQualifierClass = qualifierClass; myRevertedPath = revertedPath; mySignature = signature; @@ -99,16 +99,16 @@ public class MethodsChain { } - public MethodsChain continuation(@NotNull MethodIncompleteSignature signature, - int weight, - @NotNull ChainCompletionContext context) { - MethodsChain head = create(signature, weight, context); + public MethodChain continuation(@NotNull MethodIncompleteSignature signature, + int weight, + @NotNull ChainCompletionContext context) { + MethodChain head = create(signature, weight, context); if (head == null) return null; ArrayList newRevertedPath = newArrayList(); newRevertedPath.addAll(myRevertedPath); newRevertedPath.add(head.getPath().get(0)); - return new MethodsChain(head.getQualifierClass(), newRevertedPath, head.getHeadSignature(), weight); + return new MethodChain(head.getQualifierClass(), newRevertedPath, head.getHeadSignature(), weight); } @Override @@ -117,7 +117,7 @@ public class MethodsChain { } @SuppressWarnings("ConstantConditions") - public static CompareResult compare(@NotNull MethodsChain left, @NotNull MethodsChain right) { + public static CompareResult compare(@NotNull MethodChain left, @NotNull MethodChain right) { if (left.size() == 0) { return CompareResult.RIGHT_CONTAINS_LEFT; } diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChainLookupRangingHelper.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChainLookupRangingHelper.java index 3c5e90ce7ef5..215951144358 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChainLookupRangingHelper.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/MethodsChainLookupRangingHelper.java @@ -45,7 +45,7 @@ import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING; public class MethodsChainLookupRangingHelper { @Nullable - public static LookupElement chainToWeightableLookupElement(MethodsChain chain, + public static LookupElement chainToWeightableLookupElement(MethodChain chain, ChainCompletionContext context) { int chainSize = chain.size(); assert chainSize != 0; diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/SearchInitializer.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/SearchInitializer.java index d2f1dc1d2aad..69ece93e473b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/SearchInitializer.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/SearchInitializer.java @@ -22,7 +22,7 @@ import com.intellij.openapi.util.Pair; import java.util.*; public class SearchInitializer { - private final LinkedHashMap> myChains; + private final LinkedHashMap> myChains; private final ChainCompletionContext myContext; public SearchInitializer(SortedSet> indexValues, @@ -51,9 +51,9 @@ public class SearchInitializer { private boolean add(OccurrencesAware indexValue) { MethodIncompleteSignature methodInvocation = indexValue.getUnderlying(); int occurrences = indexValue.getOccurrences(); - MethodsChain methodsChain = MethodsChain.create(indexValue.getUnderlying(), occurrences, myContext); - if (methodsChain != null) { - myChains.put(methodInvocation, Pair.create(methodsChain, occurrences)); + MethodChain methodChain = MethodChain.create(indexValue.getUnderlying(), occurrences, myContext); + if (methodChain != null) { + myChains.put(methodInvocation, Pair.create(methodChain, occurrences)); return true; } return false; @@ -62,14 +62,14 @@ public class SearchInitializer { public InitResult init(Set excludedEdgeNames) { int size = myChains.size(); List> initedVertexes = new ArrayList<>(size); - LinkedHashMap initedChains = + LinkedHashMap initedChains = new LinkedHashMap<>(size); - for (Map.Entry> entry : myChains.entrySet()) { + for (Map.Entry> entry : myChains.entrySet()) { MethodIncompleteSignature signature = entry.getKey(); if (!excludedEdgeNames.contains(signature.getName())) { initedVertexes.add(new OccurrencesAware<>(entry.getKey(), entry.getValue().getSecond())); - MethodsChain methodsChain = entry.getValue().getFirst(); - initedChains.put(signature, methodsChain); + MethodChain methodChain = entry.getValue().getFirst(); + initedChains.put(signature, methodChain); } } return new InitResult(initedVertexes, initedChains); @@ -77,10 +77,10 @@ public class SearchInitializer { public static class InitResult { private final List> myVertexes; - private final LinkedHashMap myChains; + private final LinkedHashMap myChains; private InitResult(List> vertexes, - LinkedHashMap chains) { + LinkedHashMap chains) { myVertexes = vertexes; myChains = chains; } @@ -89,7 +89,7 @@ public class SearchInitializer { return myVertexes; } - public LinkedHashMap getChains() { + public LinkedHashMap getChains() { return myChains; } } diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsCompletionContributor.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainCompletionContributor.java similarity index 91% rename from java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsCompletionContributor.java rename to java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainCompletionContributor.java index 6ac377c260cd..ec8f94a63863 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsCompletionContributor.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainCompletionContributor.java @@ -21,8 +21,8 @@ import com.intellij.compiler.CompilerReferenceService; import com.intellij.compiler.backwardRefs.CompilerReferenceServiceEx; import com.intellij.compiler.backwardRefs.ReferenceIndexUnavailableException; import com.intellij.compiler.chainsSearch.ChainSearchMagicConstants; -import com.intellij.compiler.chainsSearch.ChainsSearcher; -import com.intellij.compiler.chainsSearch.MethodsChain; +import com.intellij.compiler.chainsSearch.ChainSearcher; +import com.intellij.compiler.chainsSearch.MethodChain; import com.intellij.compiler.chainsSearch.MethodsChainLookupRangingHelper; import com.intellij.compiler.chainsSearch.context.ChainCompletionContext; import com.intellij.compiler.chainsSearch.context.ChainSearchTarget; @@ -50,14 +50,14 @@ import static com.intellij.patterns.PsiJavaPatterns.psiElement; /** * @author Dmitry Batkovich */ -public class MethodsChainsCompletionContributor extends CompletionContributor { +public class MethodChainCompletionContributor extends CompletionContributor { public static final String REGISTRY_KEY = "compiler.ref.chain.search"; - private static final Logger LOG = Logger.getInstance(MethodsChainsCompletionContributor.class); + private static final Logger LOG = Logger.getInstance(MethodChainCompletionContributor.class); private static final boolean UNIT_TEST_MODE = ApplicationManager.getApplication().isUnitTestMode(); public static final CompletionType COMPLETION_TYPE = UNIT_TEST_MODE ? CompletionType.BASIC : CompletionType.SMART; @SuppressWarnings("unchecked") - public MethodsChainsCompletionContributor() { + public MethodChainCompletionContributor() { ElementPattern pattern = or(patternForMethodCallParameter(), patternForVariableAssignment()); extend(COMPLETION_TYPE, pattern, new CompletionProvider() { @Override @@ -100,13 +100,13 @@ public class MethodsChainsCompletionContributor extends CompletionContributor { private static List searchForLookups(ChainCompletionContext context) { CompilerReferenceServiceEx methodsUsageIndexReader = (CompilerReferenceServiceEx)CompilerReferenceService.getInstance(context.getProject()); ChainSearchTarget target = context.getTarget(); - List searchResult = - ChainsSearcher.search(ChainSearchMagicConstants.MAX_CHAIN_SIZE, - target, - ChainSearchMagicConstants.MAX_SEARCH_RESULT_SIZE, - context, - methodsUsageIndexReader); - int maxWeight = searchResult.stream().mapToInt(MethodsChain::getChainWeight).max().orElse(0); + List searchResult = + ChainSearcher.search(ChainSearchMagicConstants.MAX_CHAIN_SIZE, + target, + ChainSearchMagicConstants.MAX_SEARCH_RESULT_SIZE, + context, + methodsUsageIndexReader); + int maxWeight = searchResult.stream().mapToInt(MethodChain::getChainWeight).max().orElse(0); return searchResult .stream() diff --git a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsWeigher.java b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainWeigher.java similarity index 95% rename from java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsWeigher.java rename to java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainWeigher.java index 8ffaa183585e..ebac9ebbaf90 100644 --- a/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodsChainsWeigher.java +++ b/java/compiler/impl/src/com/intellij/compiler/chainsSearch/completion/MethodChainWeigher.java @@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull; /** * @author Dmitry Batkovich */ -public class MethodsChainsWeigher extends CompletionWeigher { +public class MethodChainWeigher extends CompletionWeigher { @Override public Comparable weigh(@NotNull final LookupElement element, @NotNull final CompletionLocation location) { if (element instanceof WeightableChainLookupElement) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/MethodChainsCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/MethodChainsCompletionTest.java index d3116ae43c73..ec89eaa7296f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/MethodChainsCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/MethodChainsCompletionTest.java @@ -19,7 +19,7 @@ import com.intellij.JavaTestUtil; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.compiler.chainsSearch.ChainRelevance; -import com.intellij.compiler.chainsSearch.completion.MethodsChainsCompletionContributor; +import com.intellij.compiler.chainsSearch.completion.MethodChainCompletionContributor; import com.intellij.compiler.chainsSearch.completion.lookup.ChainCompletionMethodCallLookupElement; import com.intellij.compiler.chainsSearch.completion.lookup.WeightableChainLookupElement; import com.intellij.ide.util.PropertiesComponent; @@ -43,13 +43,13 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest { protected void setUp() throws Exception { super.setUp(); installCompiler(); - Registry.get(MethodsChainsCompletionContributor.REGISTRY_KEY).setValue(true); + Registry.get(MethodChainCompletionContributor.REGISTRY_KEY).setValue(true); } @Override protected void tearDown() throws Exception { try { - Registry.get(MethodsChainsCompletionContributor.REGISTRY_KEY).setValue(false); + Registry.get(MethodChainCompletionContributor.REGISTRY_KEY).setValue(false); } finally { super.tearDown(); } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 4860738578b4..4daf83bdab23 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -1880,9 +1880,9 @@ + implementationClass="com.intellij.compiler.chainsSearch.completion.MethodChainCompletionContributor"/> + implementationClass="com.intellij.compiler.chainsSearch.completion.MethodChainWeigher"/>