forked from erlang/erlide_eclipse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ErlRecordDef.java
90 lines (75 loc) · 2.21 KB
/
ErlRecordDef.java
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
package org.erlide.core.internal.model.erlang;
import org.erlide.core.internal.model.root.ErlElement;
import org.erlide.core.internal.model.root.ErlMember;
import org.erlide.core.model.ErlModelException;
import org.erlide.core.model.IParent;
import org.erlide.core.model.erlang.IErlRecordDef;
import org.erlide.core.model.erlang.IErlRecordField;
import org.erlide.core.model.root.IErlElement;
import com.google.common.base.Objects;
public class ErlRecordDef extends ErlMember implements IErlRecordDef {
private final String record;
private final String extra;
/**
* @param parent
* @param imports
* @param module
*/
public ErlRecordDef(final IParent parent, final String extra) {
super(parent, "record_definition");
record = uptoCommaOrParen(extra);
this.extra = extra;
}
@Override
public Kind getKind() {
return Kind.RECORD_DEF;
}
@Override
public String getDefinedName() {
return record;
}
@Override
public String toString() {
return getName() + ": " + getDefinedName();
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), getDefinedName());
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (getParent() == null) {
// this should never happen!
return super.equals(o);
}
if (o instanceof ErlElement) {
return toString().equals(o.toString());
}
return false;
}
@Override
public String getExtra() {
return extra;
}
@Override
public IErlRecordField getFieldNamed(final String name) {
try {
for (final IErlElement e : getChildrenOfKind(Kind.RECORD_FIELD)) {
if (e instanceof IErlRecordField) {
final IErlRecordField field = (IErlRecordField) e;
if (field.getFieldName().equals(name)) {
return field;
}
}
}
} catch (final ErlModelException e) {
}
return null;
}
}