From 109e2ae4aa591b570aad42d27dbcb1dcedfeabca Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 31 May 2017 15:39:22 +0200 Subject: [PATCH] SSR: remove unnecessary methods from matching handlers --- .../LightTopLevelMatchingHandler.java | 8 +---- .../matcher/handlers/MatchingHandler.java | 14 ++------- .../matcher/handlers/SkippingHandler.java | 29 ++----------------- .../handlers/TopLevelMatchingHandler.java | 8 +---- 4 files changed, 6 insertions(+), 53 deletions(-) diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LightTopLevelMatchingHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LightTopLevelMatchingHandler.java index d79805695d4d..45d3bfc84896 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LightTopLevelMatchingHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LightTopLevelMatchingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -42,12 +42,6 @@ public final class LightTopLevelMatchingHandler extends MatchingHandler implemen return myDelegate.matchSequentially(nodes, nodes2, context); } - @Override - public boolean match(final PsiElement patternNode, - final PsiElement matchedNode, final int start, final int end, final MatchContext context) { - return myDelegate.match(patternNode, matchedNode, start, end, context); - } - @Override public boolean isMatchSequentiallySucceeded(final NodeIterator nodes2) { return true; diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java index 01fc89353e6f..da79ea1cc18d 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java @@ -44,16 +44,6 @@ public abstract class MatchingHandler { this.filter = filter; } - /** - * Matches given handler node against given value. - * @param matchedNode for matching - * @param context of the matching - * @return true if matching was successful and false otherwise - */ - public boolean match(PsiElement patternNode, PsiElement matchedNode, int start, int end, MatchContext context) { - return match(patternNode,matchedNode,context); - } - /** * Matches given handler node against given value. * @param matchedNode for matching @@ -160,8 +150,8 @@ public abstract class MatchingHandler { // We do not reset certain handlers because they are also bound to higher level nodes // e.g. Identifier handler in name is also bound to PsiMethod if (pattern.isToResetHandler(element)) { - MatchingHandler handler = pattern.getHandlerSimple(element); - if (handler instanceof SubstitutionHandler) { + final MatchingHandler handler = pattern.getHandlerSimple(element); + if (handler != null) { handler.reset(); } } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SkippingHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SkippingHandler.java index d1a6661f4cf0..adfc26c1af49 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SkippingHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SkippingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -45,7 +45,7 @@ public class SkippingHandler extends MatchingHandler implements DelegatingHandle /*if (patternNode != null && matchedNode != null && patternNode.getClass() == matchedNode.getClass()) { //return myDelegate.match(patternNode, matchedNode, matchContext); }*/ - PsiElement newPatternNode = skipNodeIfNeccessary(patternNode); + final PsiElement newPatternNode = skipNodeIfNeccessary(patternNode); matchedNode = skipNodeIfNeccessary(matchedNode); if (newPatternNode != patternNode) { @@ -69,36 +69,11 @@ public class SkippingHandler extends MatchingHandler implements DelegatingHandle return myDelegate.matchSequentially(nodes, nodes2, context); } - @Override - public boolean match(PsiElement patternNode, - PsiElement matchedNode, - final int start, - final int end, - final MatchContext context) { - if (patternNode == null || matchedNode == null || patternNode.getClass() == matchedNode.getClass()) { - return myDelegate.match(patternNode, matchedNode, start, end, context); - } - - PsiElement newPatternNode = skipNodeIfNeccessary(patternNode); - matchedNode = skipNodeIfNeccessary(matchedNode); - - if (newPatternNode != patternNode) { - return context.getPattern().getHandler(newPatternNode).match(newPatternNode, matchedNode, start, end, context); - } - - return myDelegate.match(patternNode, matchedNode, start, end, context); - } - @Override protected boolean isMatchSequentiallySucceeded(final NodeIterator nodes2) { return myDelegate.isMatchSequentiallySucceeded(nodes2); } - @Override - public boolean shouldAdvanceTheMatchFor(PsiElement patternElement, PsiElement matchedElement) { - return true; - } - @Override public MatchingHandler getDelegate() { return myDelegate; diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/TopLevelMatchingHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/TopLevelMatchingHandler.java index 5dcc5661820d..7095d72fb660 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/TopLevelMatchingHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/TopLevelMatchingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -81,12 +81,6 @@ public final class TopLevelMatchingHandler extends MatchingHandler implements De return delegate.matchSequentially(nodes, nodes2, context); } - @Override - public boolean match(final PsiElement patternNode, - final PsiElement matchedNode, final int start, final int end, final MatchContext context) { - return match(patternNode, matchedNode, context); - } - @Override public boolean isMatchSequentiallySucceeded(final NodeIterator nodes2) { return true;