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
|
/*******************************************************************************
* Copyright (c) 2000, 2016 QNX Software Systems 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:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.runtime.IPath;
public class MacroEntry extends APathEntry implements IMacroEntry {
String macroName;
String macroValue;
public MacroEntry(IPath path, IPath baseRef, String macroName, String macroValue, IPath[] exclusionPatterns,
boolean isExported) {
super(IPathEntry.CDT_MACRO, null, baseRef, path, exclusionPatterns, isExported);
if (macroName == null) {
throw new IllegalArgumentException("Macro name cannot be null"); //$NON-NLS-1$
}
this.macroName = macroName;
this.macroValue = macroValue == null ? "" : macroValue; //$NON-NLS-1$
}
/**
* Returns the macro name.
* @return String
*/
@Override
public String getMacroName() {
return macroName;
}
/**
* Returns the macro value.
* @return String
*/
@Override
public String getMacroValue() {
return macroValue;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((macroName == null) ? 0 : macroName.hashCode());
result = prime * result + ((macroValue == null) ? 0 : macroValue.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof IMacroEntry) {
IMacroEntry otherEntry = (IMacroEntry) obj;
if (!super.equals(otherEntry)) {
return false;
}
if (macroName == null) {
if (otherEntry.getMacroName() != null) {
return false;
}
} else {
if (!macroName.equals(otherEntry.getMacroName())) {
return false;
}
}
if (macroValue == null) {
if (otherEntry.getMacroValue() != null) {
return false;
}
} else {
if (!macroValue.equals(otherEntry.getMacroValue())) {
return false;
}
}
return true;
}
return super.equals(obj);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
if (macroName != null && macroName.length() > 0) {
sb.append(" name:").append(macroName); //$NON-NLS-1$
}
if (macroValue != null && macroValue.length() > 0) {
sb.append(" value:").append(macroValue); //$NON-NLS-1$
}
return sb.toString();
}
}
|