-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start a new process running the javac wrapper as javac, and use the a…
…rguments generated by CheckerMain to launch it
- Loading branch information
1 parent
23906bc
commit d328a02
Showing
7 changed files
with
281 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
./gradlew shadowjar |
144 changes: 144 additions & 0 deletions
144
src/main/java/org/checkerframework/languageserver/CFDiagnostic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package org.checkerframework.languageserver; | ||
|
||
import javax.tools.Diagnostic; | ||
import javax.tools.JavaFileObject; | ||
import java.util.Locale; | ||
|
||
public class CFDiagnostic implements Diagnostic { | ||
|
||
final String fileUri; | ||
final String kind; | ||
final long position; | ||
final long startPosition; | ||
final long endPosition; | ||
final long lineNumber; | ||
final long columnNumber; | ||
final String code; | ||
final String message; | ||
|
||
CFDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) { | ||
fileUri = diagnostic.getSource().toUri().toString(); | ||
kind = diagnostic.getKind().name(); | ||
position = diagnostic.getPosition(); | ||
startPosition = diagnostic.getStartPosition(); | ||
endPosition = diagnostic.getEndPosition(); | ||
lineNumber = diagnostic.getLineNumber(); | ||
columnNumber = diagnostic.getColumnNumber(); | ||
code = diagnostic.getCode(); | ||
message = diagnostic.getMessage(null); | ||
} | ||
|
||
/** | ||
* Gets the kind of this diagnostic, for example, error or | ||
* warning. | ||
* | ||
* @return the kind of this diagnostic | ||
*/ | ||
@Override | ||
public Kind getKind() { | ||
return Kind.valueOf(kind); | ||
} | ||
|
||
/** | ||
* Gets the source object associated with this diagnostic. | ||
* | ||
* @return the source object associated with this diagnostic. | ||
* {@code null} if no source object is associated with the | ||
* diagnostic. | ||
*/ | ||
@Override | ||
public Object getSource() { | ||
return fileUri; | ||
} | ||
|
||
/** | ||
* Gets a character offset from the beginning of the source object | ||
* associated with this diagnostic that indicates the location of | ||
* the problem. In addition, the following must be true: | ||
* | ||
* <p>{@code getStartPostion() <= getPosition()} | ||
* <p>{@code getPosition() <= getEndPosition()} | ||
* | ||
* @return character offset from beginning of source; {@link | ||
* #NOPOS} if {@link #getSource()} would return {@code null} or if | ||
* no location is suitable | ||
*/ | ||
@Override | ||
public long getPosition() { | ||
return position; | ||
} | ||
|
||
/** | ||
* Gets the character offset from the beginning of the file | ||
* associated with this diagnostic that indicates the start of the | ||
* problem. | ||
* | ||
* @return offset from beginning of file; {@link #NOPOS} if and | ||
* only if {@link #getPosition()} returns {@link #NOPOS} | ||
*/ | ||
@Override | ||
public long getStartPosition() { | ||
return startPosition; | ||
} | ||
|
||
/** | ||
* Gets the character offset from the beginning of the file | ||
* associated with this diagnostic that indicates the end of the | ||
* problem. | ||
* | ||
* @return offset from beginning of file; {@link #NOPOS} if and | ||
* only if {@link #getPosition()} returns {@link #NOPOS} | ||
*/ | ||
@Override | ||
public long getEndPosition() { | ||
return endPosition; | ||
} | ||
|
||
/** | ||
* Gets the line number of the character offset returned by | ||
* {@linkplain #getPosition()}. | ||
* | ||
* @return a line number or {@link #NOPOS} if and only if {@link | ||
* #getPosition()} returns {@link #NOPOS} | ||
*/ | ||
@Override | ||
public long getLineNumber() { | ||
return lineNumber; | ||
} | ||
|
||
/** | ||
* Gets the column number of the character offset returned by | ||
* {@linkplain #getPosition()}. | ||
* | ||
* @return a column number or {@link #NOPOS} if and only if {@link | ||
* #getPosition()} returns {@link #NOPOS} | ||
*/ | ||
@Override | ||
public long getColumnNumber() { | ||
return columnNumber; | ||
} | ||
|
||
/** | ||
* Gets a diagnostic code indicating the type of diagnostic. The | ||
* code is implementation-dependent and might be {@code null}. | ||
* | ||
* @return a diagnostic code | ||
*/ | ||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
/** | ||
* Gets a localized message for the given locale. The actual | ||
* message is implementation-dependent. If the locale is {@code | ||
* null} use the default locale. | ||
* | ||
* @param locale a locale; might be {@code null} | ||
* @return a localized message | ||
*/ | ||
@Override | ||
public String getMessage(Locale locale) { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/checkerframework/languageserver/DiagnosticList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.checkerframework.languageserver; | ||
|
||
import javax.tools.Diagnostic; | ||
import javax.tools.JavaFileObject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DiagnosticList { | ||
|
||
final List<CFDiagnostic> diags; | ||
|
||
public DiagnosticList(List<Diagnostic<? extends JavaFileObject>> diagnostics) { | ||
diags = new ArrayList<>(); | ||
for (Diagnostic<? extends JavaFileObject> d: diagnostics) { | ||
diags.add(new CFDiagnostic(d)); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/checkerframework/languageserver/JavacWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.checkerframework.languageserver; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import javax.tools.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* This class wraps around javac (com.sun.tools.javac) in order to output diagnostics. | ||
* It passes parameters transparently to javac, and so for other classes it behaves exactly the same as javac and can | ||
* substitute com.sun.tools.javac.Main. | ||
*/ | ||
public class JavacWrapper { | ||
|
||
public static void main(String[] args) { | ||
JavacWrapper javacw = new JavacWrapper(); | ||
javacw.compile(args); | ||
} | ||
|
||
public void compile(String[] args) { | ||
List<String> options = new ArrayList<>(); | ||
List<String> sourcefiles = new ArrayList<>(); | ||
separateOptionsAndFiles(args, options, sourcefiles); | ||
|
||
JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); | ||
StandardJavaFileManager fileManager = javac.getStandardFileManager(null, null, null); | ||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); | ||
|
||
Iterable<? extends JavaFileObject> javaFiles = fileManager.getJavaFileObjectsFromStrings(sourcefiles); | ||
|
||
javac | ||
.getTask(null, null, diagnostics, options, null, javaFiles) | ||
.call(); | ||
|
||
DiagnosticList diags = new DiagnosticList(diagnostics.getDiagnostics()); | ||
System.out.println(new Gson().toJson(diags, DiagnosticList.class)); | ||
} | ||
|
||
private void separateOptionsAndFiles(String[] args, List<String> options, List<String> sourcefiles) { | ||
for (String a: args) { | ||
if (a.endsWith(".java")) | ||
sourcefiles.add(a); | ||
else options.add(a); | ||
} | ||
} | ||
} |