Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 16-21
Link Here
|
16 |
import java.io.InputStreamReader; |
16 |
import java.io.InputStreamReader; |
17 |
import java.io.Reader; |
17 |
import java.io.Reader; |
18 |
import java.io.StringReader; |
18 |
import java.io.StringReader; |
|
|
19 |
import java.net.URISyntaxException; |
19 |
import java.net.URL; |
20 |
import java.net.URL; |
20 |
|
21 |
|
21 |
import org.osgi.framework.Bundle; |
22 |
import org.osgi.framework.Bundle; |
Lines 25-30
Link Here
|
25 |
import org.eclipse.swt.widgets.Display; |
26 |
import org.eclipse.swt.widgets.Display; |
26 |
import org.eclipse.swt.widgets.Shell; |
27 |
import org.eclipse.swt.widgets.Shell; |
27 |
|
28 |
|
|
|
29 |
import org.eclipse.core.runtime.OperationCanceledException; |
28 |
import org.eclipse.core.runtime.Platform; |
30 |
import org.eclipse.core.runtime.Platform; |
29 |
|
31 |
|
30 |
import org.eclipse.jface.action.Action; |
32 |
import org.eclipse.jface.action.Action; |
Lines 54-59
Link Here
|
54 |
|
56 |
|
55 |
import org.eclipse.ui.editors.text.EditorsUI; |
57 |
import org.eclipse.ui.editors.text.EditorsUI; |
56 |
|
58 |
|
|
|
59 |
import org.eclipse.jdt.core.IAnnotatable; |
57 |
import org.eclipse.jdt.core.IField; |
60 |
import org.eclipse.jdt.core.IField; |
58 |
import org.eclipse.jdt.core.IJavaElement; |
61 |
import org.eclipse.jdt.core.IJavaElement; |
59 |
import org.eclipse.jdt.core.IJavaProject; |
62 |
import org.eclipse.jdt.core.IJavaProject; |
Lines 63-74
Link Here
|
63 |
import org.eclipse.jdt.core.ITypeRoot; |
66 |
import org.eclipse.jdt.core.ITypeRoot; |
64 |
import org.eclipse.jdt.core.JavaCore; |
67 |
import org.eclipse.jdt.core.JavaCore; |
65 |
import org.eclipse.jdt.core.JavaModelException; |
68 |
import org.eclipse.jdt.core.JavaModelException; |
|
|
69 |
import org.eclipse.jdt.core.dom.AST; |
66 |
import org.eclipse.jdt.core.dom.ASTNode; |
70 |
import org.eclipse.jdt.core.dom.ASTNode; |
|
|
71 |
import org.eclipse.jdt.core.dom.ASTParser; |
72 |
import org.eclipse.jdt.core.dom.CharacterLiteral; |
67 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
73 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
|
74 |
import org.eclipse.jdt.core.dom.IAnnotationBinding; |
68 |
import org.eclipse.jdt.core.dom.IBinding; |
75 |
import org.eclipse.jdt.core.dom.IBinding; |
|
|
76 |
import org.eclipse.jdt.core.dom.IMemberValuePairBinding; |
77 |
import org.eclipse.jdt.core.dom.ITypeBinding; |
69 |
import org.eclipse.jdt.core.dom.IVariableBinding; |
78 |
import org.eclipse.jdt.core.dom.IVariableBinding; |
70 |
import org.eclipse.jdt.core.dom.NodeFinder; |
79 |
import org.eclipse.jdt.core.dom.NodeFinder; |
71 |
import org.eclipse.jdt.core.dom.SimpleName; |
80 |
import org.eclipse.jdt.core.dom.SimpleName; |
|
|
81 |
import org.eclipse.jdt.core.dom.StringLiteral; |
72 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
82 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
73 |
|
83 |
|
74 |
import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations; |
84 |
import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations; |
Lines 472-478
Link Here
|
472 |
* @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleInlineJavadocLink(org.eclipse.jdt.core.IJavaElement) |
482 |
* @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleInlineJavadocLink(org.eclipse.jdt.core.IJavaElement) |
473 |
*/ |
483 |
*/ |
474 |
public void handleInlineJavadocLink(IJavaElement linkTarget) { |
484 |
public void handleInlineJavadocLink(IJavaElement linkTarget) { |
475 |
JavadocBrowserInformationControlInput hoverInfo= getHoverInfo(new IJavaElement[] { linkTarget }, null, (JavadocBrowserInformationControlInput) control.getInput()); |
485 |
JavadocBrowserInformationControlInput hoverInfo= getHoverInfo(new IJavaElement[] { linkTarget }, null, null, (JavadocBrowserInformationControlInput) control.getInput()); |
476 |
if (control.hasDelayedInputChangeListener()) |
486 |
if (control.hasDelayedInputChangeListener()) |
477 |
control.notifyDelayedInputChange(hoverInfo); |
487 |
control.notifyDelayedInputChange(hoverInfo); |
478 |
else |
488 |
else |
Lines 533-560
Link Here
|
533 |
if (elements == null || elements.length == 0) |
543 |
if (elements == null || elements.length == 0) |
534 |
return null; |
544 |
return null; |
535 |
|
545 |
|
536 |
String constantValue; |
546 |
return getHoverInfo(elements, getEditorInputJavaElement(), hoverRegion, null); |
537 |
if (elements.length == 1 && elements[0].getElementType() == IJavaElement.FIELD) { |
|
|
538 |
constantValue= getConstantValue((IField) elements[0], hoverRegion); |
539 |
if (constantValue != null) |
540 |
constantValue= HTMLPrinter.convertToHTMLContent(constantValue); |
541 |
} else { |
542 |
constantValue= null; |
543 |
} |
544 |
|
545 |
return getHoverInfo(elements, constantValue, null); |
546 |
} |
547 |
} |
547 |
|
548 |
|
548 |
/** |
549 |
/** |
549 |
* Computes the hover info. |
550 |
* Computes the hover info. |
550 |
* |
551 |
* |
551 |
* @param elements the resolved elements |
552 |
* @param elements the resolved elements |
552 |
* @param constantValue a constant value iff result contains exactly 1 constant field, or <code>null</code> |
553 |
* @param editorInputElement the editor input, or <code>null</code> |
|
|
554 |
* @param hoverRegion the text range of the hovered word, or <code>null</code> |
553 |
* @param previousInput the previous input, or <code>null</code> |
555 |
* @param previousInput the previous input, or <code>null</code> |
554 |
* @return the HTML hover info for the given element(s) or <code>null</code> if no information is available |
556 |
* @return the HTML hover info for the given element(s) or <code>null</code> if no information is available |
555 |
* @since 3.4 |
557 |
* @since 3.4 |
556 |
*/ |
558 |
*/ |
557 |
private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, String constantValue, JavadocBrowserInformationControlInput previousInput) { |
559 |
private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) { |
558 |
int nResults= elements.length; |
560 |
int nResults= elements.length; |
559 |
StringBuffer buffer= new StringBuffer(); |
561 |
StringBuffer buffer= new StringBuffer(); |
560 |
boolean hasContents= false; |
562 |
boolean hasContents= false; |
Lines 569-576
Link Here
|
569 |
HTMLPrinter.startBulletList(buffer); |
571 |
HTMLPrinter.startBulletList(buffer); |
570 |
IJavaElement curr= elements[i]; |
572 |
IJavaElement curr= elements[i]; |
571 |
if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) { |
573 |
if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) { |
572 |
//FIXME: provide links |
574 |
String label= JavaElementLabels.getElementLabel(curr, getHeaderFlags(curr)); |
573 |
HTMLPrinter.addBullet(buffer, getInfoText(curr, constantValue, false)); |
575 |
String link; |
|
|
576 |
try { |
577 |
String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, curr); |
578 |
link= JavaElementLinks.createLink(uri, label); |
579 |
} catch (URISyntaxException e) { |
580 |
JavaPlugin.log(e); |
581 |
link= label; |
582 |
} |
583 |
HTMLPrinter.addBullet(buffer, link); |
574 |
hasContents= true; |
584 |
hasContents= true; |
575 |
} |
585 |
} |
576 |
HTMLPrinter.endBulletList(buffer); |
586 |
HTMLPrinter.endBulletList(buffer); |
Lines 580-587
Link Here
|
580 |
|
590 |
|
581 |
element= elements[0]; |
591 |
element= elements[0]; |
582 |
if (element instanceof IMember) { |
592 |
if (element instanceof IMember) { |
|
|
593 |
HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true)); |
594 |
buffer.append("<br>"); //$NON-NLS-1$ |
595 |
addAnnotations(buffer, element, editorInputElement, hoverRegion); |
583 |
IMember member= (IMember) element; |
596 |
IMember member= (IMember) element; |
584 |
HTMLPrinter.addSmallHeader(buffer, getInfoText(member, constantValue, true)); |
|
|
585 |
Reader reader; |
597 |
Reader reader; |
586 |
try { |
598 |
try { |
587 |
// reader= JavadocContentAccess.getHTMLContentReader(member, true, true); |
599 |
// reader= JavadocContentAccess.getHTMLContentReader(member, true, true); |
Lines 620-626
Link Here
|
620 |
hasContents= true; |
632 |
hasContents= true; |
621 |
|
633 |
|
622 |
} else if (element.getElementType() == IJavaElement.LOCAL_VARIABLE || element.getElementType() == IJavaElement.TYPE_PARAMETER) { |
634 |
} else if (element.getElementType() == IJavaElement.LOCAL_VARIABLE || element.getElementType() == IJavaElement.TYPE_PARAMETER) { |
623 |
HTMLPrinter.addSmallHeader(buffer, getInfoText(element, constantValue, true)); |
635 |
addAnnotations(buffer, element, editorInputElement, hoverRegion); |
|
|
636 |
HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true)); |
624 |
hasContents= true; |
637 |
hasContents= true; |
625 |
} |
638 |
} |
626 |
leadingImageWidth= 20; |
639 |
leadingImageWidth= 20; |
Lines 642-663
Link Here
|
642 |
return null; |
655 |
return null; |
643 |
} |
656 |
} |
644 |
|
657 |
|
645 |
private static String getInfoText(IJavaElement element, String constantValue, boolean allowImage) { |
658 |
private static String getInfoText(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion, boolean allowImage) { |
646 |
long flags; |
659 |
long flags= getHeaderFlags(element); |
647 |
switch (element.getElementType()) { |
|
|
648 |
case IJavaElement.LOCAL_VARIABLE: |
649 |
flags= LOCAL_VARIABLE_FLAGS; |
650 |
break; |
651 |
case IJavaElement.TYPE_PARAMETER: |
652 |
flags= TYPE_PARAMETER_FLAGS; |
653 |
break; |
654 |
default: |
655 |
flags= LABEL_FLAGS; |
656 |
break; |
657 |
} |
658 |
StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(element, flags)); |
660 |
StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(element, flags)); |
|
|
661 |
|
659 |
if (element.getElementType() == IJavaElement.FIELD) { |
662 |
if (element.getElementType() == IJavaElement.FIELD) { |
|
|
663 |
String constantValue= getConstantValue((IField) element, editorInputElement, hoverRegion); |
660 |
if (constantValue != null) { |
664 |
if (constantValue != null) { |
|
|
665 |
constantValue= HTMLPrinter.convertToHTMLContent(constantValue); |
661 |
IJavaProject javaProject= element.getJavaProject(); |
666 |
IJavaProject javaProject= element.getJavaProject(); |
662 |
if (JavaCore.INSERT.equals(javaProject.getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, true))) |
667 |
if (JavaCore.INSERT.equals(javaProject.getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, true))) |
663 |
label.append(' '); |
668 |
label.append(' '); |
Lines 667-672
Link Here
|
667 |
label.append(constantValue); |
672 |
label.append(constantValue); |
668 |
} |
673 |
} |
669 |
} |
674 |
} |
|
|
675 |
|
676 |
// if (element.getElementType() == IJavaElement.METHOD) { |
677 |
// IMethod method= (IMethod)element; |
678 |
// //TODO: add default value for annotation type members, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=249016 |
679 |
// } |
670 |
|
680 |
|
671 |
String imageName= null; |
681 |
String imageName= null; |
672 |
if (allowImage) { |
682 |
if (allowImage) { |
Lines 677-686
Link Here
|
677 |
} |
687 |
} |
678 |
|
688 |
|
679 |
StringBuffer buf= new StringBuffer(); |
689 |
StringBuffer buf= new StringBuffer(); |
680 |
addImageAndLabel(buf, imageName, 16, 16, 2, 2, label.toString(), 20, 2); |
690 |
addImageAndLabel(buf, element, imageName, 16, 16, label.toString(), 20, 2); |
681 |
return buf.toString(); |
691 |
return buf.toString(); |
682 |
} |
692 |
} |
683 |
|
693 |
|
|
|
694 |
private static long getHeaderFlags(IJavaElement element) { |
695 |
switch (element.getElementType()) { |
696 |
case IJavaElement.LOCAL_VARIABLE: |
697 |
return LOCAL_VARIABLE_FLAGS; |
698 |
case IJavaElement.TYPE_PARAMETER: |
699 |
return TYPE_PARAMETER_FLAGS; |
700 |
default: |
701 |
return LABEL_FLAGS; |
702 |
} |
703 |
} |
704 |
|
684 |
/* |
705 |
/* |
685 |
* @since 3.4 |
706 |
* @since 3.4 |
686 |
*/ |
707 |
*/ |
Lines 697-722
Link Here
|
697 |
* Returns the constant value for the given field. |
718 |
* Returns the constant value for the given field. |
698 |
* |
719 |
* |
699 |
* @param field the field |
720 |
* @param field the field |
700 |
* @param hoverRegion the hover region |
721 |
* @param editorInputElement the editor input element |
|
|
722 |
* @param hoverRegion the hover region in the editor |
701 |
* @return the constant value for the given field or <code>null</code> if none |
723 |
* @return the constant value for the given field or <code>null</code> if none |
702 |
* @since 3.4 |
724 |
* @since 3.4 |
703 |
*/ |
725 |
*/ |
704 |
private String getConstantValue(IField field, IRegion hoverRegion) { |
726 |
private static String getConstantValue(IField field, ITypeRoot editorInputElement, IRegion hoverRegion) { |
705 |
if (!isStaticFinal(field)) |
727 |
if (!isStaticFinal(field)) |
706 |
return null; |
728 |
return null; |
707 |
|
729 |
|
708 |
ITypeRoot typeRoot= getEditorInputJavaElement(); |
730 |
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); |
709 |
if (typeRoot == null) |
731 |
if (node == null) |
710 |
return null; |
732 |
return null; |
711 |
|
733 |
|
712 |
Object constantValue= null; |
734 |
Object constantValue= null; |
713 |
|
735 |
if (node.getNodeType() == ASTNode.SIMPLE_NAME) { |
714 |
CompilationUnit unit= SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, null); |
|
|
715 |
if (unit == null) |
716 |
return null; |
717 |
|
718 |
ASTNode node= NodeFinder.perform(unit, hoverRegion.getOffset(), hoverRegion.getLength()); |
719 |
if (node != null && node.getNodeType() == ASTNode.SIMPLE_NAME) { |
720 |
IBinding binding= ((SimpleName)node).resolveBinding(); |
736 |
IBinding binding= ((SimpleName)node).resolveBinding(); |
721 |
if (binding != null && binding.getKind() == IBinding.VARIABLE) { |
737 |
if (binding != null && binding.getKind() == IBinding.VARIABLE) { |
722 |
IVariableBinding variableBinding= (IVariableBinding)binding; |
738 |
IVariableBinding variableBinding= (IVariableBinding)binding; |
Lines 729-748
Link Here
|
729 |
return null; |
745 |
return null; |
730 |
|
746 |
|
731 |
if (constantValue instanceof String) { |
747 |
if (constantValue instanceof String) { |
732 |
StringBuffer result= new StringBuffer(); |
748 |
return getEscapedStringLiteral((String) constantValue); |
733 |
result.append('"'); |
|
|
734 |
String stringConstant= (String)constantValue; |
735 |
if (stringConstant.length() > 80) { |
736 |
result.append(stringConstant.substring(0, 80)); |
737 |
result.append(JavaElementLabels.ELLIPSIS_STRING); |
738 |
} else { |
739 |
result.append(stringConstant); |
740 |
} |
741 |
result.append('"'); |
742 |
return result.toString(); |
743 |
|
749 |
|
744 |
} else if (constantValue instanceof Character) { |
750 |
} else if (constantValue instanceof Character) { |
745 |
String constantResult= '\'' + constantValue.toString() + '\''; |
751 |
String constantResult= getEscapedCharacterLiteral(((Character) constantValue).charValue()); |
746 |
|
752 |
|
747 |
char charValue= ((Character) constantValue).charValue(); |
753 |
char charValue= ((Character) constantValue).charValue(); |
748 |
String hexString= Integer.toHexString(charValue); |
754 |
String hexString= Integer.toHexString(charValue); |
Lines 774-779
Link Here
|
774 |
} |
780 |
} |
775 |
} |
781 |
} |
776 |
|
782 |
|
|
|
783 |
private static ASTNode getHoveredASTNode(ITypeRoot editorInputElement, IRegion hoverRegion) { |
784 |
if (editorInputElement == null) |
785 |
return null; |
786 |
|
787 |
CompilationUnit unit= SharedASTProvider.getAST(editorInputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null); |
788 |
if (unit == null) |
789 |
return null; |
790 |
|
791 |
return NodeFinder.perform(unit, hoverRegion.getOffset(), hoverRegion.getLength()); |
792 |
} |
793 |
|
794 |
private static String getEscapedStringLiteral(String stringValue) { |
795 |
StringLiteral stringLiteral= AST.newAST(AST.JLS3).newStringLiteral(); |
796 |
stringLiteral.setLiteralValue(stringValue); |
797 |
String stringConstant= stringLiteral.getEscapedValue(); |
798 |
if (stringConstant.length() > 80) { |
799 |
return stringConstant.substring(0, 80) + JavaElementLabels.ELLIPSIS_STRING; |
800 |
} else { |
801 |
return stringConstant; |
802 |
} |
803 |
} |
804 |
|
805 |
private static String getEscapedCharacterLiteral(char ch) { |
806 |
CharacterLiteral characterLiteral= AST.newAST(AST.JLS3).newCharacterLiteral(); |
807 |
characterLiteral.setCharValue(ch); |
808 |
return characterLiteral.getEscapedValue(); |
809 |
} |
810 |
|
777 |
/** |
811 |
/** |
778 |
* Creates and returns a formatted message for the given |
812 |
* Creates and returns a formatted message for the given |
779 |
* constant with its hex value. |
813 |
* constant with its hex value. |
Lines 838-872
Link Here
|
838 |
return null; |
872 |
return null; |
839 |
} |
873 |
} |
840 |
|
874 |
|
841 |
public static void addImageAndLabel(StringBuffer buf, String imageName, int imageWidth, int imageHeight, int imageLeft, int imageTop, String label, int labelLeft, int labelTop) { |
875 |
public static void addImageAndLabel(StringBuffer buf, String imageSrcPath, int imageWidth, int imageHeight, String label, int labelLeft, int labelTop) { |
|
|
876 |
addImageAndLabel(buf, null, imageSrcPath, imageWidth, imageHeight, label, labelLeft, labelTop); |
877 |
} |
878 |
|
879 |
public static void addImageAndLabel(StringBuffer buf, IJavaElement element, String imageSrcPath, int imageWidth, int imageHeight, String label, int labelLeft, int labelTop) { |
880 |
buf.append("<div style='word-wrap: break-word; position: relative; "); //$NON-NLS-1$ |
881 |
|
882 |
if (imageSrcPath != null) { |
883 |
buf.append("margin-left: ").append(labelLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
884 |
buf.append("padding-top: ").append(labelTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
885 |
} |
842 |
|
886 |
|
843 |
if (imageName != null) { |
887 |
buf.append("'>"); //$NON-NLS-1$ |
844 |
StringBuffer imageStyle= new StringBuffer("position: absolute; "); //$NON-NLS-1$ |
888 |
if (imageSrcPath != null) { |
|
|
889 |
if (element != null) { |
890 |
try { |
891 |
String uri= JavaElementLinks.createURI(JavaElementLinks.OPEN_LINK_SCHEME, element); |
892 |
buf.append("<a href='").append(uri).append("'>"); //$NON-NLS-1$//$NON-NLS-2$ |
893 |
} catch (URISyntaxException e) { |
894 |
element= null; // no link |
895 |
} |
896 |
} |
897 |
StringBuffer imageStyle= new StringBuffer("border:none; position: absolute; "); //$NON-NLS-1$ |
845 |
imageStyle.append("width: ").append(imageWidth).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
898 |
imageStyle.append("width: ").append(imageWidth).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
846 |
imageStyle.append("height: ").append(imageHeight).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
899 |
imageStyle.append("height: ").append(imageHeight).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
847 |
imageStyle.append("top: ").append(imageTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
900 |
imageStyle.append("left: ").append(- labelLeft - 1).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
848 |
imageStyle.append("left: ").append(imageLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
849 |
|
901 |
|
|
|
902 |
// hack for broken transparent PNG support in IE 6, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=223900 : |
850 |
buf.append("<!--[if lte IE 6]><![if gte IE 5.5]>\n"); //$NON-NLS-1$ |
903 |
buf.append("<!--[if lte IE 6]><![if gte IE 5.5]>\n"); //$NON-NLS-1$ |
851 |
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$ |
904 |
String tooltip= JavaHoverMessages.JavadocHover_openDeclaration; |
|
|
905 |
buf.append("<span alt='").append(tooltip).append("' style=\"").append(imageStyle). //$NON-NLS-1$ //$NON-NLS-2$ |
906 |
append("filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='").append(imageSrcPath).append("')\"></span>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
852 |
buf.append("<![endif]><![endif]-->\n"); //$NON-NLS-1$ |
907 |
buf.append("<![endif]><![endif]-->\n"); //$NON-NLS-1$ |
853 |
|
908 |
|
854 |
buf.append("<!--[if !IE]>-->\n"); //$NON-NLS-1$ |
909 |
buf.append("<!--[if !IE]>-->\n"); //$NON-NLS-1$ |
855 |
buf.append("<img style='").append(imageStyle).append("' src='").append(imageName).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
910 |
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$ |
856 |
buf.append("<!--<![endif]-->\n"); //$NON-NLS-1$ |
911 |
buf.append("<!--<![endif]-->\n"); //$NON-NLS-1$ |
857 |
buf.append("<!--[if gte IE 7]>\n"); //$NON-NLS-1$ |
912 |
buf.append("<!--[if gte IE 7]>\n"); //$NON-NLS-1$ |
858 |
buf.append("<img style='").append(imageStyle).append("' src='").append(imageName).append("'/>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
913 |
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$ |
859 |
buf.append("<![endif]-->\n"); //$NON-NLS-1$ |
914 |
buf.append("<![endif]-->\n"); //$NON-NLS-1$ |
|
|
915 |
if (element != null) { |
916 |
buf.append("</a>"); //$NON-NLS-1$ |
917 |
} |
860 |
} |
918 |
} |
861 |
|
919 |
|
862 |
buf.append("<div style='word-wrap:break-word;"); //$NON-NLS-1$ |
|
|
863 |
if (imageName != null) { |
864 |
buf.append("margin-left: ").append(labelLeft).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
865 |
buf.append("margin-top: ").append(labelTop).append("px; "); //$NON-NLS-1$ //$NON-NLS-2$ |
866 |
} |
867 |
buf.append("'>"); //$NON-NLS-1$ |
868 |
buf.append(label); |
920 |
buf.append(label); |
|
|
921 |
|
869 |
buf.append("</div>"); //$NON-NLS-1$ |
922 |
buf.append("</div>"); //$NON-NLS-1$ |
870 |
} |
923 |
} |
871 |
|
924 |
|
|
|
925 |
public static void addAnnotations(StringBuffer buf, IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) { |
926 |
if (element instanceof IAnnotatable) { |
927 |
try { |
928 |
String annotationString= getAnnotations(element, editorInputElement, hoverRegion); |
929 |
if (annotationString != null) { |
930 |
buf.append("<div style='margin-bottom: 5px;'>"); //$NON-NLS-1$ |
931 |
buf.append(annotationString); |
932 |
buf.append("</div>"); //$NON-NLS-1$ |
933 |
} |
934 |
} catch (JavaModelException e) { |
935 |
// no annotations this time... |
936 |
buf.append("<br>"); //$NON-NLS-1$ |
937 |
} catch (URISyntaxException e) { |
938 |
// no annotations this time... |
939 |
buf.append("<br>"); //$NON-NLS-1$ |
940 |
} |
941 |
} |
942 |
} |
943 |
|
944 |
private static String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException { |
945 |
if (!(element instanceof IAnnotatable)) |
946 |
return null; |
947 |
|
948 |
if (((IAnnotatable)element).getAnnotations().length == 0) |
949 |
return null; |
950 |
|
951 |
IBinding binding; |
952 |
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); |
953 |
|
954 |
if (node == null) { |
955 |
ASTParser p= ASTParser.newParser(AST.JLS3); |
956 |
p.setProject(element.getJavaProject()); |
957 |
try { |
958 |
binding= p.createBindings(new IJavaElement[] { element }, null)[0]; |
959 |
} catch (OperationCanceledException e) { |
960 |
return null; |
961 |
} |
962 |
|
963 |
} else { |
964 |
if (node.getNodeType() != ASTNode.SIMPLE_NAME) |
965 |
return null; |
966 |
|
967 |
binding= ((SimpleName)node).resolveBinding(); |
968 |
} |
969 |
|
970 |
if (binding == null) |
971 |
return null; |
972 |
|
973 |
IAnnotationBinding[] annotations= binding.getAnnotations(); |
974 |
if (annotations.length == 0) |
975 |
return null; |
976 |
|
977 |
StringBuffer buf= new StringBuffer(); |
978 |
for (int i= 0; i < annotations.length; i++) { |
979 |
//TODO: skip annotations that don't have an @Documented annotation? |
980 |
addAnnotation(buf, element, annotations[i]); |
981 |
buf.append("<br>"); //$NON-NLS-1$ |
982 |
} |
983 |
|
984 |
return buf.toString(); |
985 |
} |
986 |
|
987 |
private static void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException { |
988 |
String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, annotation.getAnnotationType().getJavaElement()); |
989 |
buf.append('@'); |
990 |
addLink(buf, uri, annotation.getName()); |
991 |
|
992 |
IMemberValuePairBinding[] mvPairs= annotation.getDeclaredMemberValuePairs(); |
993 |
if (mvPairs.length > 0) { |
994 |
buf.append('('); |
995 |
for (int j= 0; j < mvPairs.length; j++) { |
996 |
if (j > 0) { |
997 |
buf.append(JavaElementLabels.COMMA_STRING); |
998 |
} |
999 |
IMemberValuePairBinding mvPair= mvPairs[j]; |
1000 |
String memberURI= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, mvPair.getMethodBinding().getJavaElement()); |
1001 |
addLink(buf, memberURI, mvPair.getName()); |
1002 |
buf.append('='); |
1003 |
addValue(buf, element, mvPair.getValue()); |
1004 |
} |
1005 |
buf.append(')'); |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
private static void addValue(StringBuffer buf, IJavaElement element, Object value) throws URISyntaxException { |
1010 |
if (value instanceof ITypeBinding) { |
1011 |
ITypeBinding typeBinding= (ITypeBinding)value; |
1012 |
IJavaElement type= typeBinding.getJavaElement(); |
1013 |
String typeLabel= JavaElementLinks.getElementLabel(type, LABEL_FLAGS, true); |
1014 |
buf.append(typeLabel).append(".class"); //$NON-NLS-1$ |
1015 |
|
1016 |
} else if (value instanceof IVariableBinding) { // only enum constants |
1017 |
IVariableBinding variableBinding= (IVariableBinding)value; |
1018 |
IJavaElement variable= variableBinding.getJavaElement(); |
1019 |
String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, variable); |
1020 |
String name= variable.getElementName(); |
1021 |
addLink(buf, uri, name); |
1022 |
|
1023 |
} else if (value instanceof IAnnotationBinding) { |
1024 |
IAnnotationBinding annotationBinding= (IAnnotationBinding)value; |
1025 |
addAnnotation(buf, element, annotationBinding); |
1026 |
|
1027 |
} else if (value instanceof String) { |
1028 |
buf.append(getEscapedStringLiteral((String)value)); |
1029 |
|
1030 |
} else if (value instanceof Character) { |
1031 |
buf.append(getEscapedCharacterLiteral(((Character)value).charValue())); |
1032 |
|
1033 |
} else if (value instanceof Object[]) { |
1034 |
Object[] values= (Object[])value; |
1035 |
buf.append('{'); |
1036 |
for (int i= 0; i < values.length; i++) { |
1037 |
if (i > 0) { |
1038 |
buf.append(JavaElementLabels.COMMA_STRING); |
1039 |
} |
1040 |
addValue(buf, element, values[i]); |
1041 |
} |
1042 |
buf.append('}'); |
1043 |
|
1044 |
} else { // primitive types (except char) or null |
1045 |
buf.append(String.valueOf(value)); |
1046 |
} |
1047 |
} |
1048 |
|
1049 |
private static StringBuffer addLink(StringBuffer buf, String uri, String label) { |
1050 |
return buf.append(JavaElementLinks.createLink(uri, label)); |
1051 |
} |
872 |
} |
1052 |
} |