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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to