-
Notifications
You must be signed in to change notification settings - Fork 63
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
Annotations #977
Annotations #977
Conversation
if (list.length != 0) | ||
commentText = list.get(0).getAttrParms.get(0).getValue.replaceAll("^\"|\"$", "") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to resolve this code duplication... Xtend's support for polymorphism seems insufficient to avoid it.
@@ -55,6 +57,7 @@ | |||
import org.eclipse.xtext.validation.Check; | |||
import org.eclipse.xtext.validation.CheckType; | |||
import org.eclipse.xtext.validation.ValidationMessageAcceptor; | |||
import org.jetbrains.annotations.NotNull; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to introduce this dependency. It will break things for Eclipse users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I build the eclipse product, and it looks like Epoch isn't broken by this dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it also seems like this can be safely removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you build Epoch? In Eclipse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is not that it would break Epoch, it would prevent developers from building Epoch in Eclipse. This is because Eclipse doesn't use Maven or Gradle but it's own build system that is severely deprived from otherwise generally accessible dependencies like this one. We've run into this issue several times before...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, got it...
/** | ||
* Specification of the structure of an annotation. | ||
*/ | ||
static class AttributeSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good candidate to factor out into its own file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything until line 1296 could be moved there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factoring out seems a bit tricky, since check()
(L1229) calls error()
, which is a protected method inherited from AbstractDeclarativeValidator
. We could move the check functions back to the validator class, but that would sort of invalidate the refactoring because most of the code is still in the validator class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could pass in a lambda?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can override the error function and just call super, this will make it visible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works like magic. Thanks for the great advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! There is some code in the validator that still needs some attention.
Shall we punt on the DSLs in the interest of getting this merged in soon? They should be a proper extension, anyway, so this can be addressed at a later time. |
/** | ||
* Search for an `@label` annotation for a given reaction. | ||
* | ||
* | ||
* @param n the reaction for which the label should be searched | ||
* @return The annotated string if an `@label` annotation was found. `null` otherwise. | ||
*/ | ||
public static String label(Reaction n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this overload could be removed if binary compatibility is not important, which seems likely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't get this comment. What binary compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone has compiled a class that depends on this method and we remove it, their class will break. Minor releases generally preserve binary compatibility. I'm not sure whether this java API is publicly supported since you've started public releases... If the only ide extensions that use the java API are in this repo then we can most likely remove it (we're also pre-1.0.0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better! Left some more comments/requests.
private static String USERNAME_REGEX = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 1743
:1758
belong in the AttributeSpec
class.
Co-authored-by: Marten Lohstroh <[email protected]>
* so that it can be called from the AttributeSpec class. | ||
*/ | ||
@Override | ||
public void error(java.lang.String message, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically you can also leave it protected. Protected visibility is subclasses + current package, so it would be visible in AttributeSpec, which is in this package. This is a detail though
The current Attribute syntax generates 2 warnings from Antlr.
It seems that the leading Any thoughts on this? @lhstrh @oowekyala |
The ambiguity comes from the "at" clause of an instantiation in combination with the annotations that can be featured inside of a reactor definition (i.e., above declarations of inputs, outputs, reactions, etc.). Once the parser encounters something like |
@lhstrh is right. One solution would be to mandate a semicolon to terminate all declarations. I also like Soroush's idea to change Host back to a string, the productions are really complicated and anyway some checking is still done in the validator: lingua-franca/org.lflang/src/org/lflang/LinguaFranca.xtext Lines 432 to 446 in b24e5b5
|
I personally think that an attribute instead of How about something like this:
and
|
While I agree that using an annotation or surrounding the host with quotes might be better, I think that for this PR it's preferable to just require the semicolon in the offending production. I think we might want to more carefully evaluate the 'at' clause and its use before changing it. We can link this convo in a new issue. |
I just want to emphasize that we don't need a semicolon on all declarations, just on instantiations that have an at clause. The impact of this change would be minimal. |
That would be a bit weird.
I'm not proposing to change its meaning in this PR. Just how it can be declared. If we convert it to an attribute, then we can of course later still have a discussion about whether to keep it or change what it does. |
* | ||
* @throws IllegalArgumentException If the node cannot have attributes | ||
*/ | ||
public static String findLabelAttribute(EObject node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense if this was in a separate class like AttributeUtils
? Same for other stuff here that relate to attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I like this idea.
Concretely, my suggestion for a quick fix to the ambiguity problem is to replace the following line on
with
|
Looks like we are ready to go? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for making all the requested changes :-)
This is a pull request tracking the progress of an annotation system in LF (#756).
This PR extends the syntax to support "attributes," which has the form
@<attrName>(<paramName1> = <paramValue1>, <paramName2> = <paramValue2>, ...)
.<paramName>
is optional, though @oowekyala pointed out that it would be good to have named parameters to conform with Java annotation grammar.As a proof of concept, the label mechanism is implemented using an
@label
attribute.Example: Label.lf
TODOs:
Duplicate AttrParm 'name'
issue.