org.eclipse.jface.text.ISynchronizable Java Examples

The following examples show how to use org.eclipse.jface.text.ISynchronizable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentAdapter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void setContents(String contents) {
	synchronized (lock) {
		if (fDocument == null) {
			if (fTextFileBuffer != null) {
				fDocument = fTextFileBuffer.getDocument();
			} else {
				ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
				fDocument =  manager.createEmptyDocument(fFile.getFullPath(), LocationKind.IFILE);
			}
			fDocument.addDocumentListener(this);
			((ISynchronizable)fDocument).setLockObject(lock);
		}
	}
	if (!contents.equals(fDocument.get())) {
		fDocument.set(contents);
	}
}
 
Example #2
Source File: DocumentAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initialize() {
	ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
	try {
		if (fFileStore != null) {
			manager.connectFileStore(fFileStore, new NullProgressMonitor());
			fTextFileBuffer= manager.getFileStoreTextFileBuffer(fFileStore);
		} else {
			manager.connect(fPath, fLocationKind, new NullProgressMonitor());
			fTextFileBuffer= manager.getTextFileBuffer(fPath, fLocationKind);
		}
		fDocument= fTextFileBuffer.getDocument();
	} catch (CoreException x) {
		fDocument= manager.createEmptyDocument(fPath, fLocationKind);
		if (fDocument instanceof ISynchronizable)
			((ISynchronizable)fDocument).setLockObject(new Object());
	}
	fDocument.addDocumentListener(this);
	fIsClosed= false;
}
 
Example #3
Source File: EmbeddedEditorModelAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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());
}
 
Example #4
Source File: ClassFileDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
Example #5
Source File: DocumentReconcileManager.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static <R> R runUnderDocumentLock(IDocument doc, CallableX<R, RuntimeException> runnable) {
	if(doc instanceof ISynchronizable) {
		ISynchronizable synchronizable = (ISynchronizable) doc;
		
		Object lockObject = synchronizable.getLockObject();
		if(lockObject != null) {
			synchronized(lockObject) {
				return runnable.call();
			}
		}
	}
	
	return runnable.call();
}
 
Example #6
Source File: DocumentSync.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static Object runWithDocumentSynched(IDocument document, ICallback<Object, IDocument> iCallback,
        boolean createCopy) {
    Object lockObject = null;
    if (document instanceof ISynchronizable) {
        ISynchronizable sync = (ISynchronizable) document;
        lockObject = sync.getLockObject();
    }
    DocCopy docCopy = null;
    try {
        if (lockObject != null) {
            if (createCopy) {
                synchronized (lockObject) {
                    docCopy = new DocCopy(document);
                }
                return iCallback.call(docCopy);
            } else {
                synchronized (lockObject) {
                    return iCallback.call(document);
                }
            }
        } else { //unsynched
            if (createCopy && !(document instanceof DocCopy)) {
                docCopy = new DocCopy(document);
                return iCallback.call(docCopy);
            }
            return iCallback.call(document);
        }
    } finally {
        if (docCopy != null) {
            docCopy.dispose();
        }
    }
}
 
Example #7
Source File: DocUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static Object runWithDocumentSynched(IDocument document, ICallback<Object, IDocument> iCallback) {
    Object lockObject = null;
    if (document instanceof ISynchronizable) {
        ISynchronizable sync = (ISynchronizable) document;
        lockObject = sync.getLockObject();
    }
    if (lockObject != null) {
        synchronized (lockObject) {
            return iCallback.call(document);
        }
    } else { //unsynched
        return iCallback.call(document);
    }

}
 
Example #8
Source File: BaseMarkOccurrencesJob.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gotten from JavaEditor#getLockObject
 */
protected Object getLockObject(IAnnotationModel annotationModel) {
    if (annotationModel instanceof ISynchronizable) {
        return ((ISynchronizable) annotationModel).getLockObject();
    } else {
        return annotationModel;
    }
}
 
Example #9
Source File: SemanticHighlightingPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document
 * @return the document's lock object
 */
private Object getLockObject(IDocument document) {
	if (document instanceof ISynchronizable) {
		Object lock= ((ISynchronizable)document).getLockObject();
		if (lock != null)
			return lock;
	}
	return document;
}
 
Example #10
Source File: OverrideIndicatorManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the lock object for the given annotation model.
 *
 * @param annotationModel the annotation model
 * @return the annotation model's lock object
 * @since 3.0
 */
private Object getLockObject(IAnnotationModel annotationModel) {
	if (annotationModel instanceof ISynchronizable) {
		Object lock= ((ISynchronizable)annotationModel).getLockObject();
		if (lock != null)
			return lock;
	}
	return annotationModel;
}
 
Example #11
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the lock object for the given annotation model.
 *
 * @param annotationModel the annotation model
 * @return the annotation model's lock object
 * @since 3.0
 */
private Object getLockObject(IAnnotationModel annotationModel) {
	if (annotationModel instanceof ISynchronizable) {
		Object lock= ((ISynchronizable)annotationModel).getLockObject();
		if (lock != null)
			return lock;
	}
	return annotationModel;
}
 
Example #12
Source File: MultiRegionSpellingReconcileStrategy.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes this collector with the given annotation model.
 *
 * @param annotationModel
 *            the annotation model
 */
