Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

kapt task throws warnings about source version being less than '11' #17

Open
pramod-knidal opened this issue May 9, 2023 · 4 comments

Comments

@pramod-knidal
Copy link

kapt task throws the following warning when a project is built in android studio

Supported source version 'RELEASE_8' from annotation processor 'org.jetbrains.kotlin.kapt3.base.ProcessorWrapper' less than -source '11'

would be great if the source and target compatibility is updated to VERSION_11 like below:

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

I tried to publish jars locally and use it but the existing grammar locators stopped working.

Side Note:

I saw a comment in the code where you had noted that you were unable to include local projects in the gradle file. That can be fixed by making following changes:

in the settings.gradle in root directory

rootProject.name = 'Prism4jProject'
include 'prism4j'
project(':prism4j').name = "prism4j"
include 'prism4j-languages'
project(':prism4j-languages').name = "prism4j-languages"
include 'prism4j-bundler'
project(':prism4j-bundler').name = "prism4j-bundler"

in the prism4j-bundler module's build.gradle file you can include other local projects like this:

implementation project(path: ':prism4j')
@pramod-knidal
Copy link
Author

@noties: The prism bundler doesn't work with Jetpack Compose because of this (or related to this) issue.

> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

Here is my build.gradle file:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlin {
        jvmToolchain(11)
    }

    buildFeatures {
        buildConfig true
        viewBinding true
        compose true
    }

    composeOptions {
        kotlinCompilerExtensionVersion '1.4.7'
    }

The issue doesn't show up if I remove the kapt processing of prism4j-bundler which we use to add the Grammar for all the languages. How can I add the grammar for all the languages directly in my code? Is there a way to generate it for all languages and copy the code directly as a workaround?

@noties
Copy link
Owner

noties commented Jun 12, 2023

Hello @pramodshri-tgsys ,

yeah, the library has not been updated in some time. If you look at it - bundler just copies source files for grammars that could be found here.

Then, generated grammar locator would look like that:

public class GrammarLocatorDef implements GrammarLocator {

  @SuppressWarnings("ConstantConditions")
  private static final Prism4j.Grammar NULL =
      new Prism4j.Grammar() {
        @NotNull
        @Override
        public String name() {
          return null;
        }

        @NotNull
        @Override
        public List<Prism4j.Token> tokens() {
          return null;
        }
      };

  private final Map<String, Prism4j.Grammar> cache = new HashMap<>(3);

  @Nullable
  @Override
  public Prism4j.Grammar grammar(@NotNull Prism4j prism4j, @NotNull String language) {

    final String name = realLanguageName(language);

    Prism4j.Grammar grammar = cache.get(name);
    if (grammar != null) {
      if (NULL == grammar) {
        grammar = null;
      }
      return grammar;
    }

    grammar = obtainGrammar(prism4j, name);
    if (grammar == null) {
      cache.put(name, NULL);
    } else {
      cache.put(name, grammar);
      triggerModify(prism4j, name);
    }

    return grammar;
  }

  @NotNull
  protected String realLanguageName(@NotNull String name) {
    final String out;
    switch (name) {
      case "js":
        out = "javascript";
        break;
      case "xml":
      case "html":
      case "mathml":
      case "svg":
        out = "markup";
        break;
      case "dotnet":
        out = "csharp";
        break;
      case "jsonp":
        out = "json";
        break;
      default:
        out = name;
    }
    return out;
  }

  @Nullable
  protected Prism4j.Grammar obtainGrammar(@NotNull Prism4j prism4j, @NotNull String name) {
    final Prism4j.Grammar grammar;
    switch (name) {
      case "brainfuck":
        grammar = Prism_brainfuck.create(prism4j);
        break;
      case "c":
        grammar = Prism_c.create(prism4j);
        break;
      case "clike":
        grammar = Prism_clike.create(prism4j);
        break;
      case "clojure":
        grammar = Prism_clojure.create(prism4j);
        break;
      case "cpp":
        grammar = Prism_cpp.create(prism4j);
        break;
      case "csharp":
        grammar = Prism_csharp.create(prism4j);
        break;
      case "css":
        grammar = Prism_css.create(prism4j);
        break;
      case "css-extras":
        grammar = Prism_css_extras.create(prism4j);
        break;
      case "dart":
        grammar = Prism_dart.create(prism4j);
        break;
      case "git":
        grammar = Prism_git.create(prism4j);
        break;
      case "go":
        grammar = Prism_go.create(prism4j);
        break;
      case "groovy":
        grammar = Prism_groovy.create(prism4j);
        break;
      case "java":
        grammar = Prism_java.create(prism4j);
        break;
      case "javascript":
        grammar = Prism_javascript.create(prism4j);
        break;
      case "json":
        grammar = Prism_json.create(prism4j);
        break;
      case "kotlin":
        grammar = Prism_kotlin.create(prism4j);
        break;
      case "latex":
        grammar = Prism_latex.create(prism4j);
        break;
      case "makefile":
        grammar = Prism_makefile.create(prism4j);
        break;
      case "markdown":
        grammar = Prism_markdown.create(prism4j);
        break;
      case "markup":
        grammar = Prism_markup.create(prism4j);
        break;
      case "python":
        grammar = Prism_python.create(prism4j);
        break;
      case "scala":
        grammar = Prism_scala.create(prism4j);
        break;
      case "sql":
        grammar = Prism_sql.create(prism4j);
        break;
      case "swift":
        grammar = Prism_swift.create(prism4j);
        break;
      case "yaml":
        grammar = Prism_yaml.create(prism4j);
        break;
      default:
        grammar = null;
    }
    return grammar;
  }

  protected void triggerModify(@NotNull Prism4j prism4j, @NotNull String name) {
    switch (name) {
      case "markup":
        prism4j.grammar("css");
        prism4j.grammar("javascript");
        break;
      case "css":
        prism4j.grammar("css-extras");
        break;
    }
  }

  @Override
  @NotNull
  public Set<String> languages() {
    final Set<String> set = new HashSet<String>(25);
    set.add("brainfuck");
    set.add("c");
    set.add("clike");
    set.add("clojure");
    set.add("cpp");
    set.add("csharp");
    set.add("css");
    set.add("css-extras");
    set.add("dart");
    set.add("git");
    set.add("go");
    set.add("groovy");
    set.add("java");
    set.add("javascript");
    set.add("json");
    set.add("kotlin");
    set.add("latex");
    set.add("makefile");
    set.add("markdown");
    set.add("markup");
    set.add("python");
    set.add("scala");
    set.add("sql");
    set.add("swift");
    set.add("yaml");
    return set;
  }
}

So, it might be possible to eliminate the bundler alltogether and just use the code above directly

@pramodshri
Copy link

Thanks @noties . That should be it.

Any plans to add jetpack compose versions of Markwon? I think jetpack uses AnnotatedString instead of Spannable.

@noties
Copy link
Owner

noties commented Jun 14, 2023

Hello @pramodshri ,

Markwon renders markdown as TextView spans. So a major rework would be required to adjust to Compose AnnotatedString. Right now there is no plan for such thing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants