8000 Add DocumentedFieldSignature · sakerbuild/saker.java.compiler@499a77c · GitHub
[go: up one dir, main page]

Skip to content

Commit 499a77c

Browse files
committed
Add DocumentedFieldSignature
1 parent df8d903 commit 499a77c

File tree

2 files changed

+86
-13
lines changed

2 files changed

+86
-13
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2020 Bence Sipka
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
package saker.java.compiler.impl.compile.signature.impl;
17+
18+
import java.io.Externalizable;
19+
import java.io.IOException;
20+
import java.io.ObjectInput;
21+
import java.io.ObjectOutput;
22+
import java.util.Set;
23+
24+
import javax.lang.model.element.Modifier;
25+
26+
import saker.java.compiler.impl.signature.type.TypeSignature;
27+
28+
public class DocumentedFieldSignature extends SimpleFieldSignature {
29+
private static final long serialVersionUID = 1L;
30+
31+
protected String docComment;
32+
33+
/**
34+
* For {@link Externalizable}.
35+
*/
36+
public DocumentedFieldSignature() {
37+
}
38+
39+
public DocumentedFieldSignature(Set<Modifier> modifiers, TypeSignature type, String name, String docComment) {
40+
super(modifiers, type, name);
41+
this.docComment = docComment;
42+
}
43+
44+
@Override
45+
public String getDocComment() {
46+
return docComment;
47+
}
48+
49+
@Override
50+
public void writeExternal(ObjectOutput out) throws IOException {
51+
super.writeExternal(out);
52+
53+
out.writeObject(docComment);
54+
}
55+
56+
@Override
57+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
58+
super.readExternal(in);
59+
60+
docComment = (String) in.readObject();
61+
}
62+
63+
@Override
64+
public boolean equals(Object obj) {
65+
if (this == obj)
66+
return true;
67+
if (!super.equals(obj))
68+
return false;
69+
if (getClass() != obj.getClass())
70+
return false;
71+
DocumentedFieldSignature other = (DocumentedFieldSignature) obj;
72+
if (docComment == null) {
73+
if (other.docComment != null)
74+
return false;
75+
} else if (!docComment.equals(other.docComment))
76+
return false;
77+
return true;
78+
}
79+
80+
}

impl/src/main/saker/java/compiler/impl/compile/signature/impl/FieldSignatureImpl.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,12 @@ public FieldSignatureImpl() {
4343
public static FieldSignature create(ElementKind kind, Set<Modifier> modifiers, TypeSignature type, String name,
4444
ConstantValueResolver constantValue, String docComment) {
4545
if (kind == ElementKind.ENUM_CONSTANT) {
46-
if (docComment == null) {
47-
return new SimpleEnumConstantFieldSignature(type, name);
48-
}
49-
return new DocumentedSimpleEnumConstantFieldSignature(type, name, docComment);
46+
return createEnumSignature(type, name, docComment);
5047
}
5148
if (ElementKindCompatUtils.isRecordComponentElementKind(kind)) {
52-
return new RecordComponentSignatureImpl(modifiers, type, name, docComment);
53-
}
54-
if (docComment == null) {
55-
if (constantValue == null) {
56-
return new SimpleFieldSignature(modifiers, type, name);
57-
}
58-
return new ConstantFieldSignature(modifiers, type, name, constantValue);
49+
return createRecordComponent(modifiers, type, name, docComment);
5950
}
60-
61-
return new FieldSignatureImpl(modifiers, type, name, constantValue, docComment);
51+
return createField(modifiers, type, name, constantValue, docComment);
6252
}
6353

6454
public static FieldSignature createField(Set<Modifier> modifiers, TypeSignature type, String name,
@@ -69,6 +59,9 @@ public static FieldSignature createField(Set<Modifier> modifiers, TypeSignature
6959
}
7060
return new ConstantFieldSignature(modifiers, type, name, constantValue);
7161
}
62+
if (constantValue == null) {
63+
return new DocumentedFieldSignature(modifiers, type, name, docComment);
64+
}
7265
return new FieldSignatureImpl(modifiers, type, name, constantValue, docComment);
7366
}
7467

0 commit comments

Comments
 (0)
0