Home » Modeling » TMF (Xtext) » Check Type of Element
| | |
Re: Check Type of Element [message #1021333 is a reply to message #1020779] |
Tue, 19 March 2013 22:06 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
My question is scoping,I write custom validation for drive name (drive name starting with upper case and one character ).I written a validation with above grammar ,but my warning shows all line I want to my warning shows only Drive name.I do not solving this problem :
My validation code :
@Check
public void CheckDriveName(Drive d){
if(d.getName().length()!=1){
error(" 'Drive' name must be one character " ,null,FilesystemPackage.DRIVE__NAME,
NVALID_DRIVENAME, d.getName());
}else if (Character.isLowerCase(d.getName().charAt(0)) ){
warning(" Drive name should start with uppercase " ,null,FilesystemPackage.DRIVE__NAME,INVALID_DRIVENAME,d.getName());
}
}
I upload my language screenshot
|
|
| | | | |
Re: Check Type of Element [message #1021423 is a reply to message #1021372] |
Wed, 20 March 2013 03:32 |
|
Hi,
since you use a derived metamodel (at least i think so) the featrue may be in a parent class (so have a look where the getName() is in the Java Classes
so in your case you may have to call org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(String, EObject, EStructuralFeature, int)
like
error("message", drive, YourPackage.Literals. Sync_Element__NAME, -1) or something like that
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: Check Type of Element [message #1021533 is a reply to message #1021423] |
Wed, 20 March 2013 09:26 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi christian ,
I write validation for Sync .if source is a file type Target must be file.I cehck this case but I want to write quick fix if source is a file, for targer comes files types or just the opposite.I hope understand my problem.I solved this problem How solved
@Check
public void Checkscyn(Sync s){
SyncElement synsource = s.getSource();
SyncElement syntarget = s.getTarget();
if(synsource.eClass() != syntarget.eClass()){
error(" synchronization is incorrect ,use same type element",null, FilesystemPackage.SYNC__NAME,
INVALID_SYCN,s.getName());
}
}
Ouick fix:
@Fix(FilesystemJavaValidator.INVALID_SYCN)
public void fixSourceTarger(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Choose" , " '" + issue.getData()[0]+ "'", "gggg", new ISemanticModification() {
public void apply(EObject element , IModificationContext context){
((Sync)element).setName(issue.getData()[0]);
System.out.println( ((Sync)element).getSource().getName());
System.out.println(issue.getData()[0]);
}
}
);
}
|
|
| | | |
Re: Check Type of Element [message #1021708 is a reply to message #1021696] |
Wed, 20 March 2013 14:46 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
sory I can't understand . I want to bring Drive Name at the quick fix for example ,C
.User select these one.I put Drive name in a list but ı can t call this function.
I try this code but I do not bring related type.
@Fix( FilesystemJavaValidator.INVALID_SYCN)
public void createsycn(final Issue issue,IssueResolutionAcceptor acceptor){
final String linkText = issue.getData()[0];
acceptor.accept(issue, "Create entity '" + linkText+ "'", "Create entity '" + linkText+ "'", null,
new ISemanticModification() {
public void apply(EObject element, IModificationContext context)
{ SyncElement a = null;
Checkscyn(a );
// TODO Auto-generated method stub
}
public void Checkscyn(SyncElement s){
Drive d = EcoreUtil2.getContainerOfType(s, Drive.class);
List<Drive> drivelist = EcoreUtil2.getAllContentsOfType(d,Drive.class);
System.out.println(drivelist);
}
});
createLinkingIssueResolutions(issue, acceptor);
}
|
|
| | | | |
Re: Check Type of Element [message #1021843 is a reply to message #1021836] |
Wed, 20 March 2013 19:27 |
|
public class MyDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix("code")
public void createsycn(final Issue issue,IssueResolutionAcceptor acceptor){
final String linkText = issue.getData()[0];
acceptor.accept(issue, "Create entity '" + linkText+ "'", "Create entity '" + linkText+ "'", null,
new ISemanticModification() {
public void apply(EObject element, IModificationContext context)
{
Sync d = (Sync)element;
Filesystem fs = EcoreUtil2.getContainerOfType(d, Filesystem.class);
for (File fx : EcoreUtil2.getAllContentsOfType(fs, File.class)) {
System.out.println(fx.getName());
}
}
});}
}
public class MyDslJavaValidator extends AbstractMyDslJavaValidator {
@Check
public void Checkscyn(Sync s){
SyncElement synsource = s.getSource();
SyncElement syntarget = s.getTarget();
if(synsource.eClass() != syntarget.eClass()){
error(" synchronization is incorrect ,use same type element",s, MyDslPackage.Literals.SYNC__NAME,"code",s.getName());
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: Check Type of Element [message #1021861 is a reply to message #1021845] |
Wed, 20 March 2013 20:20 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Thank you very much for your interest.I'm sorry because I'm new to these issues and having trouble understanding.I try these code but fx.getName() not get in the quick fix dialog page.I want to choose fx.getName for target.in addition I try createLinkingIssueResolutions(Issue, IssueResolutionAcceptor) but parameters wrong ,I am not define correct parameters for createLinkingIssueResolutions.
@Fix( FilesystemJavaValidator.INVALID_SYCN)
public void createsycn(final Issue issue,IssueResolutionAcceptor acceptor){
final String linkText = issue.getData()[0];
acceptor.accept(issue, "choose same type '" + linkText+ "'", "null '" + linkText+ "'", null,
new ISemanticModification() {
public void apply(EObject element, IModificationContext context)
{
Sync d = (Sync)element;
Filesystem fs = EcoreUtil2.getContainerOfType(d, Filesystem.class);
for (File fx : EcoreUtil2.getAllContentsOfType(fs, File.class)) {
System.out.println(fx.getName());
}
}
});
}
|
|
|
Re: Check Type of Element [message #1021876 is a reply to message #1021861] |
Wed, 20 March 2013 20:58 |
|
Hi,
you have no linking issue so you cannot use it. and it wont solve your problem since the cross ref is valid by semantics of scoping/linking
i just told you to get an idea how a similar not the same problem is solved.
the link text problem i cannot reproduce
the quickfix has the text. Create entity 'xxxx'
sooooooo i have still no clue at all what your problem is. i do not want to do your work.
and a am distrubed by your context switches.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Check Type of Element [message #1021879 is a reply to message #1021876] |
Wed, 20 March 2013 21:06 |
|
So i would have expected that you would build something like
public class MyDslQuickfixProvider extends DefaultQuickfixProvider {
@Inject
private IssueModificationContext.Factory modificationContextFactory;
@Fix("code")
public void createsycn(final Issue issue, final IssueResolutionAcceptor acceptor){
final IModificationContext modificationContext = modificationContextFactory.createModificationContext(issue);
final IXtextDocument xtextDocument = modificationContext.getXtextDocument();
if (xtextDocument == null)
return;
xtextDocument.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
Sync sync = (Sync) state.getEObject(issue.getUriToProblem().fragment());
Filesystem fs = EcoreUtil2.getContainerOfType(sync, Filesystem.class);
if (sync.getSource() instanceof Folder) {
for (final Folder fx : EcoreUtil2.getAllContentsOfType(fs, Folder.class)) {
acceptor.accept(issue, fx.getName(), "Folder " + fx.getName(), null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context)
throws Exception {
((Sync)element).setTarget(fx);
}
});
}
} else if (sync.getSource() instanceof File) {
for (final File fx : EcoreUtil2.getAllContentsOfType(fs, File.class)) {
acceptor.accept(issue, fx.getName(), "File " + fx.getName(), null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context)
throws Exception {
((Sync)element).setTarget(fx);
}
});
}
}
}
});
}
}
yourself
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 03:20:55 GMT 2024
Powered by FUDForum. Page generated in 0.06663 seconds
|