Skip to content

Ast #9

@HanzoDev1375

Description

@HanzoDev1375

void debug() {
try {

  // Create an instance of swc4j.
  Swc4j swc4j = new Swc4j();
  // Prepare a TypeScript code snippet.
  String code = "function add(a:number, b:number) { return a+b; }";
  // Prepare a script name.
  URL specifier = new URL("file:///storage/emulated/0/Apktool_M/abc.ts");
  // Prepare an option with script name and media type.
  Swc4jTranspileOptions options =
      new Swc4jTranspileOptions()
          .setSpecifier(specifier)
          .setMediaType(Swc4jMediaType.TypeScript)
          // Set capture tokens.
          .setCaptureTokens(true)
          .setParseMode(Swc4jParseMode.Script);
  // Parse the code.
  Swc4jParseOutput output = swc4j.parse(code, options);
  // Print the tokens.
  System.out.println("/*********************************************");
  System.out.println("         The tokens are as follows.");
  System.out.println("*********************************************/");
  output.getTokens().forEach(it ->{
	  binding.editor.setText(it.getSpan().getLine()+ it.getSpan().getColumn());
  });
} catch (Exception err) {
	
    binding.editor.setText(err.getLocalizedMessage());
}

}

Hello, I took this Java code from your blog. I just have one question. Why are the lines and columns not printed in my EditText when the code has an error in the for loop?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions