protected XtendFile getXtendFile(XtextResource resource) { if(resource == null || resource.getContents().isEmpty() || !(resource.getContents().get(0) instanceof XtendFile)) return null; else return (XtendFile) resource.getContents().get(0); }
public T exec(XtextResource resource) throws Exception { if(resource != null && !resource.getContents().isEmpty()) { work.exec(resource.getContents().get(0)); } return null; } });
protected ITextRegionAccess createRegionAccessViaSerializer(XtextResource resource) { EObject root = resource.getContents().get(0); ITextRegionAccess regionAccess = serializer.serializeToRegions(root); return regionAccess; }
@Override public XImportSection getImportSection(XtextResource resource) { EList<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { for (Iterator<EObject> i = contents.get(0).eAllContents(); i.hasNext();) { EObject next = i.next(); if (next instanceof XImportSection) return (XImportSection) next; } } return null; }
protected void clearInternalState() { for (EObject content : getContents()) { unload(content); } getContents().clear(); clearErrorsAndWarnings(); this.parseResult = null; }
protected ChangeRecorder createChangeRecorder(XtextResource res) { return new ChangeRecorder(res.getContents().get(0)); }
protected ChangeRecorder createChangeRecorder(XtextResource resource) { return new ChangeRecorder(resource.getContents().get(0)); }
public TypeUsages collectTypeUsages(XtextResource resource) { if(resource != null && !resource.getContents().isEmpty()) { this.resource = resource; this.implicitStaticImports = implicitImports.getStaticImportClasses(resource); this.implicitExtensionImports = implicitImports.getExtensionClasses(resource); collectAllReferences(resource.getContents().get(0)); } return typeUsages; }
@Override public void doSave(OutputStream outputStream, Map<?, ?> options) throws IOException { if (getContents().isEmpty()) throw new IllegalStateException("The Xtext resource must contain at least one element."); SaveOptions saveOptions = SaveOptions.getOptions(options); setEncodingFromOptions(options); serializer.serialize(getContents().get(0), new OutputStreamWriter(outputStream, getEncoding()), saveOptions); }
public List<org.eclipse.emf.common.util.Diagnostic> validateConcreteSyntax() { List<org.eclipse.emf.common.util.Diagnostic> diagnostics = new ArrayList<org.eclipse.emf.common.util.Diagnostic>(); IDiagnosticAcceptor acceptor = new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics); for (EObject obj : getContents()) validator.validateRecursive(obj, acceptor, new HashMap<Object, Object>()); return diagnostics; }
public ContentAssistContext[] create(String document, ITextRegion selection, int offset, XtextResource resource) { this.document = document; this.selection = selection; this.resource = resource; //This is called to make sure late initialization is done. if (resource instanceof DerivedStateAwareResource) { resource.getContents(); } this.parseResult = resource.getParseResult(); if (parseResult == null) throw new NullPointerException("parseResult is null"); return doCreateContexts(offset); }
public ContentAssistContext[] create(ITextViewer viewer, int offset, XtextResource resource) throws BadLocationException { this.viewer = viewer; this.resource = resource; //This is called to make sure late initialization is done. if (resource instanceof DerivedStateAwareResource) { resource.getContents(); } this.parseResult = resource.getParseResult(); if (parseResult == null) throw new NullPointerException("parseResult is null"); return doCreateContexts(offset); }
public String serializeToDslString(ZenModel zenModel) { // Xtext serializer needs both a resource with non-null URL and a resource set XtextResourceSet resourceSet = new RepreZenXtextResourceSet(); XtextResource resource = ((XtextResource) resourceSet.createResource(URI.createURI("dummy.rapid"))); resource.getContents().add(zenModel); // serialize return serializer.serialize(zenModel); }
public List<? extends TextEdit> format(final Document document, final XtextResource resource, final DocumentFormattingParams params, final CancelIndicator cancelIndicator) { final int offset = 0; final int length = document.getContents().length(); if (((length == 0) || resource.getContents().isEmpty())) { return CollectionLiterals.<TextEdit>emptyList(); } boolean _hasFormatOverride = FormattingService.OverrideChecker.hasFormatOverride(this.getClass()); if (_hasFormatOverride) { return this.format(resource, document, offset, length); } return this.format(resource, document, offset, length, params.getOptions()); }
protected void updateInternalState(IParseResult newParseResult) { this.parseResult = newParseResult; if (parseResult.getRootASTElement() != null && !getContents().contains(parseResult.getRootASTElement())) getContents().add(0, parseResult.getRootASTElement()); reattachModificationTracker(parseResult.getRootASTElement()); clearErrorsAndWarnings(); addSyntaxErrors(); doLinking(); }
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); checkNodeModel(resource); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty()); else assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); checkNodeModel(resource); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty()); else assertEquals(resource.getErrors().toString(), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } for(Diagnostic d: resource.getWarnings()) System.out.println("Resource Warning: "+d); if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty()); else assertEquals(resource.getErrors().toString(), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } for(Diagnostic d: resource.getWarnings()) System.out.println("Resource Warning: "+d); if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
/** * @param oldParseResult the previous parse result that should be detached if necessary. * @param newParseResult the current parse result that should be attached to the content of this resource * @since 2.1 */ protected void updateInternalState(IParseResult oldParseResult, IParseResult newParseResult) { if (oldParseResult != null && oldParseResult.getRootASTElement() != null && oldParseResult.getRootASTElement() != newParseResult.getRootASTElement()) { EObject oldRootAstElement = oldParseResult.getRootASTElement(); if (oldRootAstElement != newParseResult.getRootASTElement()) { unload(oldRootAstElement); getContents().remove(oldRootAstElement); } } updateInternalState(newParseResult); }
this.format(IterableExtensions.<EObject>head(res.getContents()), format); if ((this.diagnoseConflicts && format.isConflictOccurred())) { final FormattableDocument debug = new FormattableDocument(cfg, doc); RuntimeException _runtimeException = new RuntimeException(); debug.setRootTrace(_runtimeException); this.format(IterableExtensions.<EObject>head(res.getContents()), debug);