Skip to content

Commit

Permalink
Assorted cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Sep 16, 2023
1 parent 723e968 commit ea1063f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,21 @@

import jakarta.annotation.Nonnull;

import java.util.Objects;

/**
* Simple compiler feedback wrapper.
*
* @param line
* Line the message applies to.
* @param column
* Column the message applies to within the line.
* @param message
* Message detailing the problem.
* @param level
* Diagnostic problem level.
*
* @author Matt Coley
*/
public class CompilerDiagnostic {
private final int line;
private final int column;
private final String message;
private final Level level;

/**
* @param line
* Line the message applies to.
* @param column
* Column the message applies to within the line.
* @param message
* Message detailing the problem.
* @param level
* Diagnostic problem level.
*/
public CompilerDiagnostic(int line, int column, @Nonnull String message, @Nonnull Level level) {
this.line = line;
this.column = column;
this.message = message;
this.level = level;
}

public record CompilerDiagnostic(int line, int column, @Nonnull String message, @Nonnull Level level) {
/**
* @param line
* New line number.
Expand All @@ -43,63 +28,11 @@ public CompilerDiagnostic withLine(int line) {
return new CompilerDiagnostic(line, column, message, level);
}

/**
* @return Line the message applies to.
*/
public int getLine() {
return line;
}

/**
* @return Column the message applies to within the line.
*/
public int getColumn() {
return column;
}

/**
* @return Message detailing the problem.
*/
@Nonnull
public String getMessage() {
return message;
}

/**
* @return Diagnostic problem level.
*/
@Nonnull
public Level getLevel() {
return level;
}

@Override
public String toString() {
return level.name() + " - " + line + ":" + message;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

CompilerDiagnostic other = (CompilerDiagnostic) o;

if (line != other.line) return false;
if (column != other.column) return false;
if (!Objects.equals(message, other.message)) return false;
return level == other.level;
}

@Override
public int hashCode() {
int result = line;
result = 31 * result + column;
result = 31 * result + message.hashCode();
result = 31 * result + level.hashCode();
return result;
}

/**
* Diagnostic level.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean wasSuccess() {
return compilations != null &&
compilations.size() > 0 &&
exception == null &&
diagnostics.stream().noneMatch(d -> d.getLevel() == CompilerDiagnostic.Level.ERROR);
diagnostics.stream().noneMatch(d -> d.level() == CompilerDiagnostic.Level.ERROR);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public ScriptEngineConfig getServiceConfig() {

@Nonnull
@Override
public CompletableFuture<ScriptResult> run(String script) {
public CompletableFuture<ScriptResult> run(@Nonnull String script) {
return CompletableFuture.supplyAsync(() -> handleExecute(script), compileAndRunPool);
}

@Nonnull
@Override
public CompletableFuture<GenerateResult> compile(String scriptSource) {
public CompletableFuture<GenerateResult> compile(@Nonnull String scriptSource) {
return CompletableFuture.supplyAsync(() -> generate(scriptSource), compileAndRunPool);
}

Expand Down Expand Up @@ -306,7 +306,7 @@ private List<CompilerDiagnostic> mapDiagnostics(@Nonnull String originalSource,

int syntheticLineCount = StringUtil.count("\n", StringUtil.cutOffAtFirst(compileSource, originalSource));
return diagnostics.stream()
.map(d -> d.withLine(d.getLine() - syntheticLineCount))
.map(d -> d.withLine(d.line() - syntheticLineCount))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ScriptEngine extends Service {
* @return Future of script execution.
*/
@Nonnull
CompletableFuture<ScriptResult> run(String scriptSource);
CompletableFuture<ScriptResult> run(@Nonnull String scriptSource);

/**
* @param scriptSource
Expand All @@ -29,5 +29,5 @@ public interface ScriptEngine extends Service {
* @return Future of script compilation.
*/
@Nonnull
CompletableFuture<GenerateResult> compile(String scriptSource);
CompletableFuture<GenerateResult> compile(@Nonnull String scriptSource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BasicInfoImporter(@Nonnull InfoImporterConfig config, @Nonnull ClassPatch

@Nonnull
@Override
public Info readInfo(String name, ByteSource source) throws IOException {
public Info readInfo(@Nonnull String name, @Nonnull ByteSource source) throws IOException {
byte[] data = source.readAll();

// Check for Java classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public interface InfoImporter extends Service {
* When the content cannot be read.
*/
@Nonnull
Info readInfo(String name, ByteSource source) throws IOException;
Info readInfo(@Nonnull String name, @Nonnull ByteSource source) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ResourceSummaryService(@Nonnull ResourceSummaryServiceConfig config,

// TODO: Summarizer for android
// - Manifest
// - Permissions
// - Entry points (can update existing entry-point summarizer)
// - Permissions (and their descriptions, level of concern perhaps?)

// Add discovered summarizers from classpath.
for (ResourceSummarizer summarizer : summarizers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public Problem(int line, int column, @Nonnull ProblemLevel level, @Nonnull Probl
* @return Problem from the diagnostic data.
*/
public static Problem fromDiagnostic(CompilerDiagnostic diagnostic) {
ProblemLevel level = switch (diagnostic.getLevel()) {
ProblemLevel level = switch (diagnostic.level()) {
case WARNING -> ProblemLevel.WARN;
case INFO -> ProblemLevel.INFO;
default -> ProblemLevel.ERROR;
};
return new Problem(diagnostic.getLine(), diagnostic.getColumn(), level, ProblemPhase.BUILD, diagnostic.getMessage());
return new Problem(diagnostic.line(), diagnostic.column(), level, ProblemPhase.BUILD, diagnostic.message());
}

/**
Expand Down

0 comments on commit ea1063f

Please sign in to comment.