protected void setModel(XtextDocument document, String prefix, String editablePart, String suffix) { if (this.insertLineBreaks) { String delimiter = document.getDefaultLineDelimiter(); prefix = prefix + delimiter; suffix = delimiter + suffix; } String model = prefix + editablePart + suffix; document.set(model); XtextResource resource = createResource(model); document.setInput(resource); AnnotationModel annotationModel = new AnnotationModel(); if (document instanceof ISynchronizable) { Object lock = ((ISynchronizable) document).getLockObject(); if (lock == null) { lock = new Object(); ((ISynchronizable) document).setLockObject(lock); } ((ISynchronizable) annotationModel).setLockObject(lock); } this.viewer.setDocument(document, annotationModel, prefix.length(), editablePart.length()); }
protected void doScheduleInitialValidation(XtextDocument document) { URI uri = document.getResourceURI(); if (uri == null) return; IResourceDescription description = resourceDescriptions.getResourceDescription(uri); if (description == null) { // resource was just created - build is likely to be running in background return; } Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(description); for(URI outgoing: outgoingReferences) { if (isDirty(outgoing)) { document.checkAndUpdateAnnotations(); return; } } }
/** * Uninstall this reconciler from the editor */ public void uninstall() { if (presenter != null) presenter.setCanceled(true); if (sourceViewer.getDocument() != null) { if (calculator != null) { XtextDocument document = (XtextDocument) sourceViewer.getDocument(); document.removeModelListener(this); sourceViewer.removeTextInputListener(this); } } editor = null; sourceViewer = null; presenter = null; }
/** * Refreshes the highlighting. */ public void refresh() { if (calculator != null) { new Job("calculating highlighting") { @Override protected IStatus run(IProgressMonitor monitor) { ((XtextDocument) sourceViewer.getDocument()).readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { modelChanged(state); } }); return Status.OK_STATUS; } }.schedule(); } else { Display display = getDisplay(); display.asyncExec(presenter.createSimpleUpdateRunnable()); } }
@Override protected IStatus run(final IProgressMonitor monitor) { if (monitor.isCanceled() || paused) return Status.CANCEL_STATUS; long start = System.currentTimeMillis(); final IXtextDocument document = XtextDocumentUtil.get(textViewer); if (document instanceof XtextDocument) { ((XtextDocument) document).internalModify(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { doRun(state, monitor); } }); } if (log.isDebugEnabled()) log.debug("Reconciliation finished. Time required: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$ return Status.OK_STATUS; }
@Fix(SadlJavaValidator.AMBIGUOUS_NAME) public void addNSQualifier(final Issue issue, final IssueResolutionAcceptor acceptor) { String[] fixes = issue.getData(); Iterator<String> itr = Splitter.on(",").split(fixes[0]).iterator(); while (itr.hasNext()) { // loop over prefixes final String prefix = itr.next(); acceptor.accept(issue, prefix, "Add the namespace prefix '" + prefix + "' to disambiguate name", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { if (element instanceof ResourceByName) { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { int insertAt = issue.getOffset(); xtextDocument.replace(insertAt, issue.getLength(), prefix); } } } }); } }
/** * Creates a new document with the contents of the given {@link XtextResource}. * * @param resource * the resource to be used as input to the document * @return the created document */ private ICoreXtextDocument createDocument(final XtextResource resource) { XtextDocument document = documentProvider.get(); if (resource.getParseResult() != null && resource.getParseResult().getRootNode() != null) { document.set(resource.getParseResult().getRootNode().getText()); } document.setInput(resource); return new XtextDocumentAdapter(document); }
/** * Performs (schedule) a "fast-only" validation job on preference changes. * * @param event * the event */ @Override public void propertyChange(final PropertyChangeEvent event) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(NLS.bind("Preference Change: {0} => {1} -> {2}", new Object[] {event.getProperty(), event.getOldValue(), event.getNewValue()})); //$NON-NLS-1$ } for (Iterator<?> i = getConnectedElements(); i.hasNext();) { ((XtextDocument) getDocument(i.next())).checkAndUpdateAnnotations(); } }
protected void setupDocument(Object element, IDocument document) { String content = getString(element); document.set(content); IDocumentPartitioner partitioner = documentPartitioner.get(); partitioner.connect(document); document.setDocumentPartitioner(partitioner); XtextResource resource = createResource(element); loadResource(element, resource); if (resource!=null) { ((XtextDocument) document).setInput(resource); } }
@Override protected void disposeElementInfo(Object element, ElementInfo info) { if (info.fDocument instanceof XtextDocument) { XtextDocument document = (XtextDocument) info.fDocument; document.disposeInput(); } super.disposeElementInfo(element, info); }
@Override protected IRegion findWord(IDocument document, int offset) { if (document instanceof XtextDocument) { Iterator<ILexerTokenRegion> tokenIterator = ((XtextDocument) document).getTokens().iterator(); ILexerTokenRegion leadingToken = null; ILexerTokenRegion trailingToken = null; while(tokenIterator.hasNext()) { ILexerTokenRegion token = tokenIterator.next(); if (token.getOffset() <= offset && token.getOffset() + token.getLength() >= offset) { if (leadingToken != null) trailingToken = token; else leadingToken = token; } if (token.getOffset() > offset) break; } if (leadingToken != null) { try { if (leadingToken.getLength() > 1 && (trailingToken == null || !Character.isLetter(document.getChar(trailingToken.getOffset())))) { return new Region(leadingToken.getOffset(), leadingToken.getLength()); } else if (trailingToken != null) { return new Region(trailingToken.getOffset(), trailingToken.getLength()); } } catch(BadLocationException ignore) {} } } return super.findWord(document, offset); }
public EmbeddedEditor(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, IEditedResourceProvider resourceProvider, Runnable afterSetDocumet) { this.document = document; this.viewer = viewer; this.configuration = configuration; this.resourceProvider = resourceProvider; this.afterSetDocument = afterSetDocumet; }
/** * @return the common region of the given partition and the changed region in the DocumentEvent based on the underlying tokens. */ protected IRegion computeInterSection(ITypedRegion partition, DocumentEvent e, XtextDocument document) { Iterable<ILexerTokenRegion> tokensInPartition = Iterables.filter(document.getTokens(),Regions.overlaps(partition.getOffset(), partition.getLength())); Iterator<ILexerTokenRegion> tokens = Iterables.filter(tokensInPartition, Regions.overlaps(e.getOffset(), e.getLength())).iterator(); if (tokens.hasNext()) { ILexerTokenRegion first = tokens.next(); ILexerTokenRegion last = first; while(tokens.hasNext()) last = tokens.next(); return new Region(first.getOffset(), last.getOffset()+last.getLength() -first.getOffset()); } // this shouldn't happen, but just in case return the whole partition return partition; }
public void setDocument(IDocument document) { if (!(document instanceof XtextDocument)) { throw new IllegalArgumentException("Document must be an " + XtextDocument.class.getSimpleName()); } if (spellingReconcileStrategy != null) { spellingReconcileStrategy.setDocument(document); } }
@Override public void configure(Binder binder) { super.configure(binder); binder.bind(String.class).annotatedWith(Names.named("stylesheet")).toInstance("/StextHoverStyleSheet.css"); binder.bind(XtextDocument.class).to(ParallelReadXtextDocument.class); binder.bind(TaskMarkerCreator.class).to(SCTTaskMarkerCreator.class); binder.bind(TaskMarkerTypeProvider.class).to(SCTTaskMarkerTypeProvider.class); }
private void registerGuiceBindingsUi() { new GuiceModuleAccess.BindingFactory() .addTypeToType(typeRef(XtextDocument.class), typeRef(CooperateXtextDocument.class)) .addTypeToType(typeRef(XtextDocumentProvider.class), typeRef(CooperateCDOXtextDocumentProvider.class)) .addTypeToType(typeRef(IResourceSetProvider.class), typeRef(XtextLiveScopeResourceSetProvider.class)) .contributeTo(getLanguage().getEclipsePluginGenModule()); getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles() .add("de.cooperateproject.modeling.textual.xtext.runtime.ui"); }
@Override public void removeDocumentStateListener(IDocumentStateListener listener) { if (null != listener) { IXtextDocumentContentObserver delegatingListener = documentStateListeners.remove(listener); if (null != delegatingListener && null != embeddedEditor) { XtextDocument doc = embeddedEditor.getDocument(); if (null != doc) { doc.removeXtextDocumentContentObserver(delegatingListener); } } } }
@Fix(SadlJavaValidator.OBJECTPROPERTY_NOT_DEFINED) public void addObjectPropertyDefinition(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Property", "Add missing object property definition to the model", null, new ISemanticModification() { public void apply(EObject rsrcId, IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { Object[] fixInfo = prepareMissingConceptFix(xtextDocument, rsrcId, issue); xtextDocument.replace(((Integer)fixInfo[1]).intValue(), 1, "." + System.getProperty("line.separator") + (fixInfo[0] != null ? fixInfo[0] : "New_Prop") + " describes .\n"); } } }); }
@Fix(SadlJavaValidator.DATATYPEPROPERTY_NOT_DEFINED) public void addDatatypePropertyDefinition(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Property", "Add missing data property definition to the model", null, new ISemanticModification() { public void apply(EObject rsrcId, IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { Object[] fixInfo = prepareMissingConceptFix(xtextDocument, rsrcId, issue); xtextDocument.replace(((Integer)fixInfo[1]).intValue(), 1, "." + System.getProperty("line.separator") + (fixInfo[0] != null ? fixInfo[0] : "New_Prop") + " describes .\n"); } } }); }
/** Custom XtextDocument. */ public Class<? extends XtextDocument> bindXtextDocument() { return N4JSDocument.class; }
protected XtextDocument createEmptyDocument() { return documentProvider.get(); }
public XtextDocument getDocument() { return this.document; }
public void scheduleInitialValidation(IXtextDocument document) { if (!(document instanceof XtextDocument)) return; doScheduleInitialValidation((XtextDocument) document); }
protected Iterable<ILexerTokenRegion> getTokens(IDocument document) { XtextDocument doc = (XtextDocument) document; return doc.getTokens(); }
protected XtextDocument getXtextDocument() { return this.document; }
public static void text2model(final SQLQueryDesigner designer, XtextDocument doc) { text2model(designer, doc, false); }
public static void text2model(final SQLQueryDesigner designer, final XtextDocument doc, final boolean showWarning) { try { if (isRunning) return; isRunning = true; designer.refreshViewer(); ConvertUtil.cleanDBMetadata(designer.getDbMetadata().getRoot()); System.out.println("convert the model"); //$NON-NLS-1$ doc.readOnly(new IUnitOfWork<String, XtextResource>() { public String exec(XtextResource resource) { if (!resource.getErrors().isEmpty()) { if (showWarning && !doc.get().trim().isEmpty()) UIUtils.showWarning(Messages.Text2Model_warn); // designer.showWarning("Parser is not able to convert Query to the model"); isRunning = false; return ""; //$NON-NLS-1$ } designer.showInfo(""); //$NON-NLS-1$ ANode root = designer.getRoot(); EList<?> list = resource.getContents(); if (list != null && !list.isEmpty()) { for (Object obj : list) { if (obj instanceof ModelImpl) { SelectQuery sq = ((ModelImpl) obj).getQuery(); if (sq instanceof SelectImpl) { convertSelect(designer, root, (SelectImpl) sq); EList<SelectSubSet> op = ((SelectImpl) sq).getOp(); if (op != null && !op.isEmpty()) { for (SelectSubSet sss : op) { MUnion munion = null; if (sss.getOp() != null) { munion = CreateUnion.createUnion(root); String setop = sss.getOp().toUpperCase(); if (setop.equals(AMKeyword.SET_OPERATOR_UNION) && sss.getAll() != null) setop += " ALL"; //$NON-NLS-1$ munion.setValue(setop); } convertSelect(designer, Misc.nvl(munion, root), (SelectImpl) sss.getQuery()); } } } } ConvertOrderBy.convertOrderBy(designer, ((ModelImpl) obj).getOrderByEntry()); } } isRunning = false; return ""; //$NON-NLS-1$ } }); } catch (Throwable e) { e.printStackTrace(); } }
public XtextDocument getXTextDocument() { return (XtextDocument) viewer.getDocument(); }
protected XtextDocument getXtextDocument() { return document; }
public Class<? extends XtextDocument> bindXtextDocument() { return CooperateXtextDocument.class; }
protected Object text (XtextDocument doc) { return "IVML model"; }
private Object[] prepareMissingConceptFix(IXtextDocument xtextDocument, EObject conceptEobject, Issue issue) throws BadLocationException { String nameAt0 = null; String propName = null; String nameAt2 = null; if (conceptEobject instanceof ResourceByName) { nameAt0 = ((ResourceByName)conceptEobject).getName().getName(); EObject container = conceptEobject.eContainer().eContainer(); if (container instanceof PropValPartialTriple) { propName = ((ResourceByName)((PropValPartialTriple)container).getPropertyName()).getName().getName(); // ((SadlProposalProvider)proposalProvider).visitor.toString(); // System.out.println("Property: " + propName); } } if (issue.getCode().equals(SadlJavaValidator.INSTANCE_NOT_DEFINED)) { SadlModelManager visitor = null; try { visitor = sadlModelManagerProvider.get(conceptEobject.eResource()); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (visitor != null) { ConceptName rcn = null; try { rcn = visitor.getObjectPropertyRange(new ConceptName(propName)); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (rcn != null) { nameAt2 = rcn.getName(); } else { nameAt2 = "Class"; } } } int length = ((XtextDocument)xtextDocument).getLength() - (issue.getOffset() + issue.getLength()); String rest = xtextDocument.get(issue.getOffset() + issue.getLength(), length); int index = rest.indexOf('.'); int insertionPt = issue.getOffset() + issue.getLength() + index; Object[] results = new Object[3]; results[0] = nameAt0; results[1] = Integer.valueOf(insertionPt); results[2] = nameAt2; return results; }