You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/10/29 17:10:33 UTC
[GitHub] [netbeans] jlahoda opened a new pull request, #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
jlahoda opened a new pull request, #4885:
URL: https://github.com/apache/netbeans/pull/4885
---
**^Add meaningful description above**
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
- are all your own work, and you have the right to contribute them.
- are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024281415
##########
java/java.lexer/src/org/netbeans/lib/java/lexer/JavaMultiLineStringLexer.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.lib.java.lexer;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.spi.lexer.Lexer;
+import org.netbeans.spi.lexer.LexerInput;
+import org.netbeans.spi.lexer.LexerRestartInfo;
+import org.netbeans.spi.lexer.TokenFactory;
+
+/**
+ *
+ * @author jlahoda
+ */
+public class JavaMultiLineStringLexer implements Lexer<JavaMultiLineStringTokenId> {
+
+ private final LexerInput input;
+
+ private final TokenFactory<JavaMultiLineStringTokenId> tokenFactory;
+
+ private int[] changePoints;
+ private int changePointsPointer;
+
+ public JavaMultiLineStringLexer(LexerRestartInfo<JavaMultiLineStringTokenId> info) {
+ this.input = info.input();
+ this.tokenFactory = info.tokenFactory();
+ }
+
+ @Override
+ public Token<JavaMultiLineStringTokenId> nextToken() {
+ if (changePoints == null) {
+ while (input.read() != LexerInput.EOF)
+ ;
+ String text = input.readText().toString();
+ String[] lines = text.split("\n", -1);
+ int indent = Arrays.stream(lines)
+ .mapToInt(this::leadingIndent)
+ .min()
+ .orElse(0);
+ changePoints = Arrays.stream(lines).flatMap(l -> Stream.of(indent, l.length() - indent, 1)).mapToInt(i -> i).toArray();
+ changePointsPointer = 0;
+ input.backup(input.readLengthEOF());
+ }
+ if (changePointsPointer >= changePoints.length) {
+ return null;
+ }
+ int len = 0;
+ while (len == 0)
+ len = changePoints[changePointsPointer++];
+ for (int i = 0; i < len; i++) {
+ if (input.read() == LexerInput.EOF && len == 1) {
+ return null;
+ }
+ }
+ JavaMultiLineStringTokenId id;
+ switch (changePointsPointer % 3) {
+ case 0: id = JavaMultiLineStringTokenId.NEWLINE; break;
+ case 1: id = JavaMultiLineStringTokenId.INDENT; break;
+ case 2: id = JavaMultiLineStringTokenId.TEXT; break;
+ default: throw new IllegalStateException();
+ }
+ return tokenFactory.createToken(id);
+ }
+
+ private int leadingIndent(String line) {
+ int indent = 0;
+
+ for (int i = 0; i < line.length(); i++) { //TODO: code points
+ if (Character.isWhitespace(line.charAt(i)))
+ indent++;
+ else
Review Comment:
this else block is a dead code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024286370
##########
java/java.lexer/src/org/netbeans/lib/java/lexer/JavaMultiLineStringLexer.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.lib.java.lexer;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.spi.lexer.Lexer;
+import org.netbeans.spi.lexer.LexerInput;
+import org.netbeans.spi.lexer.LexerRestartInfo;
+import org.netbeans.spi.lexer.TokenFactory;
+
+/**
+ *
+ * @author jlahoda
+ */
+public class JavaMultiLineStringLexer implements Lexer<JavaMultiLineStringTokenId> {
+
+ private final LexerInput input;
+
+ private final TokenFactory<JavaMultiLineStringTokenId> tokenFactory;
+
+ private int[] changePoints;
+ private int changePointsPointer;
+
+ public JavaMultiLineStringLexer(LexerRestartInfo<JavaMultiLineStringTokenId> info) {
+ this.input = info.input();
+ this.tokenFactory = info.tokenFactory();
+ }
+
+ @Override
+ public Token<JavaMultiLineStringTokenId> nextToken() {
+ if (changePoints == null) {
+ while (input.read() != LexerInput.EOF)
+ ;
+ String text = input.readText().toString();
+ String[] lines = text.split("\n", -1);
+ int indent = Arrays.stream(lines)
+ .mapToInt(this::leadingIndent)
+ .min()
+ .orElse(0);
+ changePoints = Arrays.stream(lines).flatMap(l -> Stream.of(indent, l.length() - indent, 1)).mapToInt(i -> i).toArray();
+ changePointsPointer = 0;
+ input.backup(input.readLengthEOF());
+ }
+ if (changePointsPointer >= changePoints.length) {
+ return null;
+ }
+ int len = 0;
+ while (len == 0)
+ len = changePoints[changePointsPointer++];
+ for (int i = 0; i < len; i++) {
+ if (input.read() == LexerInput.EOF && len == 1) {
+ return null;
+ }
+ }
+ JavaMultiLineStringTokenId id;
+ switch (changePointsPointer % 3) {
+ case 0: id = JavaMultiLineStringTokenId.NEWLINE; break;
+ case 1: id = JavaMultiLineStringTokenId.INDENT; break;
+ case 2: id = JavaMultiLineStringTokenId.TEXT; break;
+ default: throw new IllegalStateException();
+ }
+ return tokenFactory.createToken(id);
+ }
+
+ private int leadingIndent(String line) {
Review Comment:
would
return IntStream.range(0, line.length()).filter(i -> Character.isWhitespace(line.char At(i))).count();
work??
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "jlahoda (via GitHub)" <gi...@apache.org>.
jlahoda commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3529911154
Well, embedding as such is not a Java-specific feature, and already works. If you have HTML like:
```
<!DOCTYPE html>
<html>
<head>
<script>
console.log("Hello, World!");
</script>
</head>
<body>
</body>
</html>
```
what you get inside the `script` tag is embedded JavaScript. There are quite a few other embedding providers, many of them in the HTML/JavaScript area.
What cannot be done at this point is for anything to be embedded inside Java. And having Java embedded inside a bigger file is also extremely limited. (And having Java embedded inside Java is a bit of a minefield.)
There are many tricky parts here, but possibly the biggest one as follows. Consider this method:
https://github.com/apache/netbeans/blob/62a3770454446bcb421043f31f89f011e87ca1af/java/java.hints.test/src/org/netbeans/modules/java/hints/test/api/HintTest.java#L309
the content of the `code` parameter here is 100% Java. Ideally, I would prefer if, on use-sites, I didn't have to say anything to get the proper Java embedding. But to get that, the embedding can only be done after the file is parsed AND attributed, so that for a method invocation we know which method is being invoked. This is possibly the most tricky thing here.
A small part of this is that, after the code is parsed and attributed, and we need to somehow detect the language for the embedding. So we look at the annotations on the parameter. This is where the annotations are used, and they are very difficult to replace here - the source code may not be available at all, and even if it is, it would be very slow and hard to look into it. Annotations are immediately ready. Note the embedding provider is ignoring the package of the annotation, and only uses its simple name, so if needed, "anyone" can create their own `Language` annotation. There's also a positive synergy with the external annotations.
The newly-introduced Language annotation is only meant for code inside NetBeans - like from the abovementioned method. And we already have quite a few more:
https://github.com/apache/netbeans/tree/62a3770454446bcb421043f31f89f011e87ca1af/platform/api.annotations.common/src/org/netbeans/api/annotations/common
There are other heuristics included - like the variable name, and tracking how the value flows. A comment may be another heuristics (and, admittedly, the commend would not require parse&attribute). But, unless we decide that we want to abandon the embedding based on attribution altogether, the comments are not really something urgent - there are bigger fish to fry.
(Overall, I would summarize it as: I would prefer if I wasn't forced to add tags to the source code or manually specify embeddings at use sites. It would be much better if could "tag" the declarations, and the rest would "simply" work.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3263951830
One problem solved here also affects JShell Integration. Using `var` in JShell causes Exceptions and fails to work properly. The hack from 2f4dd82 together with a few followups fixes makes it work again.
I think the core problem is, that `var` is not a keyword. It is only valid when used in (local) variable declarations, so from my understanding `var` on the lexer level can only be an identifier and only the parser level can decide whether we see the identifier `var` or a local variable declaration. At least that is my take away from skimming through the JLS.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r2525122721
##########
platform/api.annotations.common/src/org/netbeans/api/annotations/common/Language.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.api.annotations.common;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to mark a specific variable so that the is expected to contain source
+ * code in a given language.
+ *
+ * @since 1.57
+ */
+@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
+@Retention(RetentionPolicy.CLASS) //TODO: can be SOURCE after PR 4882
+@Documented
+public @interface Language {
Review Comment:
would this allow as future enhancement to annotate on the class level (for example) and all blocks inside the element scope would inherit the annotation? That way tests would only have to set a single annotation on top.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024250511
##########
ide/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java:
##########
@@ -566,6 +566,25 @@ public boolean apply(Request request) {
return cancelTime == 0 ? 0 : now - cancelTime;
}
+ /*test*/ static <T extends Parser.Result> List<Embedding> callParserBaseEmbeddingProvider (
+ final @NonNull ParserBasedEmbeddingProvider<T> task,
+ final @NullAllowed T result,
+ final @NullAllowed SchedulerEvent event) {
Review Comment:
put blank line after brace cause not obvious where method body begins
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r2525136159
##########
platform/api.annotations.common/src/org/netbeans/api/annotations/common/Language.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.api.annotations.common;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to mark a specific variable so that the is expected to contain source
+ * code in a given language.
+ *
+ * @since 1.57
+ */
+@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
+@Retention(RetentionPolicy.CLASS) //TODO: can be SOURCE after PR 4882
+@Documented
+public @interface Language {
Review Comment:
```java
@Language("java")
public class Foo {
public void fooTest() {
test(
"""
// this is recognized as java
"""
);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3527287640
This needs to be a language independent feature otherwise you can add this into the JDK as a Java specific feature. Some languages doesn't have annotations afaik. A comment doesn't need to be explained with special syntax. IMHO.
Do we already have NetBeans specific annotations? Maybe I got this topic wrong.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3531615637
@jlahoda I know that we already have embeddings in NetBeans, but this is based on language standard featuures. The IDE knows script or style and knows this is JS or CSS and so on. But this is because the parser knows those tags that are not artificial.
This example here in JS will break and will not compile, if we will have this as an annotation:
```JavaScript
@Language("sql")
const sqlString = "SELECT * FROM users WHERE age > 30 AND city = 'New York'";
function foo(@Language("sql") sql) {
return null
}
```
This is why i mean this should be a language independent feature if we want to be handled this by the IDE. FOr java there is maybe not a problem of custom annotations, but I also need to ask my self when I use VS Code or any other IDE, what this annotation makes. This will unfortunately not work for other languages than Java.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] mbien commented on pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
mbien commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-1295948800
awesome feature. I remember one of my first thoughts when hearing that java was getting multi line strings was that NetBeans is pretty good with embedding other languages - this would make a great match.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3522015509
Is this only a Java in NetBeans feature? I mean we can also have SQL in strings in JS, PHP and also HTML in JS and in PHP etc. This would be very nice to handle multi embedding in strings in different languages. Had just a quick look and it seemed more or less just for Java atm? IntelliJ handles this with a comment for permanent injection or with a hint for strings with temporarely injection: https://www.jetbrains.com/help/idea/using-language-injections.html.
Is it really common to make annotations per IDE? The Matisse GUI editor is using smth like this for make the code readonly `// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents`. Don't get me wrong, I really like the feature but when I see annotation I think of "@language" and this is not what I want to see in my code. A comment is more clear IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-3531703650
At the end, I just wanted to say, that I like the feature but I prefer a more intuitive way of using that what we already have like comments across languages. I'm also not blocking this feature if an annotation is the preferred way,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024273281
##########
java/java.editor.base/src/org/netbeans/modules/java/editor/base/embedding/EmbeddingProviderImpl.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.editor.base.embedding;
+
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map.Entry;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.lexer.Language;
+import org.netbeans.api.lexer.PartType;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.parsing.api.Embedding;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.netbeans.modules.parsing.spi.Parser;
+import org.netbeans.modules.parsing.spi.ParserBasedEmbeddingProvider;
+import org.netbeans.modules.parsing.spi.Scheduler;
+import org.netbeans.modules.parsing.spi.SchedulerTask;
+import org.netbeans.modules.parsing.spi.TaskFactory;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class EmbeddingProviderImpl extends ParserBasedEmbeddingProvider<Parser.Result> {
+
+ public EmbeddingProviderImpl() {
+ super();
+ }
+
+ @Override
+ public List<Embedding> getEmbeddings(Parser.Result result) {
+ CompilationController info = CompilationController.get(result);
+ if (info == null) {
+ return Collections.emptyList();
+ }
+ List<Embedding> embeddings = new ArrayList<>();
+ TokenSequence<?> ts = TokenHierarchy.get(info.getSnapshot().getSource().getDocument(true)).tokenSequence(); //XXX: locking!
+ ts.moveStart();
+ while (ts.moveNext()) {
+ if (ts.token().id() == JavaTokenId.MULTILINE_STRING_LITERAL && ts.token().partType() == PartType.COMPLETE) {
+ String language = findLanguageFromTarget(info, ts.offset() + 1);
+ String mimeType = language != null ? mapLanguageToMimeType(language) : null;
+ if (mimeType == null) {
+ continue;
+ }
+ List<Embedding> parts = embeddingsForTextBlockContent(result.getSnapshot(), ts, mimeType);
+ if (!parts.isEmpty()) {
+ embeddings.add(Embedding.create(parts));
+ }
+ }
+ }
+ return embeddings;
+ }
+
+ private static String findLanguageFromTarget(CompilationController info, int pos) {
+ try {
+ info.toPhase(JavaSource.Phase.RESOLVED); //TODO - improve, avoid resolved if at all possible
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ return null;
+ }
+ TreePath tp = info.getTreeUtilities().pathFor(pos);
+ if (tp.getLeaf().getKind() != Kind.STRING_LITERAL) {
+ return null;
+ }
+ VariableElement target = null;
+ switch (tp.getParentPath().getLeaf().getKind()) {
+ case METHOD_INVOCATION: {
+ int argPos = ((MethodInvocationTree) tp.getParentPath().getLeaf()).getArguments().indexOf(tp.getLeaf());
+ if (argPos == (-1)) {
+ break;
+ }
+ Element el = info.getTrees().getElement(tp.getParentPath());
+ if (el == null || (el.getKind() != ElementKind.METHOD && el.getKind() != ElementKind.CONSTRUCTOR)) {
+ break;
+ }
+ target = ((ExecutableElement) el).getParameters().get(argPos);
+ break;
+ }
+ case VARIABLE: {
+ target = (VariableElement) info.getTrees().getElement(tp.getParentPath());
+ break;
+ }
+ }
+ if (target == null) {
+ return null;
+ }
+ for (AnnotationMirror am : target.getAnnotationMirrors()) {
Review Comment:
lines 124 to 133 look loke a candidate for a private static method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024267227
##########
java/java.editor.base/src/org/netbeans/modules/java/editor/base/embedding/EmbeddingProviderImpl.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.editor.base.embedding;
+
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map.Entry;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.lexer.Language;
+import org.netbeans.api.lexer.PartType;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.parsing.api.Embedding;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.netbeans.modules.parsing.spi.Parser;
+import org.netbeans.modules.parsing.spi.ParserBasedEmbeddingProvider;
+import org.netbeans.modules.parsing.spi.Scheduler;
+import org.netbeans.modules.parsing.spi.SchedulerTask;
+import org.netbeans.modules.parsing.spi.TaskFactory;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class EmbeddingProviderImpl extends ParserBasedEmbeddingProvider<Parser.Result> {
+
+ public EmbeddingProviderImpl() {
+ super();
+ }
+
+ @Override
+ public List<Embedding> getEmbeddings(Parser.Result result) {
+ CompilationController info = CompilationController.get(result);
+ if (info == null) {
+ return Collections.emptyList();
+ }
+ List<Embedding> embeddings = new ArrayList<>();
+ TokenSequence<?> ts = TokenHierarchy.get(info.getSnapshot().getSource().getDocument(true)).tokenSequence(); //XXX: locking!
+ ts.moveStart();
+ while (ts.moveNext()) {
+ if (ts.token().id() == JavaTokenId.MULTILINE_STRING_LITERAL && ts.token().partType() == PartType.COMPLETE) {
+ String language = findLanguageFromTarget(info, ts.offset() + 1);
+ String mimeType = language != null ? mapLanguageToMimeType(language) : null;
+ if (mimeType == null) {
+ continue;
+ }
+ List<Embedding> parts = embeddingsForTextBlockContent(result.getSnapshot(), ts, mimeType);
+ if (!parts.isEmpty()) {
+ embeddings.add(Embedding.create(parts));
+ }
+ }
+ }
+ return embeddings;
+ }
+
+ private static String findLanguageFromTarget(CompilationController info, int pos) {
+ try {
+ info.toPhase(JavaSource.Phase.RESOLVED); //TODO - improve, avoid resolved if at all possible
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ return null;
+ }
+ TreePath tp = info.getTreeUtilities().pathFor(pos);
+ if (tp.getLeaf().getKind() != Kind.STRING_LITERAL) {
+ return null;
+ }
+ VariableElement target = null;
+ switch (tp.getParentPath().getLeaf().getKind()) {
+ case METHOD_INVOCATION: {
+ int argPos = ((MethodInvocationTree) tp.getParentPath().getLeaf()).getArguments().indexOf(tp.getLeaf());
+ if (argPos == (-1)) {
+ break;
+ }
+ Element el = info.getTrees().getElement(tp.getParentPath());
+ if (el == null || (el.getKind() != ElementKind.METHOD && el.getKind() != ElementKind.CONSTRUCTOR)) {
+ break;
+ }
+ target = ((ExecutableElement) el).getParameters().get(argPos);
+ break;
+ }
+ case VARIABLE: {
+ target = (VariableElement) info.getTrees().getElement(tp.getParentPath());
+ break;
+ }
+ }
+ if (target == null) {
+ return null;
+ }
+ for (AnnotationMirror am : target.getAnnotationMirrors()) {
+ if (am.getAnnotationType().asElement().getSimpleName().contentEquals("Language")) {
+ for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : am.getElementValues().entrySet()) {
+ if (e.getKey().getSimpleName().contentEquals("value")) {
+ return (String) e.getValue().getValue();
+ }
+ }
+ }
+ }
+ return target.getSimpleName().toString();
+ }
+
+ private static String mapLanguageToMimeType(String language) {
+ String candidate = null;
+ FileObject editors = FileUtil.getConfigFile("Editors");
+ for (FileObject primary : editors.getChildren()) {
+ for (FileObject secondary : primary.getChildren()) {
+ if (secondary.getNameExt().equalsIgnoreCase(language)) {
+ return primary.getNameExt() + "/" + secondary.getNameExt();
+ } else if (secondary.getNameExt().equalsIgnoreCase("x-" + language)) {
Review Comment:
"x-".concat(language) may give a little performance improvement
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024256361
##########
java/java.editor.base/src/org/netbeans/modules/java/editor/base/embedding/EmbeddingProviderImpl.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.editor.base.embedding;
+
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map.Entry;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.lexer.Language;
+import org.netbeans.api.lexer.PartType;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.parsing.api.Embedding;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.netbeans.modules.parsing.spi.Parser;
+import org.netbeans.modules.parsing.spi.ParserBasedEmbeddingProvider;
+import org.netbeans.modules.parsing.spi.Scheduler;
+import org.netbeans.modules.parsing.spi.SchedulerTask;
+import org.netbeans.modules.parsing.spi.TaskFactory;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class EmbeddingProviderImpl extends ParserBasedEmbeddingProvider<Parser.Result> {
+
+ public EmbeddingProviderImpl() {
+ super();
+ }
+
+ @Override
+ public List<Embedding> getEmbeddings(Parser.Result result) {
+ CompilationController info = CompilationController.get(result);
+ if (info == null) {
+ return Collections.emptyList();
+ }
+ List<Embedding> embeddings = new ArrayList<>();
+ TokenSequence<?> ts = TokenHierarchy.get(info.getSnapshot().getSource().getDocument(true)).tokenSequence(); //XXX: locking!
+ ts.moveStart();
+ while (ts.moveNext()) {
+ if (ts.token().id() == JavaTokenId.MULTILINE_STRING_LITERAL && ts.token().partType() == PartType.COMPLETE) {
+ String language = findLanguageFromTarget(info, ts.offset() + 1);
+ String mimeType = language != null ? mapLanguageToMimeType(language) : null;
+ if (mimeType == null) {
Review Comment:
would inverting the comparison and removing continue improve readability
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] neilcsmith-net commented on pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#issuecomment-1511056936
This is still marked as a draft, so removing the milestone entirely rather than bumping forward to NB19. Please add a milestone back when you feel it's ready for merging.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #4885: A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language.
Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r1024280508
##########
java/java.lexer/src/org/netbeans/lib/java/lexer/JavaMultiLineStringLexer.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.lib.java.lexer;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+import org.netbeans.api.java.lexer.JavaMultiLineStringTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.spi.lexer.Lexer;
+import org.netbeans.spi.lexer.LexerInput;
+import org.netbeans.spi.lexer.LexerRestartInfo;
+import org.netbeans.spi.lexer.TokenFactory;
+
+/**
+ *
+ * @author jlahoda
+ */
+public class JavaMultiLineStringLexer implements Lexer<JavaMultiLineStringTokenId> {
+
+ private final LexerInput input;
+
+ private final TokenFactory<JavaMultiLineStringTokenId> tokenFactory;
+
+ private int[] changePoints;
+ private int changePointsPointer;
+
+ public JavaMultiLineStringLexer(LexerRestartInfo<JavaMultiLineStringTokenId> info) {
+ this.input = info.input();
+ this.tokenFactory = info.tokenFactory();
+ }
+
+ @Override
+ public Token<JavaMultiLineStringTokenId> nextToken() {
+ if (changePoints == null) {
+ while (input.read() != LexerInput.EOF)
+ ;
+ String text = input.readText().toString();
+ String[] lines = text.split("\n", -1);
+ int indent = Arrays.stream(lines)
+ .mapToInt(this::leadingIndent)
+ .min()
+ .orElse(0);
+ changePoints = Arrays.stream(lines).flatMap(l -> Stream.of(indent, l.length() - indent, 1)).mapToInt(i -> i).toArray();
+ changePointsPointer = 0;
+ input.backup(input.readLengthEOF());
+ }
+ if (changePointsPointer >= changePoints.length) {
+ return null;
+ }
+ int len = 0;
+ while (len == 0)
+ len = changePoints[changePointsPointer++];
+ for (int i = 0; i < len; i++) {
+ if (input.read() == LexerInput.EOF && len == 1) {
+ return null;
+ }
+ }
+ JavaMultiLineStringTokenId id;
Review Comment:
lines 74 to 80 look like a candidate for private method
private JavaMultiLineStringTokenId idFromPointer() {
switch (changePointsPointer % 3) {
case 0: id = return JavaMultiLineStringTokenId.NEWLINE;
case 1: id = return JavaMultiLineStringTokenId.INDENT;
case 2: id = return JavaMultiLineStringTokenId.TEXT;
default: throw new IllegalStateException();
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] A prototype of code that allows code embedded using TextBlocks; also adds support for Java as an embedded language. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #4885:
URL: https://github.com/apache/netbeans/pull/4885#discussion_r2525512195
##########
platform/api.annotations.common/src/org/netbeans/api/annotations/common/Language.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.api.annotations.common;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to mark a specific variable so that the is expected to contain source
+ * code in a given language.
+ *
+ * @since 1.57
+ */
+@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
+@Retention(RetentionPolicy.CLASS) //TODO: can be SOURCE after PR 4882
+@Documented
+public @interface Language {
Review Comment:
or does this work the other way around: if the `String` parameter of the `test()` method is annotated, NB will know that the text block of the example above is a java snippet?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists