8000 Add getDisplayName() to ClassPathEntry for informational purposes · sakerbuild/saker.java.compiler@141ce4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 141ce4d

Browse files
committed
Add getDisplayName() to ClassPathEntry for informational purposes
Also for IDE configuration reporting so the user can more easily identify the applied project settings.
1 parent ec84ccb commit 141ce4d

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

api/src/main/saker/java/compiler/api/classpath/ClassPathEntry.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ public default StructuredTaskResult getDocumentationAttachment() {
126126
return null;
127127
}
128128

129+
/**
130+
* Gets the display name for this classpath entry.
131+
* <p>
132+
* The display name is purely for informational purposes, and is generally used in error messages or in the IDE when
133+
* IDE configurations are applied. They should be short, human readable, and identify the classpath entry in some
134+
* way.
135+
*
136+
* @return The display name or <code>null</code> if none.
137+
* @since saker.java.compiler 0.8.6
138+
*/
139+
public default String getDisplayName() {
140+
return null;
141+
}
142+
129143
/**
130144
* Gets the ABI version key of the classpath.
131145
* <p>

impl/src/main/saker/java/compiler/impl/compile/ClassPathIDEConfigurationEntry.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ClassPathIDEConfigurationEntry implements Externalizable {
3636
private StructuredTaskResult sourceAttachment;
3737
private StructuredTaskResult docAttachment;
3838
private SakerPath sourceGenDirectory;
39+
private String displayName;
3940

4041
/**
4142
* For {@link Externalizable}.
@@ -89,13 +90,22 @@ public SakerPath getSourceGenDirectory() {
8990
return sourceGenDirectory;
9091
}
9192

93+
public void setDisplayName(String displayName) {
94+
this.displayName = displayName;
95+
}
96+
97+
public String getDisplayName() {
98+
return displayName;
99+
}
100+
92101
@Override
93102
public void writeExternal(ObjectOutput out) throws IOException {
94103
out.writeObject(inputFile);
95104
SerialUtils.writeExternalCollection(out, sourceDirectories);
96105
out.writeObject(sourceAttachment);
97106
out.writeObject(docAttachment);
98107
out.writeObject(sourceGenDirectory);
108+
out.writeObject(displayName);
99109
}
100110

101111
@Override
@@ -105,12 +115,14 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
105115
sourceAttachment = (StructuredTaskResult) in.readObject();
106116
docAttachment = (StructuredTaskResult) in.readObject();
107117
sourceGenDirectory = (SakerPath) in.readObject();
118+
displayName = SerialUtils.readExternalObject(in);
108119
}
109120

110121
@Override
111122
public int hashCode() {
112123
final int prime = 31;
113124
int result = 1;
125+
result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
114126
result = prime * result + ((docAttachment == null) ? 0 : docAttachment.hashCode());
115127
result = prime * result + ((inputFile == null) ? 0 : inputFile.hashCode());
116128
result = prime * result + ((sourceAttachment == null) ? 0 : sourceAttachment.hashCode());
@@ -128,6 +140,11 @@ public boolean equals(Object obj) {
128140
if (getClass() != obj.getClass())
129141
return false;
130142
ClassPathIDEConfigurationEntry other = (ClassPathIDEConfigurationEntry) obj;
143+
if (displayName == null) {
144+
if (other.displayName != null)
145+
return false;
146+
} else if (!displayName.equals(other.displayName))
147+
return false;
131148
if (docAttachment == null) {
132149
if (other.docAttachment != null)
133150
return false;

impl/src/main/saker/java/compiler/impl/compile/JavaIDEConfigurationReportingTaskFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ private ClassPathConfigurationBuilder buildClassPathConfiguration(TaskContext ta
380380

381381
StructuredTaskResult docattachment = cpe.getDocumentationAttachment();
382382
setClassPathDocAttachment(taskcontext, cpbuilder, docattachment, sdkreferences);
383+
384+
String displayname = cpe.getDisplayName();
385+
if (!ObjectUtils.isNullOrEmpty(displayname)) {
386+
cpbuilder.setDisplayName(displayname);
387+
}
383388
return cpbuilder;
384389
}
385390

impl/src/main/saker/java/compiler/impl/compile/handler/full/FullCompilationHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ public void visit(FileClassPath inputfilecp) {
503503
}
504504
ClassPathIDEConfigurationEntry value = new ClassPathIDEConfigurationEntry(filelocation,
505505
sourcediroptions, entry.getSourceAttachment(), entry.getDocumentationAttachment());
506+
value.setDisplayName(entry.getDisplayName());
506507
result.put(filelocation, value);
507508

508509
Collection<? extends ClassPathReference> additionalclasspaths = entry

impl/src/main/saker/java/compiler/impl/compile/handler/incremental/IncrementalCompilationHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ public void visit(FileClassPath inputfilecp) {
13021302
}
13031303
ClassPathIDEConfigurationEntry value = new ClassPathIDEConfigurationEntry(filelocation,
13041304
sourcediroptions, entry.getSourceAttachment(), entry.getDocumentationAttachment());
1305+
value.setDisplayName(entry.getDisplayName());
13051306
ideconfigentries.add(value);
13061307

13071308
Collection<? extends ClassPathReference> additionalclasspaths = entry

impl/src/main/saker/java/compiler/impl/ide/configuration/JavaIDEConfigurationBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public final class JavaIDEConfigurationBuilder {
4646
public static final String FIELD_CLASSPATH_LOCAL_DOCPATH = "docpath.local";
4747
public static final String FIELD_CLASSPATH_SOURCEDIRECTORIES = "sourcedirectories";
4848
public static final String FIELD_CLASSPATH_SOURCEGENDIRECTORY = "sourcegendirectory";
49+
public static final Str FDD2 ing FIELD_CLASSPATH_DISPLAY_NAME = "display.name";
4950

5051
public static final String FIELD_BOOT_CLASSPATHS = "java.bootclasspaths";
5152

@@ -191,6 +192,7 @@ public static final class ClassPathConfigurationBuilder {
191192
protected String documentationAttachmentLocalPath;
192193
protected Set<Object> sourceDirectories = new LinkedHashSet<>();
193194
protected String sourceGenDirectory;
195+
protected String displayName;
194196

195197
public ClassPathConfigurationBuilder() {
196198
}
@@ -236,6 +238,11 @@ public ClassPathConfigurationBuilder addSourceDirectory(SourceDirectoryConfigura
236238
return this;
237239
}
238240

241+
public ClassPathConfigurationBuilder setDisplayName(String displayname) {
242+
this.displayName = displayname;
243+
return this;
244+
}
245+
239246
public Object toClassPathObject() {
240247
TreeMap<String, Object> result = new TreeMap<>();
241248
if (!ObjectUtils.isNullOrEmpty(path)) {
@@ -263,7 +270,11 @@ public Object toClassPathObject() {
263270
if (!ObjectUtils.isNullOrEmpty(sourceGenDirectory)) {
264271
result.put(FIELD_CLASSPATH_SOURCEGENDIRECTORY, sourceGenDirectory);
265272
}
273+
if (!ObjectUtils.isNullOrEmpty(displayName)) {
274+
result.put(FIELD_CLASSPATH_DISPLAY_NAME, displayName);
275+
}
266276
return ImmutableUtils.unmodifiableMap(result);
267277
}
278+
268279
}
269280
}

0 commit comments

Comments
 (0)
0