Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a0e6b865482668fda5de0c4d24985d01421b6396 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************************************
 * Copyright (c) 2007, 2016 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.make.core.scannerconfig;

import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.core.resources.IProject;

public final class InfoContext {
	private IProject fProject;
	private String fInstanceId;
	private ILanguage fLanguage;

	public InfoContext(IProject project) {
		this(project, null);
	}

	public InfoContext(IProject project, String instanceId) {
		this.fProject = project;
		this.fInstanceId = instanceId != null ? instanceId : ""; //$NON-NLS-1$
	}

	/**
	 * @since 7.1
	 */
	public InfoContext(IProject project, String instanceId, ILanguage language) {
		this.fProject = project;
		this.fInstanceId = instanceId != null ? instanceId : ""; //$NON-NLS-1$
		this.fLanguage = language;
	}

	public String getInstanceId() {
		return fInstanceId;
	}

	/**
	 * @since 7.1
	 */
	public ILanguage getLanguage() {
		return fLanguage;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;

		if (!(obj instanceof InfoContext))
			return false;

		InfoContext other = (InfoContext) obj;
		if (fProject == null) {
			if (other.fProject != null)
				return false;
		} else if (!fProject.equals(other.fProject))
			return false;

		if (!fInstanceId.equals(other.fInstanceId))
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		int code = fProject != null ? fProject.hashCode() : 0;

		code += fInstanceId.hashCode();

		return code;
	}

	@Override
	public String toString() {
		StringBuilder buf = new StringBuilder();

		if (fProject != null)
			buf.append(fProject.toString());
		else
			buf.append("no project"); //$NON-NLS-1$
		if (fInstanceId.length() != 0) {
			buf.append(" , instance: "); //$NON-NLS-1$
			buf.append(fInstanceId);
		}

		return buf.toString();
	}

	/**
	 * a convenience method that specifies whether this is a default context,
	 * i.e. the one defined for the project with no extension filters
	 *
	 * @return boolean
	 */
	public boolean isDefaultContext() {
		//		if(fProject == null)
		//			return false;

		if (fInstanceId.length() != 0)
			return false;

		return true;
	}

	public IProject getProject() {
		return fProject;
	}
}

Back to the top