Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f29b3df0ba102b579a008f4946ddf1d661d6f96a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**********************************************************************
 * Copyright (c) 2004, 2012 Intel Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     Intel Corporation - Initial API and implementation
 **********************************************************************/
package org.eclipse.cdt.ui.tests.chelp;

import org.junit.Assert;

import org.eclipse.cdt.ui.ICHelpBook;
import org.eclipse.cdt.ui.ICHelpProvider;
import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;

/**
 * This class implements ICHelpProvider and provides test information
 */
public class CHelpTestInfoProvider implements ICHelpProvider {
	private static int fNumProviders = 0;
	private static final String PROVIDER_ID_PREFIX = "TestInfoProvider_";
	
	final private String fProviderID;
	private boolean fIsInitialized;
	
	private ICHelpBook fCHelpBooks[];
	
	/**
	 * Flag indicating whether this help provider should provide help info.
	 * Should be set to <code>true</code> during tests only.
	 */
	public static boolean fgEnabled= false;

	public CHelpTestInfoProvider() {
		fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
		fCHelpBooks = CHelpProviderTester.getDefault().generateCHelpBooks(fProviderID);
	}
	
	public static int getNumProviders() {
		return fNumProviders;
	}

	@Override
	public void initialize() {
		Assert.assertFalse("initialize is called several times", fIsInitialized);
		fIsInitialized = true;
	}

	@Override
	public ICHelpBook[] getCHelpBooks() {
		if (!fgEnabled) {
			return new ICHelpBook[0];
		}
		Assert.assertTrue("getCHelpBooks is called before completion contributor gets initialized",fIsInitialized);
		return fCHelpBooks;
	}

	@Override
	public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
		if (!fgEnabled) {
			return null;
		}
		Assert.assertTrue("getFunctionInfo is called before completion contributor gets initialized",fIsInitialized);
		return CHelpProviderTester.getDefault().generateFunctionInfo(helpBooks, name, fProviderID);
	}

	@Override
	public IFunctionSummary[] getMatchingFunctions(
			ICHelpInvocationContext context, ICHelpBook[] helpBooks,
			String prefix) {
		if (!fgEnabled) {
			return new IFunctionSummary[0];
		}
		Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized", fIsInitialized);
        //return null; // TODO returning null until someone puts in a preference to control it.
        return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID);
	}

	@Override
	public ICHelpResourceDescriptor[] getHelpResources(ICHelpInvocationContext context, ICHelpBook[] helpBooks,
			String name) {
		if (!fgEnabled) {
			return new ICHelpResourceDescriptor[0];
		}
		Assert.assertTrue("getHelpResources is called before completion contributor gets initialized", fIsInitialized);
		return CHelpProviderTester.getDefault().generateHelpResources(helpBooks, name, fProviderID);
	}
}

Back to the top