### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.ui
Index: ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java,v
retrieving revision 1.101
diff -u -r1.101 JavadocView.java
--- ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java 1 Dec 2009 12:20:17 -0000 1.101
+++ ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java 24 Apr 2010 22:46:20 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -76,6 +76,7 @@
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.TextUtilities;
@@ -103,12 +104,15 @@
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IOpenable;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.SourceRange;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
@@ -893,6 +897,7 @@
* @see AbstractInfoView#computeInput(Object)
*/
protected Object computeInput(Object input) {
+ //TODO: never used?
if (getControl() == null || ! (input instanceof IJavaElement))
return null;
@@ -1062,6 +1067,19 @@
}
HTMLPrinter.addSmallHeader(buffer, getInfoText(member, constantValue, true));
+
+ try {
+ ISourceRange nameRange= ((IMember)curr).getNameRange();
+ if (SourceRange.isAvailable(nameRange)) {
+ ITypeRoot typeRoot= ((IMember)curr).getTypeRoot();
+ Region hoverRegion= new Region(nameRange.getOffset(), nameRange.getLength());
+ buffer.append("
"); //$NON-NLS-1$
+ JavadocHover.addAnnotations(buffer, curr, typeRoot, hoverRegion);
+ }
+ } catch (JavaModelException e) {
+ // no annotations this time...
+ }
+
Reader reader;
try {
String content= JavadocContentAccess2.getHTMLContent(member, true);
@@ -1095,8 +1113,16 @@
if (reader != null) {
HTMLPrinter.addParagraph(buffer, reader);
}
+
} else if (curr.getElementType() == IJavaElement.LOCAL_VARIABLE || curr.getElementType() == IJavaElement.TYPE_PARAMETER) {
HTMLPrinter.addSmallHeader(buffer, getInfoText(curr, null, true));
+ if (curr instanceof ILocalVariable) {
+ ISourceRange nameRange= ((ILocalVariable) curr).getNameRange();
+ ITypeRoot typeRoot= ((IMember) curr.getParent()).getTypeRoot();
+ Region hoverRegion= new Region(nameRange.getOffset(), nameRange.getLength());
+ buffer.append("
"); //$NON-NLS-1$
+ JavadocHover.addAnnotations(buffer, curr, typeRoot, hoverRegion);
+ }
}
}
@@ -1137,7 +1163,7 @@
}
StringBuffer buf= new StringBuffer();
- JavadocHover.addImageAndLabel(buf, imageName, 16, 16, 8, 5, label.toString(), 22, 0);
+ JavadocHover.addImageAndLabel(buf, imageName, 16, 16, label.toString(), 20, 2);
return buf.toString();
}
@@ -1288,6 +1314,8 @@
return null;
VariableDeclarationFragment fieldDecl= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(constantField, ast);
+ if (fieldDecl == null)
+ return null;
Expression initializer= fieldDecl.getInitializer();
if (initializer == null)
return null;
@@ -1491,7 +1519,7 @@
* @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleExternalLink(java.net.URL, org.eclipse.swt.widgets.Display)
*/
public boolean handleExternalLink(final URL url, Display display) {
- if (fCurrent == null || !url.equals(fCurrent.getInputElement())) {
+ if (fCurrent == null || (fCurrent.getInputElement() instanceof URL && !url.toExternalForm().equals(((URL) fCurrent.getInputElement()).toExternalForm()))) {
fCurrent= new URLBrowserInput(fCurrent, url);
if (fBackAction != null) {
Index: ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java,v
retrieving revision 1.79
diff -u -r1.79 JavadocHover.java
--- ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java 18 Nov 2009 09:53:21 -0000 1.79
+++ ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java 24 Apr 2010 22:46:20 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.net.URISyntaxException;
import java.net.URL;
import org.osgi.framework.Bundle;
@@ -25,6 +26,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
@@ -54,6 +56,7 @@
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
@@ -63,12 +66,19 @@
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CharacterLiteral;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
@@ -472,7 +482,7 @@
* @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleInlineJavadocLink(org.eclipse.jdt.core.IJavaElement)
*/
public void handleInlineJavadocLink(IJavaElement linkTarget) {
- JavadocBrowserInformationControlInput hoverInfo= getHoverInfo(new IJavaElement[] { linkTarget }, null, (JavadocBrowserInformationControlInput) control.getInput());
+ JavadocBrowserInformationControlInput hoverInfo= getHoverInfo(new IJavaElement[] { linkTarget }, null, null, (JavadocBrowserInformationControlInput) control.getInput());
if (control.hasDelayedInputChangeListener())
control.notifyDelayedInputChange(hoverInfo);
else
@@ -533,28 +543,20 @@
if (elements == null || elements.length == 0)
return null;
- String constantValue;
- if (elements.length == 1 && elements[0].getElementType() == IJavaElement.FIELD) {
- constantValue= getConstantValue((IField) elements[0], hoverRegion);
- if (constantValue != null)
- constantValue= HTMLPrinter.convertToHTMLContent(constantValue);
- } else {
- constantValue= null;
- }
-
- return getHoverInfo(elements, constantValue, null);
+ return getHoverInfo(elements, getEditorInputJavaElement(), hoverRegion, null);
}
/**
* Computes the hover info.
*
* @param elements the resolved elements
- * @param constantValue a constant value iff result contains exactly 1 constant field, or null
+ * @param editorInputElement the editor input, or null
+ * @param hoverRegion the text range of the hovered word, or null
* @param previousInput the previous input, or null
* @return the HTML hover info for the given element(s) or null
if no information is available
* @since 3.4
*/
- private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, String constantValue, JavadocBrowserInformationControlInput previousInput) {
+ private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) {
int nResults= elements.length;
StringBuffer buffer= new StringBuffer();
boolean hasContents= false;
@@ -569,8 +571,16 @@
HTMLPrinter.startBulletList(buffer);
IJavaElement curr= elements[i];
if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) {
- //FIXME: provide links
- HTMLPrinter.addBullet(buffer, getInfoText(curr, constantValue, false));
+ String label= JavaElementLabels.getElementLabel(curr, getHeaderFlags(curr));
+ String link;
+ try {
+ String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, curr);
+ link= JavaElementLinks.createLink(uri, label);
+ } catch (URISyntaxException e) {
+ JavaPlugin.log(e);
+ link= label;
+ }
+ HTMLPrinter.addBullet(buffer, link);
hasContents= true;
}
HTMLPrinter.endBulletList(buffer);
@@ -580,8 +590,10 @@
element= elements[0];
if (element instanceof IMember) {
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true));
+ buffer.append("
"); //$NON-NLS-1$
+ addAnnotations(buffer, element, editorInputElement, hoverRegion);
IMember member= (IMember) element;
- HTMLPrinter.addSmallHeader(buffer, getInfoText(member, constantValue, true));
Reader reader;
try {
// reader= JavadocContentAccess.getHTMLContentReader(member, true, true);
@@ -620,7 +632,8 @@
hasContents= true;
} else if (element.getElementType() == IJavaElement.LOCAL_VARIABLE || element.getElementType() == IJavaElement.TYPE_PARAMETER) {
- HTMLPrinter.addSmallHeader(buffer, getInfoText(element, constantValue, true));
+ addAnnotations(buffer, element, editorInputElement, hoverRegion);
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true));
hasContents= true;
}
leadingImageWidth= 20;
@@ -642,22 +655,14 @@
return null;
}
- private static String getInfoText(IJavaElement element, String constantValue, boolean allowImage) {
- long flags;
- switch (element.getElementType()) {
- case IJavaElement.LOCAL_VARIABLE:
- flags= LOCAL_VARIABLE_FLAGS;
- break;
- case IJavaElement.TYPE_PARAMETER:
- flags= TYPE_PARAMETER_FLAGS;
- break;
- default:
- flags= LABEL_FLAGS;
- break;
- }
+ private static String getInfoText(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion, boolean allowImage) {
+ long flags= getHeaderFlags(element);
StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(element, flags));
+
if (element.getElementType() == IJavaElement.FIELD) {
+ String constantValue= getConstantValue((IField) element, editorInputElement, hoverRegion);
if (constantValue != null) {
+ constantValue= HTMLPrinter.convertToHTMLContent(constantValue);
IJavaProject javaProject= element.getJavaProject();
if (JavaCore.INSERT.equals(javaProject.getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, true)))
label.append(' ');
@@ -667,6 +672,11 @@
label.append(constantValue);
}
}
+
+// if (element.getElementType() == IJavaElement.METHOD) {
+// IMethod method= (IMethod)element;
+// //TODO: add default value for annotation type members, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=249016
+// }
String imageName= null;
if (allowImage) {
@@ -677,10 +687,21 @@
}
StringBuffer buf= new StringBuffer();
- addImageAndLabel(buf, imageName, 16, 16, 2, 2, label.toString(), 20, 2);
+ addImageAndLabel(buf, element, imageName, 16, 16, label.toString(), 20, 2);
return buf.toString();
}
+ private static long getHeaderFlags(IJavaElement element) {
+ switch (element.getElementType()) {
+ case IJavaElement.LOCAL_VARIABLE:
+ return LOCAL_VARIABLE_FLAGS;
+ case IJavaElement.TYPE_PARAMETER:
+ return TYPE_PARAMETER_FLAGS;
+ default:
+ return LABEL_FLAGS;
+ }
+ }
+
/*
* @since 3.4
*/
@@ -697,26 +718,21 @@
* Returns the constant value for the given field.
*
* @param field the field
- * @param hoverRegion the hover region
+ * @param editorInputElement the editor input element
+ * @param hoverRegion the hover region in the editor
* @return the constant value for the given field or null
if none
* @since 3.4
*/
- private String getConstantValue(IField field, IRegion hoverRegion) {
+ private static String getConstantValue(IField field, ITypeRoot editorInputElement, IRegion hoverRegion) {
if (!isStaticFinal(field))
return null;
- ITypeRoot typeRoot= getEditorInputJavaElement();
- if (typeRoot == null)
+ ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion);
+ if (node == null)
return null;
-
+
Object constantValue= null;
-
- CompilationUnit unit= SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
- if (unit == null)
- return null;
-
- ASTNode node= NodeFinder.perform(unit, hoverRegion.getOffset(), hoverRegion.getLength());
- if (node != null && node.getNodeType() == ASTNode.SIMPLE_NAME) {
+ if (node.getNodeType() == ASTNode.SIMPLE_NAME) {
IBinding binding= ((SimpleName)node).resolveBinding();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
IVariableBinding variableBinding= (IVariableBinding)binding;
@@ -729,20 +745,10 @@
return null;
if (constantValue instanceof String) {
- StringBuffer result= new StringBuffer();
- result.append('"');
- String stringConstant= (String)constantValue;
- if (stringConstant.length() > 80) {
- result.append(stringConstant.substring(0, 80));
- result.append(JavaElementLabels.ELLIPSIS_STRING);
- } else {
- result.append(stringConstant);
- }
- result.append('"');
- return result.toString();
+ return getEscapedStringLiteral((String) constantValue);
} else if (constantValue instanceof Character) {
- String constantResult= '\'' + constantValue.toString() + '\'';
+ String constantResult= getEscapedCharacterLiteral(((Character) constantValue).charValue());
char charValue= ((Character) constantValue).charValue();
String hexString= Integer.toHexString(charValue);
@@ -774,6 +780,34 @@
}
}
+ private static ASTNode getHoveredASTNode(ITypeRoot editorInputElement, IRegion hoverRegion) {
+ if (editorInputElement == null)
+ return null;
+
+ CompilationUnit unit= SharedASTProvider.getAST(editorInputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
+ if (unit == null)
+ return null;
+
+ return NodeFinder.perform(unit, hoverRegion.getOffset(), hoverRegion.getLength());
+ }
+
+ private static String getEscapedStringLiteral(String stringValue) {
+ StringLiteral stringLiteral= AST.newAST(AST.JLS3).newStringLiteral();
+ stringLiteral.setLiteralValue(stringValue);
+ String stringConstant= stringLiteral.getEscapedValue();
+ if (stringConstant.length() > 80) {
+ return stringConstant.substring(0, 80) + JavaElementLabels.ELLIPSIS_STRING;
+ } else {
+ return stringConstant;
+ }
+ }
+
+ private static String getEscapedCharacterLiteral(char ch) {
+ CharacterLiteral characterLiteral= AST.newAST(AST.JLS3).newCharacterLiteral();
+ characterLiteral.setCharValue(ch);
+ return characterLiteral.getEscapedValue();
+ }
+
/**
* Creates and returns a formatted message for the given
* constant with its hex value.
@@ -838,35 +872,181 @@
return null;
}
- public static void addImageAndLabel(StringBuffer buf, String imageName, int imageWidth, int imageHeight, int imageLeft, int imageTop, String label, int labelLeft, int labelTop) {
+ public static void addImageAndLabel(StringBuffer buf, String imageSrcPath, int imageWidth, int imageHeight, String label, int labelLeft, int labelTop) {
+ addImageAndLabel(buf, null, imageSrcPath, imageWidth, imageHeight, label, labelLeft, labelTop);
+ }
+
+ public static void addImageAndLabel(StringBuffer buf, IJavaElement element, String imageSrcPath, int imageWidth, int imageHeight, String label, int labelLeft, int labelTop) {
+ buf.append("
linkAllNames
is false
, don't link the name of the given element
+ *
+ * @param element the element to render
+ * @param flags the rendering flags
+ * @param linkAllNames if true
, link all names; if false
, link all names except original element's name
+ * @return the label of the Java element
+ * @since 3.6
+ */
+ public static String getElementLabel(IJavaElement element, long flags, boolean linkAllNames) {
StringBuffer buf= new StringBuffer();
if (!Strings.USE_TEXT_PROCESSOR) {
- new JavaElementLinkedLabelComposer(element, buf).appendElementLabel(element, flags);
+ new JavaElementLinkedLabelComposer(linkAllNames ? null : element, buf).appendElementLabel(element, flags);
return Strings.markJavaElementLabelLTR(buf.toString());
} else {
String label= JavaElementLabels.getElementLabel(element, flags);