Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 166009 Details for
Bug 236850
[misc] Show Java Annotations in the Javadoc hover and view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix
236850_patch.txt (text/plain), 30.30 KB, created by
Markus Keller
on 2010-04-24 18:46:53 EDT
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Markus Keller
Created:
2010-04-24 18:46:53 EDT
Size:
30.30 KB
patch
obsolete
>### 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("<br>"); //$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("<br>"); //$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 <code>null</code> >+ * @param editorInputElement the editor input, or <code>null</code> >+ * @param hoverRegion the text range of the hovered word, or <code>null</code> > * @param previousInput the previous input, or <code>null</code> > * @return the HTML hover info for the given element(s) or <code>null</code> 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("<br>"); //$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 <code>null</code> 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("<div style='word-wrap: break-word; position: relative; "); //$NON-NLS-1$ >+ >+ if (imageSrcPath != null) { >+ buf.append("margin-left: ").append(labelLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >+ buf.append("padding-top: ").append(labelTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >+ } > >- if (imageName != null) { >- StringBuffer imageStyle= new StringBuffer("position: absolute; "); //$NON-NLS-1$ >+ buf.append("'>"); //$NON-NLS-1$ >+ if (imageSrcPath != null) { >+ if (element != null) { >+ try { >+ String uri= JavaElementLinks.createURI(JavaElementLinks.OPEN_LINK_SCHEME, element); >+ buf.append("<a href='").append(uri).append("'>"); //$NON-NLS-1$//$NON-NLS-2$ >+ } catch (URISyntaxException e) { >+ element= null; // no link >+ } >+ } >+ StringBuffer imageStyle= new StringBuffer("border:none; position: absolute; "); //$NON-NLS-1$ > imageStyle.append("width: ").append(imageWidth).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ > imageStyle.append("height: ").append(imageHeight).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >- imageStyle.append("top: ").append(imageTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >- imageStyle.append("left: ").append(imageLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >+ imageStyle.append("left: ").append(- labelLeft - 1).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ > >+ // hack for broken transparent PNG support in IE 6, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=223900 : > buf.append("<!--[if lte IE 6]><![if gte IE 5.5]>\n"); //$NON-NLS-1$ >- buf.append("<span style=\"").append(imageStyle).append("filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='").append(imageName).append("')\"></span>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ String tooltip= JavaHoverMessages.JavadocHover_openDeclaration; >+ buf.append("<span alt='").append(tooltip).append("' style=\"").append(imageStyle). //$NON-NLS-1$ //$NON-NLS-2$ >+ append("filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='").append(imageSrcPath).append("')\"></span>\n"); //$NON-NLS-1$ //$NON-NLS-2$ > buf.append("<![endif]><![endif]-->\n"); //$NON-NLS-1$ > > buf.append("<!--[if !IE]>-->\n"); //$NON-NLS-1$ >- buf.append("<img style='").append(imageStyle).append("' src='").append(imageName).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ buf.append("<img alt='").append(tooltip).append("' style='").append(imageStyle).append("' src='").append(imageSrcPath).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ > buf.append("<!--<![endif]-->\n"); //$NON-NLS-1$ > buf.append("<!--[if gte IE 7]>\n"); //$NON-NLS-1$ >- buf.append("<img style='").append(imageStyle).append("' src='").append(imageName).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ buf.append("<img alt='").append(tooltip).append("' style='").append(imageStyle).append("' src='").append(imageSrcPath).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ > buf.append("<![endif]-->\n"); //$NON-NLS-1$ >+ if (element != null) { >+ buf.append("</a>"); //$NON-NLS-1$ >+ } > } >- >- buf.append("<div style='word-wrap:break-word;"); //$NON-NLS-1$ >- if (imageName != null) { >- buf.append("margin-left: ").append(labelLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >- buf.append("margin-top: ").append(labelTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- buf.append("'>"); //$NON-NLS-1$ >+ > buf.append(label); >+ > buf.append("</div>"); //$NON-NLS-1$ > } > >+ public static void addAnnotations(StringBuffer buf, IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) { >+ if (element instanceof IAnnotatable) { >+ try { >+ String annotationString= getAnnotations(element, editorInputElement, hoverRegion); >+ if (annotationString != null) { >+ buf.append("<div style='margin-bottom: 5px;'>"); //$NON-NLS-1$ >+ buf.append(annotationString); >+ buf.append("</div>"); //$NON-NLS-1$ >+ } >+ } catch (JavaModelException e) { >+ // no annotations this time... >+ buf.append("<br>"); //$NON-NLS-1$ >+ } catch (URISyntaxException e) { >+ // no annotations this time... >+ buf.append("<br>"); //$NON-NLS-1$ >+ } >+ } >+ } >+ >+ private static String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException { >+ if (!(element instanceof IAnnotatable)) >+ return null; >+ >+ if (((IAnnotatable)element).getAnnotations().length == 0) >+ return null; >+ >+ IBinding binding; >+ ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); >+ >+ if (node == null) { >+ ASTParser p= ASTParser.newParser(AST.JLS3); >+ p.setProject(element.getJavaProject()); >+ try { >+ binding= p.createBindings(new IJavaElement[] { element }, null)[0]; >+ } catch (OperationCanceledException e) { >+ return null; >+ } >+ >+ } else { >+ if (node.getNodeType() != ASTNode.SIMPLE_NAME) >+ return null; >+ >+ binding= ((SimpleName)node).resolveBinding(); >+ } >+ >+ if (binding == null) >+ return null; >+ >+ IAnnotationBinding[] annotations= binding.getAnnotations(); >+ if (annotations.length == 0) >+ return null; >+ >+ StringBuffer buf= new StringBuffer(); >+ for (int i= 0; i < annotations.length; i++) { >+ //TODO: skip annotations that don't have an @Documented annotation? >+ addAnnotation(buf, element, annotations[i]); >+ buf.append("<br>"); //$NON-NLS-1$ >+ } >+ >+ return buf.toString(); >+ } >+ >+ private static void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException { >+ String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, annotation.getAnnotationType().getJavaElement()); >+ buf.append('@'); >+ addLink(buf, uri, annotation.getName()); >+ >+ IMemberValuePairBinding[] mvPairs= annotation.getDeclaredMemberValuePairs(); >+ if (mvPairs.length > 0) { >+ buf.append('('); >+ for (int j= 0; j < mvPairs.length; j++) { >+ if (j > 0) { >+ buf.append(JavaElementLabels.COMMA_STRING); >+ } >+ IMemberValuePairBinding mvPair= mvPairs[j]; >+ String memberURI= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, mvPair.getMethodBinding().getJavaElement()); >+ addLink(buf, memberURI, mvPair.getName()); >+ buf.append('='); >+ addValue(buf, element, mvPair.getValue()); >+ } >+ buf.append(')'); >+ } >+ } >+ >+ private static void addValue(StringBuffer buf, IJavaElement element, Object value) throws URISyntaxException { >+ if (value instanceof ITypeBinding) { >+ ITypeBinding typeBinding= (ITypeBinding)value; >+ IJavaElement type= typeBinding.getJavaElement(); >+ String typeLabel= JavaElementLinks.getElementLabel(type, LABEL_FLAGS, true); >+ buf.append(typeLabel).append(".class"); //$NON-NLS-1$ >+ >+ } else if (value instanceof IVariableBinding) { // only enum constants >+ IVariableBinding variableBinding= (IVariableBinding)value; >+ IJavaElement variable= variableBinding.getJavaElement(); >+ String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, variable); >+ String name= variable.getElementName(); >+ addLink(buf, uri, name); >+ >+ } else if (value instanceof IAnnotationBinding) { >+ IAnnotationBinding annotationBinding= (IAnnotationBinding)value; >+ addAnnotation(buf, element, annotationBinding); >+ >+ } else if (value instanceof String) { >+ buf.append(getEscapedStringLiteral((String)value)); >+ >+ } else if (value instanceof Character) { >+ buf.append(getEscapedCharacterLiteral(((Character)value).charValue())); >+ >+ } else if (value instanceof Object[]) { >+ Object[] values= (Object[])value; >+ buf.append('{'); >+ for (int i= 0; i < values.length; i++) { >+ if (i > 0) { >+ buf.append(JavaElementLabels.COMMA_STRING); >+ } >+ addValue(buf, element, values[i]); >+ } >+ buf.append('}'); >+ >+ } else { // primitive types (except char) or null >+ buf.append(String.valueOf(value)); >+ } >+ } >+ >+ private static StringBuffer addLink(StringBuffer buf, String uri, String label) { >+ return buf.append(JavaElementLinks.createLink(uri, label)); >+ } > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java,v >retrieving revision 1.12 >diff -u -r1.12 JavaElementLinks.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java 24 Mar 2010 09:21:20 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java 24 Apr 2010 22:46:20 -0000 >@@ -24,6 +24,7 @@ > > import org.eclipse.core.runtime.IProgressMonitor; > >+import org.eclipse.jdt.core.IAnnotation; > import org.eclipse.jdt.core.IField; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.ILocalVariable; >@@ -103,7 +104,7 @@ > > public String getElementName(IJavaElement element) { > String elementName= element.getElementName(); >- if (fElement.equals(element)) { // linking to the member itself would be a no-op >+ if (element.equals(fElement)) { // linking to the member itself would be a no-op > return elementName; > } > if (elementName.length() == 0) { // anonymous >@@ -111,17 +112,13 @@ > } > try { > String uri= createURI(JAVADOC_SCHEME, element); >- return createLink(uri, elementName); >+ return createHeaderLink(uri, elementName); > } catch (URISyntaxException e) { > JavaPlugin.log(e); > return elementName; > } > } > >- private String createLink(String uri, String elementName) { >- return "<a class='header' href='" + uri + ("'>" + elementName + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >- } >- > protected String getGT() { > return ">"; //$NON-NLS-1$ > } >@@ -134,7 +131,7 @@ > String typeName= super.getSimpleTypeName(enclosingElement, typeSig); > try { > String uri= createURI(JAVADOC_SCHEME, enclosingElement, typeName, null, null); >- return createLink(uri, typeName); >+ return createHeaderLink(uri, typeName); > } catch (URISyntaxException e) { > JavaPlugin.log(e); > return typeName; >@@ -319,7 +316,10 @@ > JavaPlugin.log(e); > } > } >- >+ if (element instanceof IAnnotation) { >+ element= element.getParent(); >+ } >+ > if (element instanceof ILocalVariable) { > element= element.getAncestor(IJavaElement.TYPE); > } else if (element instanceof ITypeParameter) { >@@ -459,8 +459,33 @@ > } > > /** >+ * Creates a link with the given URI and label text. >+ * >+ * @param uri the URI >+ * @param label the label >+ * @return the HTML link >+ * @since 3.6 >+ */ >+ public static String createLink(String uri, String label) { >+ return "<a href='" + uri + "'>" + label + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+ >+ /** >+ * Creates a header link with the given URI and label text. >+ * >+ * @param uri the URI >+ * @param label the label >+ * @return the HTML link >+ * @since 3.6 >+ */ >+ public static String createHeaderLink(String uri, String label) { >+ return "<a class='header' href='" + uri + "'>" + label + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+ >+ /** > * Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}. >- * Referenced element names in the label (except the given element's name) are rendered as Javadoc links. >+ * Referenced element names in the label (except the given element's name) are rendered as >+ * header links. > * > * @param element the element to render > * @param flags the rendering flags >@@ -468,10 +493,25 @@ > * @since 3.5 > */ > public static String getElementLabel(IJavaElement element, long flags) { >+ return getElementLabel(element, flags, false); >+ } >+ >+ /** >+ * Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}. >+ * Referenced element names in the label are rendered as header links. >+ * If <code>linkAllNames</code> is <code>false</code>, don't link the name of the given element >+ * >+ * @param element the element to render >+ * @param flags the rendering flags >+ * @param linkAllNames if <code>true</code>, link all names; if <code>false</code>, 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);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 236850
:
114538
|
114539
| 166009