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 (-18 / +40 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-62 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();
53
		
61
		
54
		// initialize lists - indicates that the initialization happened
62
		// initialize lists - indicates that the initialization happened
55
		fTextHoverSpecifications= new ArrayList<CEditorTextHoverDescriptor>(2);
63
		fTextHoverSpecifications= new ArrayList<CEditorTextHoverDescriptor>(hoverDescs.length-1);
56
		fInstantiatedTextHovers= new ArrayList<ITextHover>(2);
64
		fInstantiatedTextHovers= new ITextHover[hoverDescs.length-1];
57
65
58
		// populate list
66
		// populate list
59
		CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors();
60
		for (int i= 0; i < hoverDescs.length; i++) {
67
		for (int i= 0; i < hoverDescs.length; i++) {
61
			// ensure that we don't add ourselves to the list
68
			// ensure that we don't add ourselves to the list
62
			if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
69
			if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
Lines 68-88 Link Here
68
		if (fTextHoverSpecifications.size() == 0)
75
		if (fTextHoverSpecifications.size() == 0)
69
			return;
76
			return;
70
77
71
		for (Iterator<CEditorTextHoverDescriptor> iterator= new ArrayList<CEditorTextHoverDescriptor>(fTextHoverSpecifications).iterator(); iterator.hasNext(); ) {
78
		fNullEntryCount= 0;
79
		for (Iterator<CEditorTextHoverDescriptor> iterator= fTextHoverSpecifications.iterator(); iterator.hasNext(); ) {
72
			CEditorTextHoverDescriptor spec= iterator.next();
80
			CEditorTextHoverDescriptor spec= iterator.next();
73
81
74
			ICEditorTextHover hover= spec.createTextHover();
82
			ICEditorTextHover hover= spec.createTextHover();
75
			if (hover != null) {
83
			if (hover != null) {
76
				hover.setEditor(getEditor());
84
				hover.setEditor(getEditor());
77
				addTextHover(hover);
85
				iterator.remove();
78
				fTextHoverSpecifications.remove(spec);
86
			}
87
			// Add the hover, even if it is null, so that we keep a spot
88
			// for the missing hovers, for later.  This is to preserve their
89
			// order, which is important in determining the best hover
90
			addTextHover(hover);
91
			if (hover == null) {
92
				fNullEntryCount++;				
79
			}
93
			}
80
		}
94
		}
81
	}
95
	}
82
96
83
	protected void addTextHover(ITextHover hover) {
97
	protected void addTextHover(ITextHover hover) {
84
		if (!fInstantiatedTextHovers.contains(hover))
98
		int nullCount= 0;
85
			fInstantiatedTextHovers.add(hover);
99
		for (int i= 0; i < fInstantiatedTextHovers.length; i++) {
100
			if (fInstantiatedTextHovers[i] == null) {
101
				if (fNullEntryCount == nullCount) {
102
					fInstantiatedTextHovers[i]= hover;
103
					return;
104
				}
105
				nullCount++;
106
			}
107
		}
86
	}
108
	}
87
109
88
	/*
110
	/*
Lines 98-105 Link Here
98
		if (fInstantiatedTextHovers == null)
120
		if (fInstantiatedTextHovers == null)
99
			return null;
121
			return null;
100
122
101
		for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
123
		for (ITextHover hover : fInstantiatedTextHovers) {
102
			ITextHover hover= iterator.next();
124
			if (hover == null) continue;
103
125
104
			String s= hover.getHoverInfo(textViewer, hoverRegion);
126
			String s= hover.getHoverInfo(textViewer, hoverRegion);
105
			if (s != null && s.trim().length() > 0) {
127
			if (s != null && s.trim().length() > 0) {
Lines 124-132 Link Here
124
		if (fInstantiatedTextHovers == null)
146
		if (fInstantiatedTextHovers == null)
125
			return null;
147
			return null;
126
		
148
		
127
		for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
149
		for (ITextHover hover : fInstantiatedTextHovers) {
128
			ITextHover hover= iterator.next();
150
			if (hover == null) continue;
129
			
151
130
			if (hover instanceof ITextHoverExtension2) {
152
			if (hover instanceof ITextHoverExtension2) {
131
				Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
153
				Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
132
				if (info != null) {
154
				if (info != null) {

Return to bug 294812