Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Added support for constants #3507

Merged
merged 26 commits into from Jul 29, 2022

Conversation

wangliang181230
Copy link
Contributor

@wangliang181230 wangliang181230 commented Jul 26, 2022

Java: Added support for constants.

@github-actions
Copy link

github-actions bot commented Jul 26, 2022

JS File Size Changes (gzipped)

A total of 2 files have changed, with a combined diff of +24 B (+1.3%).

file master pull size diff % diff
components/prism-java.min.js 1.2 KB 1.21 KB +17 B +1.4%
components/prism-scala.min.js 703 B 710 B +7 B +1.0%

Generated by 🚫 dangerJS against 5b44cda

@wangliang181230 wangliang181230 changed the title Java: added support for variables, witch read from the window.PrismConfig Java: Added support for variables, witch read from the window.PrismConfig Jul 26, 2022
@RunDevelopment
Copy link
Member

If users really wanted to add their own Java variables, they could just do Prism.language.java['variable'] = /\b(?:foo|bar)\b/. Why is your new PrismConfig necessary?

@wangliang181230
Copy link
Contributor Author

If users really wanted to add their own Java variables, they could just do Prism.language.java['variable'] = /\b(?:foo|bar)\b/. Why is your new PrismConfig necessary?

Wait a minute, I also found this problem, so I'm developing a better solution.

@wangliang181230 wangliang181230 changed the title Java: Added support for variables, witch read from the window.PrismConfig Java: Added support for constants and variables Jul 26, 2022
@wangliang181230
Copy link
Contributor Author

wangliang181230 commented Jul 26, 2022

If users really wanted to add their own Java variables, they could just do Prism.language.java['variable'] = /\b(?:foo|bar)\b/. Why is your new PrismConfig necessary?

done

components/prism-java.js Outdated Show resolved Hide resolved
components/prism-java.js Outdated Show resolved Hide resolved
@wangliang181230 wangliang181230 changed the title Java: Added support for constants and variables Java: Added support for constants Jul 26, 2022
@RunDevelopment
Copy link
Member

One last nit. It's good to go otherwise.

@wangliang181230
Copy link
Contributor Author

wangliang181230 commented Jul 27, 2022

@RunDevelopment

图片

@wangliang181230 wangliang181230 changed the title Java: Added support for constants Java: Added support for constants and variables Jul 27, 2022
@RunDevelopment
Copy link
Member

BB

Most of the class name detect works on naming conventions:

  1. Class names start with an uppercase letter and contain at least one lowercase letter. E.g. String.
  2. Class names are a single uppercase letter. E.g. T (for generics).

BB is a false negative that we cannot resolve without compiling the Java code. Just BB without context could be a static field (constant) or a type. There is no way to know based on the name alone.
Yes, BB is declared in <A, BB>, but we would need an AST to know that, and Prism doesn't build an AST. Prism only produces a token stream.

@wangliang181230 wangliang181230 changed the title Java: Added support for constants and variables Java: Added support for constants, variables and generic parameters Jul 27, 2022
components/prism-java.js Outdated Show resolved Hide resolved
components/prism-java.js Outdated Show resolved Hide resolved
@wangliang181230 wangliang181230 changed the title Java: Added support for constants, variables and generic parameters Java: Added support for constants and generic parameters Jul 28, 2022
@wangliang181230 wangliang181230 changed the title Java: Added support for constants and generic parameters Java: Added support for constants Jul 29, 2022
@RunDevelopment RunDevelopment merged commit 342a003 into PrismJS:master Jul 29, 2022
@RunDevelopment
Copy link
Member

Thank you for contributing @wangliang181230!

@wangliang181230 wangliang181230 deleted the java-variable branch July 29, 2022 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants