]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkSuperImplementationDetector.java
9906d7465bbbf806d4f1f26230fa51998f6591ad
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / javaeditor / JavaElementHyperlinkSuperImplementationDetector.java
1 /*******************************************************************************
2  * Copyright (c) 2010, 2011 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.javaeditor;
12
13 import java.util.List;
14
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.jface.text.hyperlink.IHyperlink;
17
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.IMethod;
20 import org.eclipse.jdt.core.JavaModelException;
21
22 import org.eclipse.jdt.internal.corext.util.JdtFlags;
23
24 import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
25
26 import org.eclipse.jdt.internal.ui.JavaPlugin;
27 import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
28
29 /**
30  * Java element super implementation hyperlink detector for methods.
31  * 
32  * @since 3.7
33  */
34 public class JavaElementHyperlinkSuperImplementationDetector extends JavaElementHyperlinkDetector {
35         /*
36          * @see org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector#createHyperlink(org.eclipse.jface.text.IRegion, org.eclipse.jdt.ui.actions.SelectionDispatchAction, org.eclipse.jdt.core.IJavaElement, boolean, org.eclipse.ui.texteditor.ITextEditor)
37          * @since 3.7
38          */
39         @Override
40         protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
41                 if (element.getElementType() == IJavaElement.METHOD && SelectionConverter.canOperateOn(editor) && isOverriddenMethod((IMethod)element)) {
42                         hyperlinksCollector.add(new JavaElementSuperImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify));
43                 }
44         }
45
46         /**
47          * Indicates whether a method is overridden.
48          * 
49          * @param method the method to check
50          * @return <code>true</code> if the method is overridden, <code>false</code> otherwise
51          */
52         private boolean isOverriddenMethod(IMethod method) {
53                 try {
54                         if (JdtFlags.isPrivate(method) || JdtFlags.isStatic(method) || method.isConstructor())
55                                 return false;
56                         if (JavaElementSuperImplementationHyperlink.findSuperImplementation(method) != null)
57                                 return true;
58                 } catch (JavaModelException e) {
59                         JavaPlugin.log(e);
60                 }
61                 return false;
62         }
63 }