google / summit-ast Goto Github PK
View Code? Open in Web Editor NEWSummit-AST translates parsed Apex source code into an abstract syntax tree
License: Apache License 2.0
Summit-AST translates parsed Apex source code into an abstract syntax tree
License: Apache License 2.0
The io_bazel_rules_kotlin plug-in fails with:
Error in repository_rule: invalid user-provided repo name '': valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter
Unknown / shouldn't say "Found 0 Apex source files" nor "Failed to build AST for 0 files"
❯ bazel run :SummitTool './AccountController.cls'
INFO: Analyzed target //:SummitTool (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //src/main/java/com/google/summit:SummitTool up-to-date:
bazel-bin/src/main/java/com/google/summit/SummitTool.jar
bazel-bin/src/main/java/com/google/summit/SummitTool.jdeps
INFO: Elapsed time: 0.085s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/src/main/java/com/google/summit/SummitTool ./AccountController.cls
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
INFO: Summit AST Tool
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
INFO: Usage: SummitTool <Apex files or search directories>
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
INFO: Searching for Apex source at: ./AccountController.cls
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
WARNING: Invalid path ./AccountController.cls
java.nio.file.NoSuchFileException: ./AccountController.cls
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:149)
at java.base/java.nio.file.Files.readAttributes(Files.java:1764)
at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
at java.base/java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:71)
at java.base/java.nio.file.Files.find(Files.java:3942)
at com.google.summit.SummitTool.main(SummitTool.kt:52)
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
INFO: Found 0 Apex source files
Feb 24, 2024 5:54:03 PM com.google.summit.SummitTool main
INFO: Failed to build AST for 0 files
git clone https://github.com/google/summit-ast google/summit-ast
cd google/summit-ast
export JAVA_HOME="$(dirname $(dirname $(realpath $(which javac))))"
AccountController.cls
in project using this content:public class AccountController {
public static Account getAccount() {
return new Account();
}
}
bazel run :SummitTool './AccountController.cls'
or bazel run :SummitTool 'AccountController.cls'
Running bazel run :SummitTool './Lead_Utility.cls
will output some basic information and provide an in-memory AST.
Running the command produces the following error:
FATAL: ExecuteProgram(C:\users\michael\_bazel_michael\k757sjdo\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\src\main\java\com\google\summit\SummitTool) failed: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\michael\_bazel_michael\k757sjdo\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\src\main\java\com\google\summit\SummitTool" C:\Users\Michael\Desktop\repos\summit-ast\Lead_Utility.cls): %1 is not a valid Win32 application. (error: 193)
git clone https://github.com/google/summit-ast.git
bazel build
bazel run :SummitTool './Lead_Utility.cls'
I've tried several variations for the path with forward/backward slashes, with/without single quotes, and the full path.
Correctly parse SOSL using USER_MODE
It does seem Salesforce SOSL documentation doesn't list this... https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_syntax.htm
Warning: PMD failed to evaluate against file 'C:\Users\xx\repos\xx\force-app\main\default\classes\class.cls'. Message: ParseException: Parse exception: com.google.summit.SummitAST$ParseException: Failed to parse C:\Users\xx\repos\xx\force-app\main\default\classes\xx.cls: Syntax error at 29:13: no viable alternative at input 'WITH USER_MODE'
Syntax error at 30:6: extraneous input ']' expecting ';'
public inherited sharing class soqlExample {
public static String example(){
String SecondarySearchList = 'test';
List<List<SObject>> accountList = [
FIND :SecondarySearchList
IN NAME FIELDS
RETURNING Account(Id, Account.Name WHERE ID = '' LIMIT 100)
WITH USER_MODE
];
}
}
I should be able to use Bazel to build an application which uses Summit-AST as a dependency and use the files internally within my custom application.
I encounter a runtime error when trying to call SummitAST.parseAndTranslate
in a separate program.
Now, this could just be my lack of Kotlin knowledge showing, so I will keep trying to figure this one out, but I figured it best to at least create the issue to track my efforts here.
Is there a better or more canonical way to produce the AST for a .cls
or .trigger
file from a given file path?
.
├── BUILD
├── MODULE.bazel
├── MODULE.bazel.lock
├── WORKSPACE
└── src
└── main
└── java
└── com
└── app
├── ASTParser.java
├── BUILD
└── Runner.java
BUILD
java_binary(
name = "astparser",
runtime_deps = ["//src/main/java/com/app:apexparser-runner"],
main_class = "com.app.Runner",
)
src/main/java/com/app/BUILD
java_library(
name = "maven_deps",
exports = [
"@maven//:com_google_summit_summit_ast"
],
visibility = ["//visibility:public"],
)
java_library(
name = "apexparser-runner",
srcs = [
"ASTParser.java",
"Runner.java",
],
deps = [
":maven_deps",
],
visibility = ["//visibility:public"],
)
Runner.java
public static void main(String[] args) {
new ASTParser().parse(args[0]);
}
ASTParser.java
package com.app;
import java.nio.file.Paths;
import com.google.summit.SummitAST;
import com.google.summit.ast.CompilationUnit;
public class ASTParser {
public void parse(String path) {
CompilationUnit result = SummitAST.parseAndTranslate(Paths.get(path)); // this errors out
}
}
bazel run :astparser foo/bar.cls
Error Message:
error: non-static method parseAndTranslate(Path) cannot be referenced from a static context
CompilationUnit result = SummitAST.parseAndTranslate(Paths.get(path));
Then if I update the code to instantiate an object
CompilationUnit result = new SummitAST().parseAndTranslate(Paths.get(path));
I get this:
error: SummitAST() has private access in SummitAST
CompilationUnit result = new SummitAST().parseAndTranslate(Paths.get(path));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.