|
Re: Case insensitive and warnings [message #810235 is a reply to message #810197] |
Wed, 29 February 2012 21:54 |
|
Andrew,
Your post is a bit confusing:
Quote:I have a language which is case insensitive, but I would like to issues warnings when the wrong case is used.
What is the wrong case if the language is case-insensitive? Do you have an example of your DSL syntax that you can use to help describe what you want?
|
|
|
Re: Case insensitive and warnings [message #810249 is a reply to message #810235] |
Wed, 29 February 2012 22:22 |
|
Hi,
you can always use the node model to get the physical text behind the semantic model
following utilities might be helpful
org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(EObject)
org.eclipse.xtext.nodemodel.util.NodeModelUtils.findNodesForFeature(EObject, EStructuralFeature)
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Case insensitive and warnings [message #810290 is a reply to message #810249] |
Wed, 29 February 2012 23:41 |
Andrew Gacek Messages: 32 Registered: October 2011 |
Member |
|
|
Joey, the language is case insensitive, but there is a preferred case (based on the case with which variables were declared). I was looking for a way to allow any case, but issue a warning if the preferred case is not used.
Christian, thank you. That is exactly what I needed. Here's is what I'm doing now:
final public static String DEPRECATED_VARIABLE_CASE = "deprecated_variable_case";
@Check
public void checkVariableCase(IdExpr idExpr) {
String correctCase = idExpr.getId().getName();
ICompositeNode node = NodeModelUtils.getNode(idExpr);
String actualCase = node.getText().trim();
if (!correctCase.equals(actualCase)) {
warning("Deprecated variable case",
CasPackage.Literals.ID_EXPR__ID,
DEPRECATED_VARIABLE_CASE,
correctCase);
}
}
and I provide the following quickfix:
@Fix(CasJavaValidator.DEPRECATED_VARIABLE_CASE)
public void fixVariableCase(final Issue issue, IssueResolutionAcceptor acceptor) {
final String correct = issue.getData()[0];
acceptor.accept(issue,
"Change to " + correct,
null,
null,
new IModification() {
public void apply(IModificationContext context) throws BadLocationException {
IXtextDocument document = context.getXtextDocument();
document.replace(issue.getOffset(), issue.getLength(), correct);
}
}
);
}
Everything seems to be working great. Please let me know if I'm doing something wrong however.
Thanks again,
Andrew
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03685 seconds