Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions java/ql/src/printAst.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @name Print AST
* @description Outputs a representation of a file's Abstract Syntax Tree. This
* query is used by the VS Code extension.
* @id java/print-ast
* @kind graph
* @tags ide-contextual-queries/print-ast
*/

import java
import semmle.code.java.PrintAst
import definitions

/**
* The source file to generate an AST from.
*/
external string selectedSourceFile();

class PrintAstConfigurationOverride extends PrintAstConfiguration {
/**
* Holds if the location matches the selected file in the VS Code extension and
* the element is `fromSource`.
*/
override predicate shouldPrint(Element e, Location l) {
super.shouldPrint(e, l) and
l.getFile() = getEncodedFile(selectedSourceFile())
}
}
13 changes: 13 additions & 0 deletions java/ql/src/semmle/code/Location.qll
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ class Top extends @top {
/** Gets a textual representation of this element. */
cached
string toString() { hasName(this, result) }

/**
* Gets the name of a primary CodeQL class to which this element belongs.
*
* For most elements, this is simply the most precise syntactic category to
* which they belong; for example, `AddExpr` is a primary class, but
* `BinaryExpr` is not.
*
* This predicate always has a result. If no primary class can be
* determined, the result is `"???"`. If multiple primary classes match,
* this predicate can have multiple results.
*/
string getAPrimaryQlClass() { result = "???" }
}

/** A location maps language elements to positions in source files. */
Expand Down
2 changes: 2 additions & 0 deletions java/ql/src/semmle/code/java/Annotation.qll
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Annotation extends @annotation, Expr {
if value instanceof ArrayInit then result = value.(ArrayInit).getAnInit() else result = value
)
}

override string getAPrimaryQlClass() { result = "Annotation" }
}

/** An `Annotation` that applies to a declaration. */
Expand Down
2 changes: 2 additions & 0 deletions java/ql/src/semmle/code/java/CompilationUnit.qll
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class CompilationUnit extends Element, File {
* Gets the module associated with this compilation unit, if any.
*/
Module getModule() { cumodule(this, result) }

override string getAPrimaryQlClass() { result = "CompilationUnit" }
}
Loading