Home » Modeling » TMF (Xtext) » Formating with Xtend
Formating with Xtend [message #1053646] |
Tue, 07 May 2013 06:46 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi all,
I update Xtext framework .but I have problem.I written pure java code previosly but now Formatting class is a xtend class.
My code for formating :
public class FilesystemFormatter extends AbstractDeclarativeFormatter {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
// c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
// c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
// c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
@Override
protected void configureFormatting(FormattingConfig c) {
FilesystemGrammarAccess f = (FilesystemGrammarAccess) getGrammarAccess();
c.setAutoLinewrap(120);
//c.setLinewrap(1).after(f.getFileAccess().getSemicolonKeyword_0_2_1());
//c.setWrappedLineIndentation(f.getFileAccess().getSemicolonKeyword_0_2_1()) ;
c.setLinewrap(1, 2, 3).around(f.getFilesystemRule());
c.setLinewrap(1, 2, 3).around(f.getDriveRule());
c.setLinewrap(1, 1, 2).around(f.getSyncRule());
c.setLinewrap(1,1,2).around(f.getObjectRule());
List<Pair<Keyword,Keyword>> pairs = f.findKeywordPairs("{", "}");
for (Pair<Keyword, Keyword> pair : pairs) {
c.setIndentation(pair.getFirst(), pair.getSecond());
}
c.setLinewrap(0, 1, 2).before(f.getSL_COMMENTRule());
c.setLinewrap(0, 1, 2).before(f.getML_COMMENTRule());
c.setLinewrap(0, 1, 1).after(f.getML_COMMENTRule());
}
}
My problem :
FilesystemGrammarAccess f = (FilesystemGrammarAccess) getGrammarAccess(); is not defined in the xtend class.
I want to change this code with Xtend code
|
|
|
Re: Formating with Xtend [message #1053648 is a reply to message #1053646] |
Tue, 07 May 2013 07:05 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi,
casts are written like this in Xtend:
val FilesystemGrammarAccces f = getGrammarAccess() as
FileSystemGrammarAccess
or even shorter
val f = grammarAccess as FileSystemGrammarAccess
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 07.05.13 08:46, schrieb junior developer:
> Hi all,
>
> I update Xtext framework .but I have problem.I written pure java code
> previosly but now Formatting class is a xtend class.
>
> My code for formating :
>
> public class FilesystemFormatter extends AbstractDeclarativeFormatter {
>
>
> // It's usually a good idea to activate the following three statements.
> // They will add and preserve newlines around comments
> // c.setLinewrap(0, 1,
> 2).before(getGrammarAccess().getSL_COMMENTRule());
> // c.setLinewrap(0, 1,
> 2).before(getGrammarAccess().getML_COMMENTRule());
> // c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
> @Override
> protected void configureFormatting(FormattingConfig c) {
> FilesystemGrammarAccess f = (FilesystemGrammarAccess)
> getGrammarAccess();
>
> c.setAutoLinewrap(120);
>
> //c.setLinewrap(1).after(f.getFileAccess().getSemicolonKeyword_0_2_1());
>
>
> //c.setWrappedLineIndentation(f.getFileAccess().getSemicolonKeyword_0_2_1())
> ;
> c.setLinewrap(1, 2, 3).around(f.getFilesystemRule());
> c.setLinewrap(1, 2, 3).around(f.getDriveRule());
> c.setLinewrap(1, 1, 2).around(f.getSyncRule());
> c.setLinewrap(1,1,2).around(f.getObjectRule());
>
> List<Pair<Keyword,Keyword>> pairs = f.findKeywordPairs("{",
> "}");
> for (Pair<Keyword, Keyword> pair : pairs) {
> c.setIndentation(pair.getFirst(), pair.getSecond());
> }
>
> c.setLinewrap(0, 1, 2).before(f.getSL_COMMENTRule());
> c.setLinewrap(0, 1, 2).before(f.getML_COMMENTRule());
> c.setLinewrap(0, 1, 1).after(f.getML_COMMENTRule());
>
> }
>
>
> }
>
>
>
> My problem :
>
> FilesystemGrammarAccess f = (FilesystemGrammarAccess)
> getGrammarAccess(); is not defined in the xtend class.
>
> I want to change this code with Xtend code :(
|
|
| | | | | | | | | | | |
Re: Formating with Xtend [message #1053821 is a reply to message #1053729] |
Tue, 07 May 2013 17:36 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Jan,
My problem is solved with replace the fragment .but Do I encounter any problems at a later time.thank you for help,
BEst regrads
Jan Kohnlein wrote on Tue, 07 May 2013 08:10In the mwe2 workflow, set the variable generateXtendStub to false and
replace the fragments
validation.ValidatorFragment
with
validation.JavaValidatorFragment
and
contentAssist.ContentAssistFragment
with
contentAssist.JavaBasedContentAssistFragment
This will restore the generation of Java stubs and their bindings.
Am 07.05.13 10:08, schrieb junior developer:
> Hi Sebastian,
>
> I want to use my code that is written in the previosly version, in the
> Xtext's new version .
>
> I have been written pure java code in the previous Xtext version,now I
> want to use these code in new Xtext version.is it possible ? because
> every generated class (such as for Validation,Formating) is a Xtend
> class .I want to use new version but I want to write pure java code .
>
> must I write xtend code for this version?
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Goto Forum:
Current Time: Thu Sep 26 14:04:49 GMT 2024
Powered by FUDForum. Page generated in 0.04799 seconds
|