Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 294812 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/internal/ui/text/c/hover/BestMatchHover.java (-19 / +42 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 QNX Software Systems and others.
2
 * Copyright (c) 2009 QNX Software Systems 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 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     QNX Software Systems - Initial API and implementation
9
 *     QNX Software Systems - Initial API and implementation
10
 *     Anton Leherbauer (Wind River Systems)
10
 *     Anton Leherbauer (Wind River Systems)
11
 *     ERicsson             - Fix improper hover order (Bug 294812)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
13
13
package org.eclipse.cdt.internal.ui.text.c.hover;
14
package org.eclipse.cdt.internal.ui.text.c.hover;
Lines 16-24 Link Here
16
import java.util.Iterator;
17
import java.util.Iterator;
17
import java.util.List;
18
import java.util.List;
18
19
19
import org.eclipse.cdt.ui.CUIPlugin;
20
import org.eclipse.cdt.ui.PreferenceConstants;
21
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
22
import org.eclipse.jface.text.IInformationControlCreator;
20
import org.eclipse.jface.text.IInformationControlCreator;
23
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.jface.text.IRegion;
24
import org.eclipse.jface.text.ITextHover;
22
import org.eclipse.jface.text.ITextHover;
Lines 28-41 Link Here
28
import org.eclipse.jface.text.information.IInformationProviderExtension2;
26
import org.eclipse.jface.text.information.IInformationProviderExtension2;
29
import org.eclipse.ui.IEditorPart;
27
import org.eclipse.ui.IEditorPart;
30
28
29
import org.eclipse.cdt.ui.CUIPlugin;
30
import org.eclipse.cdt.ui.PreferenceConstants;
31
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
32
31
/**
33
/**
32
 * BestMatchHover
34
 * BestMatchHover
35
 * This is not a real hover, but instead, it is always the first hover used
36
 * and it will choose the best of the real hovers.  To choose the best hover,
37
 * we simply find the first hover that returns some text.  This implies
38
 * that the order of hovers is important and must be preserved. (Bug 294812)
33
 */
39
 */
34
public class BestMatchHover extends AbstractCEditorTextHover {
40
public class BestMatchHover extends AbstractCEditorTextHover {
35
41
36
	private List<CEditorTextHoverDescriptor> fTextHoverSpecifications;
42
	private List<CEditorTextHoverDescriptor> fTextHoverSpecifications;
37
	private List<ITextHover> fInstantiatedTextHovers;
43
	private ITextHover[] fInstantiatedTextHovers;
38
	private ITextHover fBestHover;
44
	private ITextHover fBestHover;
45
	private int fNullEntryCount;
39
46
40
	public BestMatchHover() {
47
	public BestMatchHover() {
41
		installTextHovers();
48
		installTextHovers();
Lines 50-63 Link Here
50
	 * Installs all text hovers.
57
	 * Installs all text hovers.
51
	 */
58
	 */
52
	private void installTextHovers() {
59
	private void installTextHovers() {
60
		CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors();
61
		int len = hoverDescs.length;
53
		
62
		
54
		// initialize lists - indicates that the initialization happened
63
		// initialize lists - indicates that the initialization happened
55
		fTextHoverSpecifications= new ArrayList<CEditorTextHoverDescriptor>(2);
64
		fTextHoverSpecifications= new ArrayList<CEditorTextHoverDescriptor>(len);
56
		fInstantiatedTextHovers= new ArrayList<ITextHover>(2);
65
		fInstantiatedTextHovers= new ITextHover[len];
57
66
58
		// populate list
67
		// populate list
59
		CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors();
68
		for (int i= 0; i < len; i++) {
60
		for (int i= 0; i < hoverDescs.length; i++) {
61
			// ensure that we don't add ourselves to the list
69
			// ensure that we don't add ourselves to the list
62
			if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
70
			if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
63
				fTextHoverSpecifications.add(hoverDescs[i]);
71
				fTextHoverSpecifications.add(hoverDescs[i]);
Lines 68-88 Link Here
68
		if (fTextHoverSpecifications.size() == 0)
76
		if (fTextHoverSpecifications.size() == 0)
69
			return;
77
			return;
70
78
71
		for (Iterator<CEditorTextHoverDescriptor> iterator= new ArrayList<CEditorTextHoverDescriptor>(fTextHoverSpecifications).iterator(); iterator.hasNext(); ) {
79
		fNullEntryCount= 0;
80
		for (Iterator<CEditorTextHoverDescriptor> iterator= fTextHoverSpecifications.iterator(); iterator.hasNext(); ) {
72
			CEditorTextHoverDescriptor spec= iterator.next();
81
			CEditorTextHoverDescriptor spec= iterator.next();
73
82
74
			ICEditorTextHover hover= spec.createTextHover();
83
			ICEditorTextHover hover= spec.createTextHover();
75
			if (hover != null) {
84
			if (hover != null) {
76
				hover.setEditor(getEditor());
85
				hover.setEditor(getEditor());
77
				addTextHover(hover);
86
				iterator.remove();
78
				fTextHoverSpecifications.remove(spec);
87
			}
88
			// Add the hover, even if it is null, so that we keep a spot
89
			// for the missing hovers, for later.  This is to preserve their
90
			// order, which is important in determining the best hover
91
			addTextHover(hover);
92
			if (hover == null) {
93
				fNullEntryCount++;				
79
			}
94
			}
80
		}
95
		}
81
	}
96
	}
82
97
83
	protected void addTextHover(ITextHover hover) {
98
	protected void addTextHover(ITextHover hover) {
84
		if (!fInstantiatedTextHovers.contains(hover))
99
		int nullCount= 0;
85
			fInstantiatedTextHovers.add(hover);
100
		for (int i= 0; i < fInstantiatedTextHovers.length; i++) {
101
			if (fInstantiatedTextHovers[i] == null) {
102
				if (fNullEntryCount == nullCount) {
103
					fInstantiatedTextHovers[i]= hover;
104
					return;
105
				}
106
				nullCount++;
107
			}
108
		}
86
	}
109
	}
87
110
88
	/*
111
	/*
Lines 98-105 Link Here
98
		if (fInstantiatedTextHovers == null)
121
		if (fInstantiatedTextHovers == null)
99
			return null;
122
			return null;
100
123
101
		for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
124
		for (ITextHover hover : fInstantiatedTextHovers) {
102
			ITextHover hover= iterator.next();
125
			if (hover == null) continue;
103
126
104
			String s= hover.getHoverInfo(textViewer, hoverRegion);
127
			String s= hover.getHoverInfo(textViewer, hoverRegion);
105
			if (s != null && s.trim().length() > 0) {
128
			if (s != null && s.trim().length() > 0) {
Lines 124-132 Link Here
124
		if (fInstantiatedTextHovers == null)
147
		if (fInstantiatedTextHovers == null)
125
			return null;
148
			return null;
126
		
149
		
127
		for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
150
		for (ITextHover hover : fInstantiatedTextHovers) {
128
			ITextHover hover= iterator.next();
151
			if (hover == null) continue;
129
			
152
130
			if (hover instanceof ITextHoverExtension2) {
153
			if (hover instanceof ITextHoverExtension2) {
131
				Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
154
				Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
132
				if (info != null) {
155
				if (info != null) {

Return to bug 294812