本文整理汇总了Java中org.eclipse.xtext.resource.SaveOptions类的典型用法代码示例。如果您正苦于以下问题:Java SaveOptions类的具体用法?Java SaveOptions怎么用?Java SaveOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SaveOptions类属于org.eclipse.xtext.resource包,在下文中一共展示了SaveOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: enhanceExistingImportDeclaration
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
QualifiedName qualifiedName,
String optionalAlias, MultiTextEdit result) {
addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
int offset = replaceMe.getOffset();
AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
optionalAlias,
offset,
grammarAccess);
try {
serializer.serialize(
importDeclaration,
observableBuffer,
SaveOptions.newBuilder().noValidation().getOptions());
} catch (IOException e) {
throw new RuntimeException("Should never happen since we write into memory", e);
}
result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
return observableBuffer.getAliasLocation();
}
开发者ID:eclipse,项目名称:n4js,代码行数:25,代码来源:ImportRewriter.java
示例2: serialize
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
public TreeConstructionReport serialize(EObject obj, ITokenStream tokenStream, SaveOptions options)
throws IOException {
if (options.isValidating()) {
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
validator.validateRecursive(obj, new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics),
new HashMap<Object, Object>());
if (!diagnostics.isEmpty())
throw new IConcreteSyntaxValidator.InvalidConcreteSyntaxException(
"These errors need to be fixed before the model can be serialized.", diagnostics);
}
ITokenStream formatterTokenStream;
if(formatter instanceof IFormatterExtension)
formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, null, tokenStream, !options.isFormatting());
else
formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting());
TreeConstructionReport report = parseTreeReconstructor.serializeSubtree(obj, formatterTokenStream);
formatterTokenStream.flush();
return report;
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:Serializer.java
示例3: serialize
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Override
public String serialize(EObject obj, SaveOptions options) {
checkNotNull(obj, "obj must not be null.");
checkNotNull(options, "options must not be null.");
try {
if (formatter2Provider != null) {
StringBuilder builder = new StringBuilder();
serialize(obj, builder, options);
return builder.toString();
} else {
TokenStringBuffer tokenStringBuffer = new TokenStringBuffer();
serialize(obj, tokenStringBuffer, options);
return tokenStringBuffer.toString();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:Serializer.java
示例4: grammarFragmentToString
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
/**
* @noreference
*/
public static String grammarFragmentToString(final ISerializer serializer, final EObject object, final String prefix) {
String s = null;
try {
final SaveOptions options = SaveOptions.newBuilder().format().getOptions();
s = serializer.serialize(object, options);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception)_t;
s = e.toString();
} else {
throw Exceptions.sneakyThrow(_t);
}
}
String _replace = s.trim().replaceAll("(\\r?\\n)", ("$1" + prefix)).replace("\\u", "\\\\u");
String _plus = (prefix + _replace);
s = _plus;
return s;
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:GrammarAccessExtensions.java
示例5: testXtextFormatting
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Test public void testXtextFormatting() throws IOException {
String path = getClass().getPackage().getName().replace('.', '/');
URI u = URI.createURI("classpath:/" + path + "/XtextFormatterMessy.xtext");
XtextResourceSet resourceSet = new XtextResourceSet();
resourceSet.setClasspathURIContext(getClass());
Resource r = resourceSet.getResource(u, true);
// System.out.println(r.getWarnings());
// System.out.println(r.getErrors());
ByteArrayOutputStream formatted = new ByteArrayOutputStream();
r.save(formatted, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
// System.out.println(EmfFormatter.listToStr(r.getContents()));
// System.out.println(formatted.toString());
URI expectedURI = URI.createURI("classpath:/" + path + "/XtextFormatterExpected.xtext");
XtextResource expectedResource = (XtextResource) resourceSet.getResource(expectedURI, true);
String expected = expectedResource.getParseResult().getRootNode().getText();
assertEquals(expected.replaceAll(System.lineSeparator(), "\n"),
formatted.toString().replaceAll(System.lineSeparator(), "\n"));
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:XtextFormatterTest.java
示例6: testSimple
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Test public void testSimple() throws Exception {
// this fails see bug #252181
String model = "grammar foo with org.eclipse.xtext.common.Terminals Honolulu : name=ID;";
// load grammar model
XtextResourceSet rs = get(XtextResourceSet.class);
Resource resource = rs.createResource(URI.createURI("foo.xtext"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
resource.load(new StringInputStream(model), null);
Grammar object = (Grammar) resource.getContents().get(0);
// modify first rule
object.getRules().get(0).setName("HONOLULU");
// save
ByteArrayOutputStream out = new ByteArrayOutputStream();
resource.save(out, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
String result = new String(out.toByteArray());
// check
assertFalse(model.equals(result));
String expectedModel = LineDelimiters.toPlatform("grammar foo with org.eclipse.xtext.common.Terminals\n\nHONOLULU:\n name=ID;");
assertEquals(expectedModel, result);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:XtextGrammarReconcilationTest.java
示例7: serialize
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
/**
* Serialize the given object into tokenStream using save options.
* The initial indentation is passed on to the formatter.
* This implementation is based on {@link Serializer#serialize(EObject, ITokenStream, SaveOptions)}.
*
* @param obj
* the obj
* @param tokenStream
* the token stream
* @param options
* the options
* @param initialIndentation
* the initial indentation
* @throws IOException
* Signals that an I/O exception has occurred.
*/
protected void serialize(final EObject obj, final ITokenStream tokenStream, final SaveOptions options, final String initialIndentation) throws IOException {
if (options.isValidating()) {
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
validator.validateRecursive(obj, new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics), new HashMap<Object, Object>());
if (!diagnostics.isEmpty()) {
throw new IConcreteSyntaxValidator.InvalidConcreteSyntaxException("These errors need to be fixed before the model can be serialized.", diagnostics); //$NON-NLS-1$
}
}
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
ITokenStream formatterTokenStream;
if (formatter instanceof IFormatterExtension) {
formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, initialIndentation, tokenStream, !options.isFormatting());
} else {
formatterTokenStream = formatter.createFormatterStream(initialIndentation, tokenStream, !options.isFormatting());
}
EObject context = getContext(obj);
ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, errors);
serialize(obj, context, acceptor, errors);
formatterTokenStream.flush();
}
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:38,代码来源:IndentingSerializer.java
示例8: prettyPrint
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
/**
* @since 2.7
*/
protected void prettyPrint(String absoluteGrammarFileName, Charset encoding) {
try {
String content = readFileIntoString(absoluteGrammarFileName, encoding);
final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() {
@Override
public String getLineSeparator() {
return DebugAntlrGeneratorFragment.this.getLineDelimiter();
}
};
Injector injector = new SimpleAntlrStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new SimpleAntlrRuntimeModule() {
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.bind(ILineSeparatorInformation.class).toInstance(lineSeparatorInformation);
}
});
}
}.createInjectorAndDoEMFRegistration();
XtextResource resource = injector.getInstance(XtextResource.class);
resource.setURI(URI.createFileURI(absoluteGrammarFileName));
resource.load(new StringInputStream(content, encoding.name()),
Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding.name()));
if (!resource.getErrors().isEmpty()) {
String errors = Joiner.on(getLineDelimiter()).join(resource.getErrors());
throw new GeneratorWarning("Non fatal problem: Debug grammar could not be formatted due to:" + getLineDelimiter() + errors);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(content.length());
resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
String toBeWritten = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters(
new String(outputStream.toByteArray(), encoding.name()));
writeStringIntoFile(absoluteGrammarFileName, toBeWritten, encoding);
} catch(IOException e) {
throw new GeneratorWarning(e.getMessage());
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:42,代码来源:DebugAntlrGeneratorFragment.java
示例9: serializeReplacement
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Override
public ReplaceRegion serializeReplacement(EObject obj, SaveOptions options) {
TokenStringBuffer tokenStringBuffer = new TokenStringBuffer();
try {
TreeConstructionReport report = serialize(obj, tokenStringBuffer, options);
return new ReplaceRegion(report.getPreviousLocation(), tokenStringBuffer.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:Serializer.java
示例10: toSaveOptions
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
public SaveOptions toSaveOptions() {
SaveOptions.Builder builder = SaveOptions.newBuilder();
if (!isValidateConcreteSyntax())
builder.noValidation();
if (isFormatting())
builder.format();
return builder.getOptions();
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:SerializerOptions.java
示例11: serializeReplacement
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Override
public ReplaceRegion serializeReplacement(EObject obj, SaveOptions options) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
if (node == null) {
throw new IllegalStateException("Cannot replace an obj that has no associated node");
}
String text = serialize(obj, options);
return new ReplaceRegion(node.getTotalOffset(), node.getTotalLength(), text);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:Serializer.java
示例12: saveResource
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
protected String saveResource(Resource resource) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length());
try {
Map<Object, Object> options = Maps.newHashMap();
options.put(XtextResource.OPTION_ENCODING, INTERNAL_ENCODING);
SaveOptions.defaultOptions().addTo(options);
resource.save(out, options);
String result = new String(out.toByteArray(), INTERNAL_ENCODING);
return result;
} finally {
out.close();
}
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:UnorderedGroupsSplitter.java
示例13: testLinewrapDefault
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Test
public void testLinewrapDefault() throws Exception {
FormattertestlanguageFactory f = FormattertestlanguageFactory.eINSTANCE;
TestLinewrapMinMax m = f.createTestLinewrapMinMax();
Decl d = f.createDecl();
d.getType().add("xxx");
d.getName().add("yyy");
m.getItems().add(d);
String actual = getSerializer().serialize(m, SaveOptions.newBuilder().format().getOptions());
final String expected = convertLineBreaks("test wrapminmax\n\n\nxxx yyy;");
assertEquals(expected, actual);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:FormatterTest.java
示例14: checkReplaceRegion
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
private void checkReplaceRegion(Element element, String expectedText, String completeModel) {
Serializer serializer = get(Serializer.class);
ReplaceRegion replacement = serializer.serializeReplacement(element, SaveOptions.defaultOptions());
assertEquals(expectedText, replacement.getText());
assertEquals(completeModel.indexOf(expectedText), replacement.getOffset());
assertEquals(expectedText.length(), replacement.getLength());
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:8,代码来源:CommentAssociationTest.java
示例15: doTestSerialization
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
private void doTestSerialization(final String model, final String expectedModel) throws Exception {
final XtextResource resource = this.getResourceFromString(model);
Assert.assertTrue(resource.getErrors().isEmpty());
EObject _rootASTElement = resource.getParseResult().getRootASTElement();
final Grammar g = ((Grammar) _rootASTElement);
Assert.assertNotNull(g);
final OutputStream outputStream = new ByteArrayOutputStream();
resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
final String serializedModel = outputStream.toString();
Assert.assertEquals(LineDelimiters.toPlatform(expectedModel), serializedModel);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:XtextGrammarSerializationTest.java
示例16: linewrapDefault
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
/**
* This test is copied from
* org.eclipse.xtext.nodemodel.impl.formatter.FormatterTest.
*
* @throws IOException
*/
@Test
public void linewrapDefault() {
FormatterTestLanguageFactory f = FormatterTestLanguageFactory.eINSTANCE;
TestLinewrapMinMax m = f.createTestLinewrapMinMax();
Decl d = f.createDecl();
d.getType().add("xxx");
d.getName().add("yyy");
m.getItems().add(d);
String actual = getSerializer().serialize(m, SaveOptions.newBuilder().format().getOptions());
String expected = "test wrapminmax\n\n\nxxx yyy;";
Assert.assertEquals(expected, actual);
}
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:19,代码来源:FormatterTest.java
示例17: getEclDocument
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
public ECLDocument getEclDocument(ImportInterfaceStatement importInterfaceStatement){
//init Xtext
String modelPath = importInterfaceStatement.getImportURI();
EclStandaloneSetup ess= new EclStandaloneSetup();
Injector injector = ess.createInjector();
XtextResourceSet aSet = injector.getInstance(XtextResourceSet.class);
aSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.FALSE);
EcoreUtil.resolveAll(aSet);
EclStandaloneSetup.doSetup();
URI uri =null;
//filter URI
if (modelPath.startsWith("platform:/plugin")){
uri = URI.createPlatformPluginURI(modelPath.replace("platform:/plugin", ""), false);
}else
if(modelPath.startsWith("platform:/resource")){
uri = URI.createPlatformResourceURI(modelPath.replace("platform:/resource", ""),false);
}else{//relative path
// throw new IllegalArgumentException("the path of the library must be platform based (platform:/resource or platform:/plugin)");
uri = URI.createFileURI(modelPath);
}
//load the corresponding resource
Resource eclResource = aSet.getResource(uri, true);
HashMap<Object, Object> saveOptions = new HashMap<Object, Object>();
Builder aBuilder = SaveOptions.newBuilder();
SaveOptions anOption = aBuilder.getOptions();
anOption.addTo(saveOptions);
try {
eclResource.load(saveOptions);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ECLDocument eclDoc = (ECLDocument)eclResource.getContents().get(0);
return eclDoc;
}
开发者ID:gemoc,项目名称:coordination,代码行数:41,代码来源:helperNsURI.java
示例18: getEclDocumentfromURI
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
public ECLDocument getEclDocumentfromURI(String modelPath){
//init Xtext
EclStandaloneSetup ess= new EclStandaloneSetup();
Injector injector = ess.createInjector();
XtextResourceSet aSet = injector.getInstance(XtextResourceSet.class);
aSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
EcoreUtil.resolveAll(aSet);
EclStandaloneSetup.doSetup();
URI uri =null;
//filter URI
if (modelPath.startsWith("platform:/plugin")){
uri = URI.createPlatformPluginURI(modelPath.replace("platform:/plugin", ""), false);
}else
if(modelPath.startsWith("platform:/resource")){
uri = URI.createPlatformResourceURI(modelPath.replace("platform:/resource", ""),false);
}else{//relative path
// throw new IllegalArgumentException("the path of the library must be platform based (platform:/resource or platform:/plugin)");
uri = URI.createFileURI(modelPath);
}
//load the corresponding resource
Resource eclResource = aSet.getResource(uri, true);
HashMap<Object, Object> saveOptions = new HashMap<Object, Object>();
Builder aBuilder = SaveOptions.newBuilder();
SaveOptions anOption = aBuilder.getOptions();
anOption.addTo(saveOptions);
try {
eclResource.load(saveOptions);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ECLDocument eclDoc = (ECLDocument)eclResource.getContents().get(0);
return eclDoc;
}
开发者ID:gemoc,项目名称:coordination,代码行数:40,代码来源:helperNsURI.java
示例19: loadResource
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
protected void loadResource(Resource model2Resource) {
HashMap<Object, Object> saveOptions2 = new HashMap<Object, Object>();
Builder aBuilder2 = SaveOptions.newBuilder();
SaveOptions anOption2 = aBuilder2.getOptions();
anOption2.addTo(saveOptions2);
try {
model2Resource.load(saveOptions2);
} catch (IOException e1) {
e1.printStackTrace();
}
}
开发者ID:gemoc,项目名称:coordination,代码行数:12,代码来源:Qvto2CCSLTranslator.java
示例20: serialize
import org.eclipse.xtext.resource.SaveOptions; //导入依赖的package包/类
@Override
public void serialize(EObject obj, ITokenStream tokenStream, SaveOptions options) throws IOException {
super.serialize(obj, tokenStream, options);
}
开发者ID:eclipse,项目名称:n4js,代码行数:5,代码来源:AccessibleSerializer.java
注:本文中的org.eclipse.xtext.resource.SaveOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论