summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-07-31 09:01:54 (EDT)
committerMarkus Keller2012-07-31 09:11:00 (EDT)
commitb198b5165af44f7ec251dd8ccae68e0ff1509635 (patch)
tree61dbaa16cfdeba0b1ccc9e454a3fc88edef16fb4
parentc8d6496dcd3aea6859a6c6a2970fcec2d57c212c (diff)
downloadeclipse.jdt.ui-b198b5165af44f7ec251dd8ccae68e0ff1509635.zip
eclipse.jdt.ui-b198b5165af44f7ec251dd8ccae68e0ff1509635.tar.gz
eclipse.jdt.ui-b198b5165af44f7ec251dd8ccae68e0ff1509635.tar.bz2
Bug 384543: [hovering] NPE computing a bracket hoverv20120731-131100I20120801-1800
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java20
2 files changed, 13 insertions, 11 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
index ab2bf0c..f794d33 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
@@ -33,10 +33,10 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover;
import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
import org.eclipse.jdt.internal.ui.javaeditor.WorkingCopyManager;
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
@@ -169,7 +169,7 @@ public abstract class AbstractJavaEditorTextHover implements IJavaEditorTextHove
protected ITypeRoot getEditorInputJavaElement() {
IEditorPart editor= getEditor();
if (editor != null)
- return JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
+ return EditorUtility.getEditorInputJavaElement(editor, false);
return null;
}
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java
index 2f7a8dd..4703af9 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java
@@ -87,13 +87,13 @@ public class JavaSourceHover extends AbstractJavaEditorTextHover {
@Deprecated
public String getHoverInfo(ITextViewer textViewer, IRegion region) {
IJavaElement[] result= getJavaElementsAt(textViewer, region);
- ITypeRoot editorInput= getEditorInputJavaElement();
fUpwardShiftInLines= 0;
fBracketHoverStatus= null;
- if (result == null || result.length == 0)
- return getBracketHoverInfo(textViewer, region, editorInput);
+ if (result == null || result.length == 0) {
+ return getBracketHoverInfo(textViewer, region);
+ }
if (result.length > 1)
return null;
@@ -103,7 +103,7 @@ public class JavaSourceHover extends AbstractJavaEditorTextHover {
try {
String source= ((ISourceReference) curr).getSource();
- String[] sourceLines= getTrimmedSource(source, editorInput);
+ String[] sourceLines= getTrimmedSource(source, curr);
if (sourceLines == null)
return null;
@@ -118,10 +118,12 @@ public class JavaSourceHover extends AbstractJavaEditorTextHover {
return null;
}
- private String getBracketHoverInfo(final ITextViewer textViewer, IRegion region, ITypeRoot editorInput) {
+ private String getBracketHoverInfo(final ITextViewer textViewer, IRegion region) {
IEditorPart editor= getEditor();
- if (!(editor instanceof JavaEditor))
+ ITypeRoot editorInput= getEditorInputJavaElement();
+ if (!(editor instanceof JavaEditor) || editorInput == null) {
return null;
+ }
int offset= region.getOffset();
IDocument document= textViewer.getDocument();
@@ -242,15 +244,15 @@ public class JavaSourceHover extends AbstractJavaEditorTextHover {
* Returns the trimmed source lines.
*
* @param source the source string, could be <code>null</code>
- * @param editorInput the editor input
+ * @param javaElement the java element
* @return the trimmed source lines or <code>null</code>
*/
- private String[] getTrimmedSource(String source, ITypeRoot editorInput) {
+ private String[] getTrimmedSource(String source, IJavaElement javaElement) {
if (source == null)
return null;
source= removeLeadingComments(source);
String[] sourceLines= Strings.convertIntoLines(source);
- Strings.trimIndentation(sourceLines, editorInput.getJavaProject());
+ Strings.trimIndentation(sourceLines, javaElement.getJavaProject());
return sourceLines;
}