public SpellingProblemCollector(IAnnotationModel annotationModel) {
	Assert.isLegal(annotationModel != null);
	fAnnotationModel = annotationModel;
	if (fAnnotationModel instanceof ISynchronizable) {
		fLockObject = ((ISynchronizable) fAnnotationModel).getLockObject();
	} else {
		fLockObject = fAnnotationModel;
	}
}
 
Example #13
Source File: CommonOccurrencesUpdater.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getAnnotationModelLock
 * 
 * @param annotationModel
 * @return
 */
private Object getAnnotationModelLock(IAnnotationModel annotationModel) {
	Object result = annotationModel;

	if (annotationModel instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) annotationModel).getLockObject();

		if (lock != null) {
			result = lock;
		}
	}

	return result;
}
 
Example #14
Source File: CommonPresentationReconciler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static Object getLockObject(Object object)
{
	if (object instanceof ISynchronizable)
	{
		Object lock = ((ISynchronizable) object).getLockObject();
		if (lock != null)
		{
			return lock;
		}
	}
	return object;
}
 
Example #15
Source File: NonRuleBasedDamagerRepairer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static Object getLockObject(Object object)
{
	if (object instanceof ISynchronizable)
	{
		Object lock = ((ISynchronizable) object).getLockObject();
		if (lock != null)
		{
			return lock;
		}
	}
	return object;
}
 
Example #16
Source File: TypeScriptEditor.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Returns the lock object for the given annotation model.
 *
 * @param annotationModel
 *            the annotation model
 * @return the annotation model's lock object
 * 
 */
private Object getLockObject(IAnnotationModel annotationModel) {
	if (annotationModel instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) annotationModel).getLockObject();
		if (lock != null)
			return lock;
	}
	return annotationModel;
}
 
Example #17
Source File: OverrideIndicatorModelListener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private Object getLockObject(IAnnotationModel annotationModel) {
	if (annotationModel instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) annotationModel).getLockObject();
		if (lock != null)
			return lock;
	}
	return annotationModel;
}
 
Example #18
Source File: XdsSymfileDocumentProvider.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
Example #19
Source File: TeXSpellingReconcileStrategy.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes this collector with the given annotation model.
 *
 * @param annotationModel the annotation model
 */
public TeXSpellingProblemCollector(IAnnotationModel annotationModel) {
    Assert.isLegal(annotationModel != null);
    fAnnotationModel= annotationModel;
    if (fAnnotationModel instanceof ISynchronizable)
        fLockObject= ((ISynchronizable)fAnnotationModel).getLockObject();
    else
        fLockObject= fAnnotationModel;
}
 
Example #20
Source File: HighlightingPresenter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param document
 *            the document
 * @return the document's lock object
 */
private Object getLockObject(IDocument document) {
	if (document instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) document).getLockObject();
		if (lock != null)
			return lock;
	}
	return document;
}
 
Example #21
Source File: DocumentSync.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public static IDocument createUnsynchedDocIfNeeded(IDocument doc) {
    if (doc instanceof ISynchronizable) {
        return new DocCopy(doc);
    }
    return doc;
}
 
Example #22
Source File: PyReconciler.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endCollecting() {

    List<Object> toRemove = new ArrayList<Object>();

    Object fLockObject;
    if (fAnnotationModel instanceof ISynchronizable) {
        fLockObject = ((ISynchronizable) fAnnotationModel).getLockObject();
    } else {
        fLockObject = new Object();
    }

    //let other threads execute before getting the lock on the annotation model
    Thread.yield();

    Thread thread = Thread.currentThread();
    int initiaThreadlPriority = thread.getPriority();
    try {
        //before getting the lock, let's execute with normal priority, to optimize the time that we'll 
        //retain that object locked (the annotation model is used on lots of places, so, retaining the lock
        //on it on a minimum priority thread is not a good thing.
        thread.setPriority(Thread.NORM_PRIORITY);
        Iterator<Annotation> iter;

        synchronized (fLockObject) {
            iter = fAnnotationModel.getAnnotationIterator();
            while (iter.hasNext()) {
                Object n = iter.next();
                if (n instanceof SpellingAnnotation) {
                    toRemove.add(n);
                }
            }
            iter = null;
        }

        Annotation[] annotationsToRemove = toRemove.toArray(new Annotation[toRemove.size()]);

        //let other threads execute before getting the lock (again) on the annotation model
        Thread.yield();
        synchronized (fLockObject) {
            if (fAnnotationModel instanceof IAnnotationModelExtension) {
                ((IAnnotationModelExtension) fAnnotationModel).replaceAnnotations(annotationsToRemove,
                        fAddAnnotations);
            } else {
                for (int i = 0; i < annotationsToRemove.length; i++) {
                    fAnnotationModel.removeAnnotation(annotationsToRemove[i]);
                }
                for (iter = fAddAnnotations.keySet().iterator(); iter.hasNext();) {
                    Annotation annotation = iter.next();
                    fAnnotationModel.addAnnotation(annotation, fAddAnnotations.get(annotation));
                }
            }
        }

    } finally {
        thread.setPriority(initiaThreadlPriority);
    }
    fAddAnnotations = null;
}