-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
plugins { | ||
id 'java-library' | ||
} | ||
tasks.withType(JavaCompile) { | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' | ||
options.compilerArgs << '--add-exports' << 'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' | ||
} | ||
|
||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.frc5572.robotools; | ||
|
||
import org.frc5572.robotools.checks.*; | ||
Check warning on line 3 in checker/src/main/java/org/frc5572/robotools/Checks.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/Checks.java#L3 <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck>
Raw output
|
||
|
||
public class Checks { | ||
Check warning on line 5 in checker/src/main/java/org/frc5572/robotools/Checks.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/Checks.java#L5 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
private static final Check[] CHECKS = new Check[] { | ||
new ExampleCheck(), | ||
new IOCheck(), | ||
}; | ||
|
||
public static void process(CompilationData data) { | ||
Check warning on line 12 in checker/src/main/java/org/frc5572/robotools/Checks.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/Checks.java#L12 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck>
Raw output
|
||
for(Check c : CHECKS) { | ||
Check warning on line 13 in checker/src/main/java/org/frc5572/robotools/Checks.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/Checks.java#L13 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 13 in checker/src/main/java/org/frc5572/robotools/Checks.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/Checks.java#L13 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
c.check(data); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.frc5572.robotools; | ||
|
||
import javax.annotation.processing.Messager; | ||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.util.Types; | ||
import javax.tools.Diagnostic; | ||
|
||
import com.sun.source.tree.CompilationUnitTree; | ||
import com.sun.source.tree.LineMap; | ||
import com.sun.source.tree.Tree; | ||
import com.sun.source.util.JavacTask; | ||
import com.sun.source.util.SourcePositions; | ||
import com.sun.source.util.TaskEvent; | ||
import com.sun.source.util.Trees; | ||
|
||
public class CompilationData { | ||
Check warning on line 18 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L18 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
public Types types; | ||
private Trees trees; | ||
private SourcePositions positions; | ||
private CompilationUnitTree compilationUnitTree; | ||
public TypeElement element; | ||
private Messager messager; | ||
|
||
public CompilationData(Types types, Trees trees, SourcePositions positions, CompilationUnitTree compilationUnitTree, | ||
Check warning on line 27 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L27 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>
Raw output
Check warning on line 27 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L27 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck>
Raw output
|
||
TypeElement element, Messager messager) { | ||
this.types = types; | ||
this.trees = trees; | ||
this.positions = positions; | ||
this.compilationUnitTree = compilationUnitTree; | ||
this.element = element; | ||
this.messager = messager; | ||
} | ||
|
||
public CompilationData(JavacTask task, TaskEvent event) { | ||
this(task.getTypes(), Trees.instance(task), Trees.instance(task).getSourcePositions(), event.getCompilationUnit(), event.getTypeElement(), null); | ||
Check warning on line 38 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L38 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>
Raw output
|
||
} | ||
|
||
public CompilationData(ProcessingEnvironment processingEnv, TypeElement element) { | ||
this(processingEnv.getTypeUtils(), null, null, null, element, processingEnv.getMessager()); | ||
} | ||
|
||
public void error(Element element, Object object) { | ||
echo(element, object.toString(), Diagnostic.Kind.ERROR, "error", "Error"); | ||
} | ||
|
||
public void warn(Element element, Object object) { | ||
echo(element, object.toString(), Diagnostic.Kind.MANDATORY_WARNING, "warning", "Warning"); | ||
} | ||
|
||
public void note(Element element, Object object) { | ||
echo(element, object.toString(), Diagnostic.Kind.NOTE, "notice", "Note"); | ||
} | ||
|
||
private void echo(Element element, String errString, Diagnostic.Kind kind, String ghString, String humanString) { | ||
Check warning on line 57 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L57 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>
Raw output
|
||
if (compilationUnitTree == null) { | ||
messager.printMessage(kind, errString, element); | ||
} else { | ||
Tree tree = trees.getTree(element); | ||
LineMap linemap = compilationUnitTree.getLineMap(); | ||
long pos = positions.getStartPosition(compilationUnitTree, tree); | ||
long row = linemap.getLineNumber(pos); | ||
String name = compilationUnitTree.getSourceFile().toUri().toString().split("/src/")[1]; | ||
System.out.println("::" + ghString + " file=src/" + name + ",line=" + row + "::" + errString); | ||
Check warning on line 66 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L66 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>
Raw output
|
||
} | ||
} | ||
|
||
private boolean _implements(String qualifiedName, TypeElement elem) { | ||
if(elem.getQualifiedName().toString().equals(qualifiedName)) { | ||
Check warning on line 71 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L71 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 71 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L71 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return true; | ||
} | ||
Element superClass = types.asElement(elem.getSuperclass()); | ||
if(superClass instanceof TypeElement) { | ||
Check warning on line 75 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L75 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 75 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L75 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
if(_implements(qualifiedName, (TypeElement) superClass)) { | ||
Check warning on line 76 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L76 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 76 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L76 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return true; | ||
} | ||
} | ||
for(var iface : elem.getInterfaces()) { | ||
Check warning on line 80 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L80 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 80 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L80 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
Element interface_ = types.asElement(iface); | ||
if(interface_ instanceof TypeElement) { | ||
Check warning on line 82 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L82 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 82 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L82 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
if(_implements(qualifiedName, (TypeElement) interface_)) { | ||
Check warning on line 83 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L83 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 83 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L83 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean _extends(String qualifiedName, TypeElement elem) { | ||
if(elem.getQualifiedName().toString().equals(qualifiedName)) { | ||
Check warning on line 92 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L92 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 92 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L92 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return true; | ||
} | ||
Element superClass = types.asElement(elem.getSuperclass()); | ||
if(superClass instanceof TypeElement) { | ||
Check warning on line 96 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L96 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 96 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L96 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
if(_extends(qualifiedName, (TypeElement) superClass)) { | ||
Check warning on line 97 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L97 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 97 in checker/src/main/java/org/frc5572/robotools/CompilationData.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/CompilationData.java#L97 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean implementsInterface(String qualifiedName) { | ||
return _implements(qualifiedName, this.element); | ||
} | ||
|
||
public boolean implementsInterface(TypeElement e, String qualifiedName) { | ||
return _implements(qualifiedName, e); | ||
} | ||
|
||
public boolean extendsClass(String qualifiedName) { | ||
return _extends(qualifiedName, this.element); | ||
} | ||
|
||
public boolean extendsClass(TypeElement e, String qualifiedName) { | ||
return _extends(qualifiedName, e); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.frc5572.robotools; | ||
|
||
import com.sun.source.util.TreeScanner; | ||
import com.sun.source.tree.IdentifierTree; | ||
|
||
public class GetIdentifier extends TreeScanner<String, Void> { | ||
Check warning on line 6 in checker/src/main/java/org/frc5572/robotools/GetIdentifier.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/GetIdentifier.java#L6 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
@Override | ||
public String visitIdentifier(IdentifierTree node, Void p) { | ||
return node.getName().toString(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.frc5572.robotools; | ||
|
||
import javax.lang.model.util.Types; | ||
|
||
import com.sun.source.util.JavacTask; | ||
import com.sun.source.util.Plugin; | ||
import com.sun.source.util.SourcePositions; | ||
import com.sun.source.util.TaskEvent; | ||
import com.sun.source.util.TaskListener; | ||
import com.sun.source.util.Trees; | ||
|
||
public class RobotPlugin implements Plugin { | ||
Check warning on line 12 in checker/src/main/java/org/frc5572/robotools/RobotPlugin.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/RobotPlugin.java#L12 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
@Override | ||
public String getName() { | ||
return "rchk"; | ||
} | ||
|
||
@Override | ||
public void init(JavacTask task, String... arg1) { | ||
Types types = task.getTypes(); | ||
Trees trees = Trees.instance(task); | ||
SourcePositions positions = trees.getSourcePositions(); | ||
task.addTaskListener(new TaskListener() { | ||
@Override | ||
public void finished(TaskEvent e) { | ||
if (e.getKind() == TaskEvent.Kind.ANALYZE) { | ||
CompilationData data = new CompilationData(types, trees, positions, e.getCompilationUnit(), e.getTypeElement(), null); | ||
Check warning on line 28 in checker/src/main/java/org/frc5572/robotools/RobotPlugin.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/RobotPlugin.java#L28 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>
Raw output
|
||
Checks.process(data); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.frc5572.robotools; | ||
|
||
import java.util.Set; | ||
|
||
import javax.annotation.processing.AbstractProcessor; | ||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.annotation.processing.SupportedAnnotationTypes; | ||
import javax.annotation.processing.SupportedOptions; | ||
import javax.annotation.processing.SupportedSourceVersion; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ModuleElement; | ||
import javax.lang.model.element.PackageElement; | ||
import javax.lang.model.element.TypeElement; | ||
|
||
@SupportedAnnotationTypes("*") | ||
Check warning on line 17 in checker/src/main/java/org/frc5572/robotools/RobotProcessor.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/RobotProcessor.java#L17 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
@SupportedSourceVersion(SourceVersion.RELEASE_11) | ||
@SupportedOptions("frc_check.skip") | ||
public class RobotProcessor extends AbstractProcessor { | ||
|
||
private void processTypeElement(TypeElement typeElement) { | ||
for (Element e3 : typeElement.getEnclosedElements()) { | ||
if (e3 instanceof TypeElement) { | ||
processTypeElement((TypeElement) e3); | ||
} | ||
} | ||
CompilationData data = new CompilationData(processingEnv, typeElement); | ||
Checks.process(data); | ||
} | ||
|
||
private boolean hasProcessed; | ||
|
||
@Override | ||
public synchronized void init(ProcessingEnvironment processingEnv) { | ||
super.init(processingEnv); | ||
System.out.println(processingEnv.getOptions().get("frc_check.skip")); | ||
hasProcessed = false; | ||
} | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnv) { | ||
if(hasProcessed) { | ||
Check warning on line 43 in checker/src/main/java/org/frc5572/robotools/RobotProcessor.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/RobotProcessor.java#L43 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck>
Raw output
Check warning on line 43 in checker/src/main/java/org/frc5572/robotools/RobotProcessor.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/RobotProcessor.java#L43 <com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck>
Raw output
|
||
return false; | ||
} | ||
hasProcessed = true; | ||
for (ModuleElement m : processingEnv.getElementUtils().getAllModuleElements()) { | ||
if (!m.isUnnamed()) { | ||
continue; | ||
} | ||
for (Element e : m.getEnclosedElements()) { | ||
if (e instanceof PackageElement) { | ||
PackageElement pe = (PackageElement) e; | ||
if (pe.getQualifiedName().toString().startsWith("frc.")) { | ||
for (Element e2 : pe.getEnclosedElements()) { | ||
if (e2 instanceof TypeElement) { | ||
TypeElement te = (TypeElement) e2; | ||
processTypeElement(te); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.frc5572.robotools.checks; | ||
|
||
import org.frc5572.robotools.CompilationData; | ||
|
||
@FunctionalInterface | ||
Check warning on line 5 in checker/src/main/java/org/frc5572/robotools/checks/Check.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/checks/Check.java#L5 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
public interface Check { | ||
|
||
public boolean check(CompilationData data); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.frc5572.robotools.checks; | ||
|
||
import org.frc5572.robotools.CompilationData; | ||
|
||
public class ExampleCheck implements Check { | ||
Check warning on line 5 in checker/src/main/java/org/frc5572/robotools/checks/ExampleCheck.java GitHub Actions / testtool[testtool] checker/src/main/java/org/frc5572/robotools/checks/ExampleCheck.java#L5 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
@Override | ||
public boolean check(CompilationData data) { | ||
|
||
return false; | ||
} | ||
|
||
} |