类org.eclipse.jface.text.ISynchronizable源码实例Demo

下面列出了怎么用org.eclipse.jface.text.ISynchronizable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-eclipse   文件: EmbeddedEditorModelAccess.java
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());
}
 
源代码2 项目: eclipse.jdt.ls   文件: DocumentAdapter.java
@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);
	}
}
 
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;
}
 
源代码4 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * @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;
}
 
源代码5 项目: texlipse   文件: TeXSpellingReconcileStrategy.java
/**
 * 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;
}
 
源代码6 项目: xds-ide   文件: XdsSymfileDocumentProvider.java
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
private Object getLockObject(IAnnotationModel annotationModel) {
	if (annotationModel instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) annotationModel).getLockObject();
		if (lock != null)
			return lock;
	}
	return annotationModel;
}
 
源代码8 项目: typescript.java   文件: TypeScriptEditor.java
/**
 * 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;
}
 
private static Object getLockObject(Object object)
{
	if (object instanceof ISynchronizable)
	{
		Object lock = ((ISynchronizable) object).getLockObject();
		if (lock != null)
		{
			return lock;
		}
	}
	return object;
}
 
private static Object getLockObject(Object object)
{
	if (object instanceof ISynchronizable)
	{
		Object lock = ((ISynchronizable) object).getLockObject();
		if (lock != null)
		{
			return lock;
		}
	}
	return object;
}
 
源代码11 项目: APICloud-Studio   文件: CommonOccurrencesUpdater.java
/**
 * 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;
}
 
/**
 * 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;
	}
}
 
@Override
protected IDocument createEmptyDocument() {
	IDocument document= FileBuffers.getTextFileBufferManager().createEmptyDocument(null, LocationKind.IFILE);
	if (document instanceof ISynchronizable)
		((ISynchronizable)document).setLockObject(new Object());
	return document;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * @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;
}
 
源代码17 项目: Pydev   文件: BaseMarkOccurrencesJob.java
/**
 * Gotten from JavaEditor#getLockObject
 */
protected Object getLockObject(IAnnotationModel annotationModel) {
    if (annotationModel instanceof ISynchronizable) {
        return ((ISynchronizable) annotationModel).getLockObject();
    } else {
        return annotationModel;
    }
}
 
源代码18 项目: Pydev   文件: DocUtils.java
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);
    }

}
 
源代码19 项目: Pydev   文件: DocumentSync.java
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();
        }
    }
}
 
源代码20 项目: goclipse   文件: DocumentReconcileManager.java
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();
}
 
源代码21 项目: Pydev   文件: DocumentSync.java
public static IDocument createUnsynchedDocIfNeeded(IDocument doc) {
    if (doc instanceof ISynchronizable) {
        return new DocCopy(doc);
    }
    return doc;
}
 
源代码22 项目: Pydev   文件: PyReconciler.java
@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;
}
 
 类所在包
 同包方法