diff --git a/plugin_ide.debug/src-lang/melnorme/lang/ide/debug/ui/DelegatingDebugTextHover.java b/plugin_ide.debug/src-lang/melnorme/lang/ide/debug/ui/DelegatingDebugTextHover.java index 6c0ef8589..bc8fe7eaa 100644 --- a/plugin_ide.debug/src-lang/melnorme/lang/ide/debug/ui/DelegatingDebugTextHover.java +++ b/plugin_ide.debug/src-lang/melnorme/lang/ide/debug/ui/DelegatingDebugTextHover.java @@ -20,14 +20,12 @@ */ //BM: adapted to ILangEditorTextHover // TODO: try to find a way to restrict the hover to relevant launches only? -public class DelegatingDebugTextHover implements ILangEditorTextHover, ITextHoverExtension, ITextHoverExtension2 { +public class DelegatingDebugTextHover +implements ILangEditorTextHover, ITextHoverExtension, ITextHoverExtension2 { private IEditorPart fEditor; private ICEditorTextHover fDelegate; - /* - * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int) - */ @Override public IRegion getHoverRegion(ITextViewer viewer, int offset) { fDelegate = getDelegate(); @@ -37,9 +35,6 @@ public IRegion getHoverRegion(ITextViewer viewer, int offset) { return null; } - /* - * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - */ @Override @SuppressWarnings("deprecation") public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { @@ -50,9 +45,6 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { return null; } - /* - * @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - */ @Override @SuppressWarnings("deprecation") public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { @@ -67,14 +59,6 @@ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { return null; } - @Override - public Object getHoverInfo2_do(ITextViewer textViewer, IRegion hoverRegion) { - return getHoverInfo2(textViewer, hoverRegion); - } - - /* - * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator() - */ @Override public IInformationControlCreator getHoverControlCreator() { if (fDelegate instanceof ITextHoverExtension) { @@ -83,9 +67,6 @@ public IInformationControlCreator getHoverControlCreator() { return null; } - /* - * @see org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover#setEditor(org.eclipse.ui.IEditorPart) - */ @Override public final void setEditor(IEditorPart editor) { fEditor = editor; diff --git a/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationIterator.java b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationIterator.java new file mode 100644 index 000000000..8627ac215 --- /dev/null +++ b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/javaeditor/JavaAnnotationIterator.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package _org.eclipse.jdt.internal.ui.javaeditor; + +import java.util.Iterator; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.core.resources.IMarker; + +import org.eclipse.jface.text.source.Annotation; + +import org.eclipse.ui.texteditor.MarkerAnnotation; + + +/** + * Filters problems based on their types. + */ +public class JavaAnnotationIterator implements Iterator { + + private Iterator fIterator; + private Annotation fNext; + private boolean fReturnAllAnnotations; + + + /** + * Returns a new JavaAnnotationIterator. + * @param parent the parent iterator to iterate over annotations + * @param returnAllAnnotations whether to return all annotations or just problem annotations + */ + public JavaAnnotationIterator(Iterator parent, boolean returnAllAnnotations) { + fReturnAllAnnotations= returnAllAnnotations; + fIterator= parent; + skip(); + } + + private void skip() { + while (fIterator.hasNext()) { + Annotation next= fIterator.next(); + + if (next.isMarkedDeleted()) + continue; + + if (fReturnAllAnnotations || /*next instanceof IJavaAnnotation ||*/ isProblemMarkerAnnotation(next)) { + fNext= next; + return; + } + } + fNext= null; + } + + private static boolean isProblemMarkerAnnotation(Annotation annotation) { + if (!(annotation instanceof MarkerAnnotation)) + return false; + try { + return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM)); + } catch (CoreException e) { + return false; + } + } + + @Override + public boolean hasNext() { + return fNext != null; + } + + @Override + public Annotation next() { + try { + return fNext; + } finally { + skip(); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } +} diff --git a/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractAnnotationHover.java b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractAnnotationHover.java new file mode 100644 index 000000000..2219a14c6 --- /dev/null +++ b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractAnnotationHover.java @@ -0,0 +1,803 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package _org.eclipse.jdt.internal.ui.text.java.hover; + +import java.util.Iterator; + +import melnorme.lang.ide.ui.LangUIPlugin; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.ITextFileBufferManager; +import org.eclipse.core.filebuffers.LocationKind; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.AbstractInformationControl; +import org.eclipse.jface.text.AbstractReusableInformationControlCreator; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; +import org.eclipse.jface.text.IInformationControlExtension2; +import org.eclipse.jface.text.IInformationControlExtension4; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHoverExtension2; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension2; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; + +import _org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationIterator; + + +/** + * Abstract super class for annotation hovers. + * + * @since 3.0 + */ +public abstract class AbstractAnnotationHover extends AbstractJavaEditorTextHover { + + /** + * An annotation info contains information about an {@link Annotation} + * It's used as input for the {@link AbstractAnnotationHover.AnnotationInformationControl} + * + * @since 3.4 + */ + protected static class AnnotationInfo { + public final Annotation annotation; + public final Position position; + public final ITextViewer viewer; + + public AnnotationInfo(Annotation annotation, Position position, ITextViewer textViewer) { + this.annotation= annotation; + this.position= position; + this.viewer= textViewer; + } + + /** + * Create completion proposals which can resolve the given annotation at + * the given position. Returns an empty array if no such proposals exist. + * + * @return the proposals or an empty array + */ + public ICompletionProposal[] getCompletionProposals() { + return new ICompletionProposal[0]; + } + + /** + * Adds actions to the given toolbar. + * + * @param manager the toolbar manager to add actions to + * @param infoControl the information control + */ + public void fillToolBar(ToolBarManager manager, IInformationControl infoControl) { +// ConfigureAnnotationsAction configureAnnotationsAction= new ConfigureAnnotationsAction(annotation, infoControl); +// manager.add(configureAnnotationsAction); + } + } + + /** + * The annotation information control shows informations about a given + * {@link AbstractAnnotationHover.AnnotationInfo}. It can also show a toolbar + * and a list of {@link ICompletionProposal}s. + * + * @since 3.4 + */ + private static class AnnotationInformationControl extends AbstractInformationControl implements IInformationControlExtension2 { + + private final DefaultMarkerAnnotationAccess fMarkerAnnotationAccess; + private Control fFocusControl; + private AnnotationInfo fInput; + private Composite fParent; + + public AnnotationInformationControl(Shell parentShell, String statusFieldText) { + super(parentShell, statusFieldText); + + fMarkerAnnotationAccess= new DefaultMarkerAnnotationAccess(); + create(); + } + + public AnnotationInformationControl(Shell parentShell, ToolBarManager toolBarManager) { + super(parentShell, toolBarManager); + + fMarkerAnnotationAccess= new DefaultMarkerAnnotationAccess(); + create(); + } + + /* + * @see org.eclipse.jface.text.IInformationControl#setInformation(java.lang.String) + */ + @Override + public void setInformation(String information) { + //replaced by IInformationControlExtension2#setInput + } + + /* + * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) + */ + @Override + public void setInput(Object input) { + Assert.isLegal(input instanceof AnnotationInfo); + fInput= (AnnotationInfo)input; + disposeDeferredCreatedContent(); + deferredCreateContent(); + } + + /* + * @see org.eclipse.jface.text.IInformationControlExtension#hasContents() + */ + @Override + public boolean hasContents() { + return fInput != null; + } + + private AnnotationInfo getAnnotationInfo() { + return fInput; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover.AbstractInformationControl#setFocus() + */ + @Override + public void setFocus() { + super.setFocus(); + if (fFocusControl != null) + fFocusControl.setFocus(); + } + + /* + * @see org.eclipse.jface.text.AbstractInformationControl#setVisible(boolean) + */ + @Override + public final void setVisible(boolean visible) { + if (!visible) + disposeDeferredCreatedContent(); + super.setVisible(visible); + } + + protected void disposeDeferredCreatedContent() { + Control[] children= fParent.getChildren(); + for (int i= 0; i < children.length; i++) { + children[i].dispose(); + } + ToolBarManager toolBarManager= getToolBarManager(); + if (toolBarManager != null) + toolBarManager.removeAll(); + } + + /* + * @see org.eclipse.jface.text.AbstractInformationControl#createContent(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createContent(Composite parent) { + fParent= parent; + GridLayout layout= new GridLayout(1, false); + layout.verticalSpacing= 0; + layout.marginWidth= 0; + layout.marginHeight= 0; + fParent.setLayout(layout); + } + + /* + * @see org.eclipse.jface.text.AbstractInformationControl#computeSizeHint() + */ + @Override + public Point computeSizeHint() { + Point preferedSize= getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + + Point constrains= getSizeConstraints(); + if (constrains == null) + return preferedSize; + + int trimWidth= getShell().computeTrim(0, 0, 0, 0).width; + Point constrainedSize= getShell().computeSize(constrains.x - trimWidth, SWT.DEFAULT, true); + + int width= Math.min(preferedSize.x, constrainedSize.x); + int height= Math.max(preferedSize.y, constrainedSize.y); + + return new Point(width, height); + } + + /** + * Fills the toolbar actions, if a toolbar is available. This + * is called after the input has been set. + */ + protected void fillToolbar() { + ToolBarManager toolBarManager= getToolBarManager(); + if (toolBarManager == null) + return; + fInput.fillToolBar(toolBarManager, this); + toolBarManager.update(true); + } + + /** + * Create content of the hover. This is called after + * the input has been set. + */ + protected void deferredCreateContent() { + fillToolbar(); + + createAnnotationInformation(fParent, getAnnotationInfo().annotation); + setColorAndFont(fParent, fParent.getForeground(), fParent.getBackground(), JFaceResources.getDialogFont()); + +// ICompletionProposal[] proposals= getAnnotationInfo().getCompletionProposals(); +// if (proposals.length > 0) +// createCompletionProposalsControl(fParent, proposals); + + fParent.layout(true); + } + + private void setColorAndFont(Control control, Color foreground, Color background, Font font) { + control.setForeground(foreground); + control.setBackground(background); + control.setFont(font); + + if (control instanceof Composite) { + Control[] children= ((Composite) control).getChildren(); + for (int i= 0; i < children.length; i++) { + setColorAndFont(children[i], foreground, background, font); + } + } + } + + private void createAnnotationInformation(Composite parent, final Annotation annotation) { + Composite composite= new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + GridLayout layout= new GridLayout(2, false); + layout.marginHeight= 2; + layout.marginWidth= 2; + layout.horizontalSpacing= 0; + composite.setLayout(layout); + + final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); + GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); + gridData.widthHint= 17; + gridData.heightHint= 16; + canvas.setLayoutData(gridData); + canvas.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + e.gc.setFont(null); + fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); + } + }); + + StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); + GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); + text.setLayoutData(data); + String annotationText= annotation.getText(); + if (annotationText != null) + text.setText(annotationText); + } + +// private void createCompletionProposalsControl(Composite parent, ICompletionProposal[] proposals) { +// Composite composite= new Composite(parent, SWT.NONE); +// composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); +// GridLayout layout2= new GridLayout(1, false); +// layout2.marginHeight= 0; +// layout2.marginWidth= 0; +// layout2.verticalSpacing= 2; +// composite.setLayout(layout2); +// +// Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); +// GridData gridData= new GridData(SWT.FILL, SWT.CENTER, true, false); +// separator.setLayoutData(gridData); +// +// Label quickFixLabel= new Label(composite, SWT.NONE); +// GridData layoutData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false); +// layoutData.horizontalIndent= 4; +// quickFixLabel.setLayoutData(layoutData); +// String text; +// if (proposals.length == 1) { +// text= JavaHoverMessages.AbstractAnnotationHover_message_singleQuickFix; +// } else { +// text= Messages.format(JavaHoverMessages.AbstractAnnotationHover_message_multipleQuickFix, new Object[] { String.valueOf(proposals.length) }); +// } +// quickFixLabel.setText(text); +// +// setColorAndFont(composite, parent.getForeground(), parent.getBackground(), JFaceResources.getDialogFont()); +// createCompletionProposalsList(composite, proposals); +// } +// +// private void createCompletionProposalsList(Composite parent, ICompletionProposal[] proposals) { +// final ScrolledComposite scrolledComposite= new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); +// GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true); +// scrolledComposite.setLayoutData(gridData); +// scrolledComposite.setExpandVertical(false); +// scrolledComposite.setExpandHorizontal(false); +// +// Composite composite= new Composite(scrolledComposite, SWT.NONE); +// composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); +// GridLayout layout= new GridLayout(2, false); +// layout.marginLeft= 5; +// layout.verticalSpacing= 2; +// composite.setLayout(layout); +// +// List list= new ArrayList(); +// for (int i= 0; i < proposals.length; i++) { +// list.add(createCompletionProposalLink(composite, proposals[i], 1));// Original link for single fix, hence pass 1 for count +// +// if (proposals[i] instanceof FixCorrectionProposal) { +// FixCorrectionProposal proposal= (FixCorrectionProposal)proposals[i]; +// int count= proposal.computeNumberOfFixesForCleanUp(proposal.getCleanUp()); +// if (count > 1) { +// list.add(createCompletionProposalLink(composite, proposals[i], count)); +// } +// } +// } +// final Link[] links= list.toArray(new Link[list.size()]); +// +// scrolledComposite.setContent(composite); +// setColorAndFont(scrolledComposite, parent.getForeground(), parent.getBackground(), JFaceResources.getDialogFont()); +// +// Point contentSize= composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); +// composite.setSize(contentSize); +// +// Point constraints= getSizeConstraints(); +// if (constraints != null && contentSize.x < constraints.x) { +// ScrollBar horizontalBar= scrolledComposite.getHorizontalBar(); +// +// int scrollBarHeight; +// if (horizontalBar == null) { +// Point scrollSize= scrolledComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT); +// scrollBarHeight= scrollSize.y - contentSize.y; +// } else { +// scrollBarHeight= horizontalBar.getSize().y; +// } +// gridData.heightHint= contentSize.y - scrollBarHeight; +// } +// +// fFocusControl= links[0]; +// for (int i= 0; i < links.length; i++) { +// final int index= i; +// final Link link= links[index]; +// link.addKeyListener(new KeyListener() { +// @Override +// public void keyPressed(KeyEvent e) { +// switch (e.keyCode) { +// case SWT.ARROW_DOWN: +// if (index + 1 < links.length) { +// links[index + 1].setFocus(); +// } +// break; +// case SWT.ARROW_UP: +// if (index > 0) { +// links[index - 1].setFocus(); +// } +// break; +// default: +// break; +// } +// } +// +// @Override +// public void keyReleased(KeyEvent e) { +// } +// }); +// +// link.addFocusListener(new FocusListener() { +// @Override +// public void focusGained(FocusEvent e) { +// int currentPosition= scrolledComposite.getOrigin().y; +// int hight= scrolledComposite.getSize().y; +// int linkPosition= link.getLocation().y; +// +// if (linkPosition < currentPosition) { +// if (linkPosition < 10) +// linkPosition= 0; +// +// scrolledComposite.setOrigin(0, linkPosition); +// } else if (linkPosition + 20 > currentPosition + hight) { +// scrolledComposite.setOrigin(0, linkPosition - hight + link.getSize().y); +// } +// } +// +// @Override +// public void focusLost(FocusEvent e) { +// } +// }); +// } +// } +// +// private Link createCompletionProposalLink(Composite parent, final ICompletionProposal proposal, int count) { +// final boolean isMultiFix= count > 1; +// if (isMultiFix) { +// new Label(parent, SWT.NONE); // spacer to fill image cell +// parent= new Composite(parent, SWT.NONE); // indented composite for multi-fix +// GridLayout layout= new GridLayout(2, false); +// layout.marginWidth= 0; +// layout.marginHeight= 0; +// parent.setLayout(layout); +// } +// +// Label proposalImage= new Label(parent, SWT.NONE); +// proposalImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); +// Image image= isMultiFix ? JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MULTI_FIX) : proposal.getImage(); +// if (image != null) { +// proposalImage.setImage(image); +// +// proposalImage.addMouseListener(new MouseListener() { +// +// @Override +// public void mouseDoubleClick(MouseEvent e) { +// } +// +// @Override +// public void mouseDown(MouseEvent e) { +// } +// +// @Override +// public void mouseUp(MouseEvent e) { +// if (e.button == 1) { +// apply(proposal, fInput.viewer, fInput.position.offset, isMultiFix); +// } +// } +// +// }); +// } +// +// Link proposalLink= new Link(parent, SWT.NONE); +// GridData layoutData= new GridData(SWT.FILL, SWT.CENTER, true, false); +// String linkText; +// if (isMultiFix) { +// linkText= Messages.format(JavaHoverMessages.AbstractAnnotationHover_multifix_variable_description, new Integer(count)); +// } else { +// linkText= proposal.getDisplayString(); +// } +// proposalLink.setText("" + linkText + ""); //$NON-NLS-1$ //$NON-NLS-2$ +// proposalLink.setLayoutData(layoutData); +// proposalLink.addSelectionListener(new SelectionAdapter() { +// /* +// * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) +// */ +// @Override +// public void widgetSelected(SelectionEvent e) { +// apply(proposal, fInput.viewer, fInput.position.offset, isMultiFix); +// } +// }); +// return proposalLink; +// } +// +// protected void apply(ICompletionProposal p, ITextViewer viewer, int offset, boolean isMultiFix) { +// //Focus needs to be in the text viewer, otherwise linked mode does not work +// dispose(); +// +// IRewriteTarget target= null; +// try { +// IDocument document= viewer.getDocument(); +// +// if (viewer instanceof ITextViewerExtension) { +// ITextViewerExtension extension= (ITextViewerExtension) viewer; +// target= extension.getRewriteTarget(); +// } +// +// if (target != null) +// target.beginCompoundChange(); +// +// if (p instanceof ICompletionProposalExtension2) { +// ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p; +// e.apply(viewer, (char) 0, isMultiFix ? SWT.CONTROL : SWT.NONE, offset); +// } else if (p instanceof ICompletionProposalExtension) { +// ICompletionProposalExtension e= (ICompletionProposalExtension) p; +// e.apply(document, (char) 0, offset); +// } else { +// p.apply(document); +// } +// +// Point selection= p.getSelection(document); +// if (selection != null) { +// viewer.setSelectedRange(selection.x, selection.y); +// viewer.revealRange(selection.x, selection.y); +// } +// } finally { +// if (target != null) +// target.endCompoundChange(); +// } +// } + } + + /** + * Presenter control creator. + * + * @since 3.4 + */ + private static final class PresenterControlCreator extends AbstractReusableInformationControlCreator { + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell) + */ + @Override + public IInformationControl doCreateInformationControl(Shell parent) { + return new AnnotationInformationControl(parent, new ToolBarManager(SWT.FLAT)); + } + } + + + /** + * Hover control creator. + * + * @since 3.4 + */ + private static final class HoverControlCreator extends AbstractReusableInformationControlCreator { + private final IInformationControlCreator fPresenterControlCreator; + + public HoverControlCreator(IInformationControlCreator presenterControlCreator) { + fPresenterControlCreator= presenterControlCreator; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell) + */ + @Override + public IInformationControl doCreateInformationControl(Shell parent) { + return new AnnotationInformationControl(parent, EditorsUI.getTooltipAffordanceString()) { + /* + * @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator() + */ + @Override + public IInformationControlCreator getInformationPresenterControlCreator() { + return fPresenterControlCreator; + } + }; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#canReuse(org.eclipse.jface.text.IInformationControl) + */ + @Override + public boolean canReuse(IInformationControl control) { + if (!super.canReuse(control)) + return false; + + if (control instanceof IInformationControlExtension4) + ((IInformationControlExtension4) control).setStatusText(EditorsUI.getTooltipAffordanceString()); + + return true; + } + } + +// /** +// * Action to configure the annotation preferences. +// * +// * @since 3.4 +// */ +// private static final class ConfigureAnnotationsAction extends Action { +// +// private final Annotation fAnnotation; +// private final IInformationControl fInfoControl; +// +// public ConfigureAnnotationsAction(Annotation annotation, IInformationControl infoControl) { +// super(); +// fAnnotation= annotation; +// fInfoControl= infoControl; +// setImageDescriptor(JavaPluginImages.DESC_ELCL_CONFIGURE_ANNOTATIONS); +// setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CONFIGURE_ANNOTATIONS); +// setToolTipText(JavaHoverMessages.AbstractAnnotationHover_action_configureAnnotationPreferences); +// } +// +// /* +// * @see org.eclipse.jface.action.Action#run() +// */ +// @Override +// public void run() { +// Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); +// +// Object data= null; +// AnnotationPreference preference= getAnnotationPreference(fAnnotation); +// if (preference != null) +// data= preference.getPreferenceLabel(); +// +// fInfoControl.dispose(); //FIXME: should have protocol to hide, rather than dispose +// PreferencesUtil.createPreferenceDialogOn(shell, "org.eclipse.ui.editors.preferencePages.Annotations", null, data).open(); //$NON-NLS-1$ +// } +// } + + private final IPreferenceStore fStore= LangUIPlugin.getDefault().getCombinedPreferenceStore(); + private final DefaultMarkerAnnotationAccess fAnnotationAccess= new DefaultMarkerAnnotationAccess(); + private final boolean fAllAnnotations; + + /** + * The hover control creator. + * + * @since 3.4 + */ + private IInformationControlCreator fHoverControlCreator; + /** + * The presentation control creator. + * + * @since 3.4 + */ + private IInformationControlCreator fPresenterControlCreator; + + + public AbstractAnnotationHover(boolean allAnnotations) { + fAllAnnotations= allAnnotations; + } + + /** + * @deprecated As of 3.4, replaced by {@link ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion)} + * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + */ + @Override + public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { + return null; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + * @since 3.4 + */ + @Override + public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { + IPath path; + IAnnotationModel model; + if (textViewer instanceof ISourceViewer) { + path= null; + model= ((ISourceViewer)textViewer).getAnnotationModel(); + } else { + // Get annotation model from file buffer manager + path= getEditorInputPath(); + model= getAnnotationModel(path); + } + if (model == null) + return null; + + try { + Iterator parent; + if (model instanceof IAnnotationModelExtension2) + parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true); + else + parent= model.getAnnotationIterator(); + Iterator e= new JavaAnnotationIterator(parent, fAllAnnotations); + + int layer= -1; + Annotation annotation= null; + Position position= null; + while (e.hasNext()) { + Annotation a= e.next(); + + AnnotationPreference preference= getAnnotationPreference(a); + if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey())))) + continue; + + Position p= model.getPosition(a); + + int l= fAnnotationAccess.getLayer(a); + + if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { + String msg= a.getText(); + if (msg != null && msg.trim().length() > 0) { + layer= l; + annotation= a; + position= p; + } + } + } + if (layer > -1) + return createAnnotationInfo(annotation, position, textViewer); + + } finally { + try { + if (path != null) { + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); + manager.disconnect(path, LocationKind.NORMALIZE, null); + } + } catch (CoreException ex) { + LangUIPlugin.logStatus(ex); + } + } + + return null; + } + + protected AnnotationInfo createAnnotationInfo(Annotation annotation, Position position, ITextViewer textViewer) { + return new AnnotationInfo(annotation, position, textViewer); + } + + /* + * @see ITextHoverExtension#getHoverControlCreator() + * @since 3.4 + */ + @Override + public IInformationControlCreator getHoverControlCreator() { + if (fHoverControlCreator == null) + fHoverControlCreator= new HoverControlCreator(getInformationPresenterControlCreator()); + return fHoverControlCreator; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover#getInformationPresenterControlCreator() + * @since 3.4 + */ + @Override + public IInformationControlCreator getInformationPresenterControlCreator() { + if (fPresenterControlCreator == null) + fPresenterControlCreator= new PresenterControlCreator(); + return fPresenterControlCreator; + } + + private IPath getEditorInputPath() { + if (getEditor() == null) + return null; + + IEditorInput input= getEditor().getEditorInput(); + if (input instanceof IStorageEditorInput) { + try { + return ((IStorageEditorInput)input).getStorage().getFullPath(); + } catch (CoreException ex) { + LangUIPlugin.logStatus(ex); + } + } + return null; + } + + protected IAnnotationModel getAnnotationModel(IPath path) { + if (path == null) + return null; + + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); + try { + manager.connect(path, LocationKind.NORMALIZE, null); + } catch (CoreException ex) { + LangUIPlugin.logStatus(ex); + return null; + } + + IAnnotationModel model= null; + try { + model= manager.getTextFileBuffer(path, LocationKind.NORMALIZE).getAnnotationModel(); + return model; + } finally { + if (model == null) { + try { + manager.disconnect(path, LocationKind.NORMALIZE, null); + } catch (CoreException ex) { + LangUIPlugin.logStatus(ex); + } + } + } + } + + /** + * Returns the annotation preference for the given annotation. + * + * @param annotation the annotation + * @return the annotation preference or null if none + */ + private static AnnotationPreference getAnnotationPreference(Annotation annotation) { + + if (annotation.isMarkedDeleted()) + return null; + return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation); + } +} diff --git a/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java new file mode 100644 index 000000000..4e3c0e1d1 --- /dev/null +++ b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2000, 2012 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Brock Janiczak - [implementation] Streams not being closed in Javadoc views - https://bugs.eclipse.org/bugs/show_bug.cgi?id=214854 + *******************************************************************************/ +package _org.eclipse.jdt.internal.ui.text.java.hover; + +import melnorme.lang.ide.ui.editor.ILangEditorTextHover; +import melnorme.lang.ide.ui.editor.WordFinder; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DefaultInformationControl; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.editors.text.EditorsUI; + + +/** + * Abstract class for providing hover information for Java elements. + * + * @since 2.1 + */ +public abstract class AbstractJavaEditorTextHover implements ILangEditorTextHover { + + private IEditorPart fEditor; + + @Override + public void setEditor(IEditorPart editor) { + fEditor= editor; + } + + protected IEditorPart getEditor() { + return fEditor; + } + +// protected ICodeAssist getCodeAssist() { +// if (fEditor != null) { +// IEditorInput input= fEditor.getEditorInput(); +// if (input instanceof IClassFileEditorInput) { +// IClassFileEditorInput cfeInput= (IClassFileEditorInput) input; +// return cfeInput.getClassFile(); +// } +// +// WorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager(); +// return manager.getWorkingCopy(input, false); +// } +// +// return null; +// } + + @SuppressWarnings("deprecation") + @Override + public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { + return getHoverInfo(textViewer, hoverRegion); + } + + @Override + public IRegion getHoverRegion(ITextViewer textViewer, int offset) { + return WordFinder.findWord(textViewer.getDocument(), offset); + } + +// /** +// * Returns the Java elements at the given hover region. +// * +// * @param textViewer the text viewer +// * @param hoverRegion the hover region +// * @return the array with the Java elements or null +// * @since 3.4 +// */ +// protected IJavaElement[] getJavaElementsAt(ITextViewer textViewer, IRegion hoverRegion) { +// /* +// * The region should be a word region an not of length 0. +// * This check is needed because codeSelect(...) also finds +// * the Java element if the offset is behind the word. +// */ +// if (hoverRegion.getLength() == 0) +// return null; +// +// IDocument document= textViewer.getDocument(); +// if (document != null && isInheritDoc(document, hoverRegion)) +// return null; +// +// ICodeAssist resolve= getCodeAssist(); +// if (resolve != null) { +// try { +// return resolve.codeSelect(hoverRegion.getOffset(), hoverRegion.getLength()); +// } catch (JavaModelException x) { +// return null; +// } +// } +// return null; +// } + + /** + * Returns whether the word is "inheritDoc". + * + * @param document the document + * @param wordRegion the word region + * @return true iff the word is "inheritDoc" + * @since 3.7 + */ + protected static boolean isInheritDoc(IDocument document, IRegion wordRegion) { + try { + String word= document.get(wordRegion.getOffset(), wordRegion.getLength()); + return "inheritDoc".equals(word); //$NON-NLS-1$ + } catch (BadLocationException e) { + return false; + } + } + + /* + * @see ITextHoverExtension#getHoverControlCreator() + * @since 3.0 + */ + @Override + public IInformationControlCreator getHoverControlCreator() { + return new IInformationControlCreator() { + @Override + public IInformationControl createInformationControl(Shell parent) { + return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString()); + } + }; + } + + /** + * Delegate method for {@link JavaInformationProvider#getInformationPresenterControlCreator()} + * + * @return the information control creator or null if none is available + * @since 3.4 + */ + public IInformationControlCreator getInformationPresenterControlCreator() { + return new IInformationControlCreator() { + @Override + public IInformationControl createInformationControl(Shell shell) { + return new DefaultInformationControl(shell, true); + } + }; + } + +// protected ITypeRoot getEditorInputJavaElement() { +// IEditorPart editor= getEditor(); +// if (editor != null) +// return EditorUtility.getEditorInputJavaElement(editor, false); +// return null; +// } +} diff --git a/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AnnotationHover.java b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AnnotationHover.java new file mode 100644 index 000000000..d5ef04c1e --- /dev/null +++ b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/AnnotationHover.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package _org.eclipse.jdt.internal.ui.text.java.hover; + +/** + * This annotation hover shows the description of the + * selected annotation. + * + * @since 3.0 + */ +public class AnnotationHover extends AbstractAnnotationHover { + + public AnnotationHover() { + super(true); + } + +} \ No newline at end of file diff --git a/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/ProblemHover.java b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/ProblemHover.java new file mode 100644 index 000000000..fb6a4133f --- /dev/null +++ b/plugin_ide.ui/src-lang/_org/eclipse/jdt/internal/ui/text/java/hover/ProblemHover.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * Copyright (c) 2000, 2012 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package _org.eclipse.jdt.internal.ui.text.java.hover; + +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.source.Annotation; + + +/** + * This annotation hover shows the description of the + * selected java annotation. + * + * XXX: Currently this problem hover only works for Java and spelling problems, + * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=62081 + * + * @since 3.0 + */ +public class ProblemHover extends AbstractAnnotationHover { + +// /** +// * Action to configure the problem severity of a compiler option. +// * +// * @since 3.4 +// */ +// private static final class ConfigureProblemSeverityAction extends Action { +// +// private static final String CONFIGURE_PROBLEM_SEVERITY_DIALOG_ID= "configure_problem_severity_dialog_id"; //$NON-NLS-1$ +// +// private final IJavaProject fProject; +// private final String fOptionId; +// private final boolean fIsJavadocOption; +// private final IInformationControl fInfoControl; +// +// public ConfigureProblemSeverityAction(IJavaProject project, String optionId, boolean isJavadocOption, IInformationControl infoControl) { +// super(); +// fProject= project; +// fOptionId= optionId; +// fIsJavadocOption= isJavadocOption; +// fInfoControl= infoControl; +// setImageDescriptor(JavaPluginImages.DESC_ELCL_CONFIGURE_PROBLEM_SEVERITIES); +// setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CONFIGURE_PROBLEM_SEVERITIES); +// setToolTipText(JavaHoverMessages.ProblemHover_action_configureProblemSeverity); +// } +// +// /* (non-Javadoc) +// * @see org.eclipse.jface.action.Action#run() +// */ +// @Override +// public void run() { +// boolean showPropertyPage; +// +// Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); +// +// if (! hasProjectSpecificOptions()) { +// String message= Messages.format( +// JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_message, +// new Object[] { JavaElementLabels.getElementLabel(fProject, JavaElementLabels.ALL_DEFAULT) }); +// +// String[] buttons= new String[] { +// JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_project, +// JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_workspace, +// IDialogConstants.CANCEL_LABEL }; +// +// int result= OptionalMessageDialog.open( +// CONFIGURE_PROBLEM_SEVERITY_DIALOG_ID, shell, JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_title, null, message, MessageDialog.QUESTION, buttons, 0, +// JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_checkBox_dontShowAgain); +// +// if (result == OptionalMessageDialog.NOT_SHOWN) { +// showPropertyPage= false; +// } else if (result == 2 || result == SWT.DEFAULT) { +// return; +// } else if (result == 0) { +// showPropertyPage= true; +// } else { +// showPropertyPage= false; +// } +// } else { +// showPropertyPage= true; +// } +// +// Map data= new HashMap(); +// String pageId; +// if (fIsJavadocOption) { +// if (showPropertyPage) { +// pageId= JavadocProblemsPreferencePage.PROP_ID; +// data.put(JavadocProblemsPreferencePage.DATA_USE_PROJECT_SPECIFIC_OPTIONS, Boolean.TRUE); +// } else { +// pageId= JavadocProblemsPreferencePage.PREF_ID; +// } +// data.put(JavadocProblemsPreferencePage.DATA_SELECT_OPTION_KEY, fOptionId); +// data.put(JavadocProblemsPreferencePage.DATA_SELECT_OPTION_QUALIFIER, JavaCore.PLUGIN_ID); +// } else { +// if (showPropertyPage) { +// pageId= ProblemSeveritiesPreferencePage.PROP_ID; +// data.put(ProblemSeveritiesPreferencePage.USE_PROJECT_SPECIFIC_OPTIONS, Boolean.TRUE); +// } else { +// pageId= ProblemSeveritiesPreferencePage.PREF_ID; +// } +// data.put(ProblemSeveritiesPreferencePage.DATA_SELECT_OPTION_KEY, fOptionId); +// data.put(ProblemSeveritiesPreferencePage.DATA_SELECT_OPTION_QUALIFIER, JavaCore.PLUGIN_ID); +// } +// +// fInfoControl.dispose(); //FIXME: should have protocol to hide, rather than dispose +// +// if (showPropertyPage) { +// PreferencesUtil.createPropertyDialogOn(shell, fProject, pageId, null, data).open(); +// } else { +// PreferencesUtil.createPreferenceDialogOn(shell, pageId, null, data).open(); +// } +// } +// +// private boolean hasProjectSpecificOptions() { +// Key[] keys= fIsJavadocOption ? JavadocProblemsConfigurationBlock.getKeys() : ProblemSeveritiesConfigurationBlock.getKeys(); +// return OptionsConfigurationBlock.hasProjectSpecificOptions(fProject.getProject(), keys, null); +// } +// } + + protected static class ProblemInfo extends AnnotationInfo { + + private static final ICompletionProposal[] NO_PROPOSALS= new ICompletionProposal[0]; + + public ProblemInfo(Annotation annotation, Position position, ITextViewer textViewer) { + super(annotation, position, textViewer); + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover.AnnotationInfo#getCompletionProposals() + */ + @Override + public ICompletionProposal[] getCompletionProposals() { +// if (annotation instanceof IJavaAnnotation) { +// ICompletionProposal[] result= getJavaAnnotationFixes((IJavaAnnotation) annotation); +// if (result.length > 0) +// return result; +// } +// +// if (annotation instanceof MarkerAnnotation) +// return getMarkerAnnotationFixes((MarkerAnnotation) annotation); + + return NO_PROPOSALS; + } + +// private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) { +// ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation); +// ICompilationUnit cu= javaAnnotation.getCompilationUnit(); +// if (cu == null) +// return NO_PROPOSALS; +// +// ISourceViewer sourceViewer= null; +// if (viewer instanceof ISourceViewer) +// sourceViewer= (ISourceViewer) viewer; +// +// IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY); +// if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location)) +// return NO_PROPOSALS; +// +// ArrayList proposals= new ArrayList(); +// JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); +// Collections.sort(proposals, new CompletionProposalComparator()); +// +// return proposals.toArray(new ICompletionProposal[proposals.size()]); +// } +// +// private static boolean hasProblem(IProblem[] problems, IProblemLocation location) { +// for (int i= 0; i < problems.length; i++) { +// IProblem problem= problems[i]; +// if (problem.getID() == location.getProblemId() && problem.getSourceStart() == location.getOffset()) +// return true; +// } +// return false; +// } +// +// private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { +// if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) +// return NO_PROPOSALS; +// +// IMarker marker= markerAnnotation.getMarker(); +// +// ICompilationUnit cu= getCompilationUnit(marker); +// if (cu == null) +// return NO_PROPOSALS; +// +// IEditorInput input= EditorUtility.getEditorInput(cu); +// if (input == null) +// return NO_PROPOSALS; +// +// IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); +// if (model == null) +// return NO_PROPOSALS; +// +// ISourceViewer sourceViewer= null; +// if (viewer instanceof ISourceViewer) +// sourceViewer= (ISourceViewer) viewer; +// +// AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); +// +// ArrayList proposals= new ArrayList(); +// JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); +// +// return proposals.toArray(new ICompletionProposal[proposals.size()]); +// } +// +// private static ICompilationUnit getCompilationUnit(IMarker marker) { +// IResource res= marker.getResource(); +// if (res instanceof IFile && res.isAccessible()) { +// IJavaElement element= JavaCore.create((IFile) res); +// if (element instanceof ICompilationUnit) +// return (ICompilationUnit) element; +// } +// return null; +// } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover.AnnotationInfo#fillToolBar(org.eclipse.jface.action.ToolBarManager) + */ + @Override + public void fillToolBar(ToolBarManager manager, IInformationControl infoControl) { + super.fillToolBar(manager, infoControl); +// if (!(annotation instanceof IJavaAnnotation)) +// return; +// +// IJavaAnnotation javaAnnotation= (IJavaAnnotation) annotation; +// +// String optionId= JavaCore.getOptionForConfigurableSeverity(javaAnnotation.getId()); +// if (optionId != null) { +// IJavaProject javaProject= javaAnnotation.getCompilationUnit().getJavaProject(); +// boolean isJavadocProblem= (javaAnnotation.getId() & IProblem.Javadoc) != 0; +// ConfigureProblemSeverityAction problemSeverityAction= new ConfigureProblemSeverityAction(javaProject, optionId, isJavadocProblem, infoControl); +// manager.add(problemSeverityAction); +// } + } + + } + + public ProblemHover() { + super(false); + } + + @Override + protected AnnotationInfo createAnnotationInfo(Annotation annotation, Position position, ITextViewer textViewer) { + return new ProblemInfo(annotation, position, textViewer); + } + +} \ No newline at end of file diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/AbstractLangEditorTextHover.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/AbstractLangEditorTextHover.java index b46609d0d..0cad27f72 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/AbstractLangEditorTextHover.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/AbstractLangEditorTextHover.java @@ -17,16 +17,19 @@ import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.ITextHoverExtension; +import org.eclipse.jface.text.ITextHoverExtension2; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.information.IInformationProviderExtension2; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; -public abstract class AbstractLangEditorTextHover implements ILangEditorTextHover, IInformationProviderExtension2 { +public abstract class AbstractLangEditorTextHover + implements ITextHover, ITextHoverExtension, ITextHoverExtension2, IInformationProviderExtension2 { protected IEditorPart fEditor; - @Override public void setEditor(IEditorPart editor) { fEditor = editor; } @@ -45,12 +48,7 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { } @Override - public final Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { - return getHoverInfo2_do(textViewer, hoverRegion); - } - - @Override - public abstract T getHoverInfo2_do(ITextViewer textViewer, IRegion hoverRegion); + public abstract Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion); @Override public abstract IInformationControlCreator getHoverControlCreator(); diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/BestMatchHover.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/BestMatchHover.java index 3d8fab4e9..2ba956c23 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/BestMatchHover.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/BestMatchHover.java @@ -31,7 +31,7 @@ * hover that returns some text for the specified parameters. * */ -public class BestMatchHover extends AbstractLangEditorTextHover { +public class BestMatchHover extends AbstractLangEditorTextHover { protected final int stateMask; //TODO: use statemask protected List> fInstantiatedTextHovers; @@ -79,7 +79,7 @@ public static IRegion doGetHoverRegion(ITextViewer textViewer, int offset) { } @Override - public Object getHoverInfo2_do(ITextViewer textViewer, IRegion hoverRegion) { + public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { fBestHover = null; for (ILangEditorTextHover hover : fInstantiatedTextHovers) { diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/ILangEditorTextHover.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/ILangEditorTextHover.java index 297b38e15..4fb710ac3 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/ILangEditorTextHover.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/editor/ILangEditorTextHover.java @@ -9,18 +9,14 @@ import org.eclipse.ui.IEditorPart; public interface ILangEditorTextHover extends ITextHover, ITextHoverExtension, ITextHoverExtension2 { - + /** * Sets the editor on which the hover is shown. - * - * @param editor the editor on which the hover popup should be shown */ void setEditor(IEditorPart editor); @Override - public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion); - - public INFO_TYPE getHoverInfo2_do(ITextViewer textViewer, IRegion hoverRegion); + public INFO_TYPE getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion); @Override public IInformationControlCreator getHoverControlCreator(); diff --git a/plugin_ide.ui/src/melnorme/lang/ide/ui/LangUIPlugin_Actual.java b/plugin_ide.ui/src/melnorme/lang/ide/ui/LangUIPlugin_Actual.java index 9344fd224..719d09b17 100644 --- a/plugin_ide.ui/src/melnorme/lang/ide/ui/LangUIPlugin_Actual.java +++ b/plugin_ide.ui/src/melnorme/lang/ide/ui/LangUIPlugin_Actual.java @@ -9,6 +9,8 @@ import LANG_PROJECT_ID.ide.ui.LANGUAGE_Images; import LANG_PROJECT_ID.ide.ui.editor.LANGUAGE_AutoEditStrategy; +import _org.eclipse.jdt.internal.ui.text.java.hover.AnnotationHover; +import _org.eclipse.jdt.internal.ui.text.java.hover.ProblemHover; /** * Actual/concrete IDE constants and other bindings, for Lang UI code. @@ -27,8 +29,9 @@ public final class LangUIPlugin_Actual { protected static final Class PLUGIN_IMAGES_CLASS = LANGUAGE_Images.class; - @SuppressWarnings("unused") protected static void initTextHovers( List>> textHoverSpecifications) { + textHoverSpecifications.add(ProblemHover.class); + textHoverSpecifications.add(AnnotationHover.class); } public static LANGUAGE_AutoEditStrategy createAutoEditStrategy(ISourceViewer sourceViewer, String contentType) {