diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java index d142161400c9..c7bd10cc2b39 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,11 +16,11 @@ package com.intellij.codeInsight.highlighting; import com.intellij.codeInsight.ExceptionUtil; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.Condition; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -29,11 +29,9 @@ import java.util.Collection; /** * @author yole */ -public class HighlightExceptionsHandlerFactory implements HighlightUsagesHandlerFactory { +public class HighlightExceptionsHandlerFactory extends HighlightUsagesHandlerFactoryBase { @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - PsiElement target = file.findElementAt(offset); + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { if (target instanceof PsiKeyword) { PsiElement parent = target.getParent(); if (PsiKeyword.TRY.equals(target.getText()) && parent instanceof PsiTryStatement) { diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java index 4a05420dd354..f9f19a4c26ee 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,20 +15,18 @@ */ package com.intellij.codeInsight.highlighting; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiKeyword; +import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class HighlightExitPointsHandlerFactory implements HighlightUsagesHandlerFactory { +public class HighlightExitPointsHandlerFactory extends HighlightUsagesHandlerFactoryBase { @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - PsiElement target = file.findElementAt(offset); + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { if (target instanceof PsiKeyword) { if (PsiKeyword.RETURN.equals(target.getText()) || PsiKeyword.THROW.equals(target.getText())) { return new HighlightExitPointsHandler(editor, file, target); diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java index def7501d93e5..b096aeb40a89 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,21 +15,19 @@ */ package com.intellij.codeInsight.highlighting; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.openapi.editor.Editor; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * @author Bas Leijdekkers */ -public class HighlightImportedElementsHandlerFactory implements HighlightUsagesHandlerFactory { +public class HighlightImportedElementsHandlerFactory extends HighlightUsagesHandlerFactoryBase { @Nullable @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file) { - final int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - final PsiElement target = file.findElementAt(offset); + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { if (!(target instanceof PsiKeyword) || !PsiKeyword.IMPORT.equals(target.getText())) { return null; } diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java index bc9c0a47ce6f..088a17231d33 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,18 +15,16 @@ */ package com.intellij.codeInsight.highlighting; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.openapi.editor.Editor; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class HighlightOverridingMethodsHandlerFactory implements HighlightUsagesHandlerFactory { +public class HighlightOverridingMethodsHandlerFactory extends HighlightUsagesHandlerFactoryBase { @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - final PsiElement target = file.findElementAt(offset); + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { if (target instanceof PsiKeyword && (PsiKeyword.EXTENDS.equals(target.getText()) || PsiKeyword.IMPLEMENTS.equals(target.getText()))) { PsiElement parent = target.getParent(); if (!(parent instanceof PsiReferenceList)) return null; diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java index df847437854f..4182f003e1bd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,7 +15,6 @@ */ package com.intellij.codeInsight.highlighting; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; @@ -24,15 +23,14 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLiteralExpression; import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class HighlightSuppressedWarningsFactory implements HighlightUsagesHandlerFactory { +public class HighlightSuppressedWarningsFactory extends HighlightUsagesHandlerFactoryBase { @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - final PsiElement target = file.findElementAt(offset); + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(target, PsiAnnotation.class); if (annotation != null && Comparing.strEqual(SuppressWarnings.class.getName(), annotation.getQualifiedName())) { final VirtualFile virtualFile = file.getVirtualFile(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandlerFactoryBase.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandlerFactoryBase.java new file mode 100644 index 000000000000..83c6cf35c57e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandlerFactoryBase.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2014 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.codeInsight.highlighting; + +import com.intellij.codeInsight.TargetElementUtilBase; +import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Konstantin Bulenkov + */ +public abstract class HighlightUsagesHandlerFactoryBase implements HighlightUsagesHandlerFactory { + @Nullable + @Override + public final HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file) { + int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); + PsiElement target = file.findElementAt(offset); + if (target == null) return null; + return createHighlightUsagesHandler(editor, file, target); + } + + @Nullable + public abstract HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target); +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrHighlightHandlerFactory.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrHighlightHandlerFactory.java index 811f8caec379..a25abdf311ef 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrHighlightHandlerFactory.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrHighlightHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,14 +15,14 @@ */ package org.jetbrains.plugins.groovy.findUsages; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase; -import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerFactory; +import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerFactoryBase; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; @@ -30,13 +30,9 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefini /** * @author Max Medvedev */ -public class GrHighlightHandlerFactory implements HighlightUsagesHandlerFactory { +public class GrHighlightHandlerFactory extends HighlightUsagesHandlerFactoryBase { @Override - public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - final PsiElement target = file.findElementAt(offset); - if (target == null) return null; - + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { ASTNode node = target.getNode(); if (node == null) return null; diff --git a/python/src/com/jetbrains/python/codeInsight/highlighting/PyHighlightExitPointsHandlerFactory.java b/python/src/com/jetbrains/python/codeInsight/highlighting/PyHighlightExitPointsHandlerFactory.java index d0bc9dcbc7ca..27522d6e7f53 100644 --- a/python/src/com/jetbrains/python/codeInsight/highlighting/PyHighlightExitPointsHandlerFactory.java +++ b/python/src/com/jetbrains/python/codeInsight/highlighting/PyHighlightExitPointsHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,30 +15,26 @@ */ package com.jetbrains.python.codeInsight.highlighting; -import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase; -import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerFactory; +import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerFactoryBase; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyReturnStatement; +import org.jetbrains.annotations.NotNull; /** * @author oleg */ -public class PyHighlightExitPointsHandlerFactory implements HighlightUsagesHandlerFactory { - public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) { - int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); - PsiElement target = file.findElementAt(offset); - if (target != null) { - final PyReturnStatement returnStatement = PsiTreeUtil.getParentOfType(target, PyReturnStatement.class); - if (returnStatement != null) { - final PyExpression returnExpr = returnStatement.getExpression(); - if (returnExpr == null || !PsiTreeUtil.isAncestor(returnExpr, target, false)) { - return new PyHighlightExitPointsHandler(editor, file, target); - } +public class PyHighlightExitPointsHandlerFactory extends HighlightUsagesHandlerFactoryBase { + public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { + final PyReturnStatement returnStatement = PsiTreeUtil.getParentOfType(target, PyReturnStatement.class); + if (returnStatement != null) { + final PyExpression returnExpr = returnStatement.getExpression(); + if (returnExpr == null || !PsiTreeUtil.isAncestor(returnExpr, target, false)) { + return new PyHighlightExitPointsHandler(editor, file, target); } } return null;