remove code duplicates

This commit is contained in:
Konstantin Bulenkov
2014-08-29 16:50:30 +02:00
parent e46c0a4e19
commit fc66b7c43b
8 changed files with 75 additions and 53 deletions
@@ -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) {
@@ -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);
@@ -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;
}
@@ -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;
@@ -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();
@@ -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);
}
@@ -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;
@@ -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;