List of usage examples for org.eclipse.jdt.internal.core BufferManager createBuffer
public static IBuffer createBuffer(IOpenable owner)
From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java
License:Open Source License
public IBuffer convertBuffer(IBuffer buf) { try {/*from w ww. j av a 2s. c om*/ if (isInOriginalContentMode() || (buf == null)) { return buf; } } catch (JavaModelException e) { } if (javaCompBuffer == null) { IBuffer myBuffer = BufferManager.createBuffer(this); javaCompBuffer = new JavaCompatibleBuffer(buf, myBuffer); } else { if (buf != javaCompBuffer) javaCompBuffer.reinitialize(buf); } return javaCompBuffer; }
From source file:org.eclipse.jdt.core.WorkingCopyOwner.java
License:Open Source License
/** * Creates a buffer for the given working copy. * The new buffer will be initialized with the contents of the underlying file * if and only if it was not already initialized by the compilation owner (a buffer is * uninitialized if its content is <code>null</code>). * <p>/* w ww . java2s .co m*/ * Note: This buffer will be associated to the working copy for its entire life-cycle. Another * working copy on same unit but owned by a different owner would not share the same buffer * unless its owner decided to implement such a sharing behaviour. * </p> * * @param workingCopy the working copy of the buffer * @return IBuffer the created buffer for the given working copy * @see IBuffer */ public IBuffer createBuffer(ICompilationUnit workingCopy) { return BufferManager.createBuffer(workingCopy); }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
/** * @see Openable#openBuffer(IProgressMonitor, Object) *///from w ww. j a v a 2 s . c o m protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException { // create buffer BufferManager bufManager = getBufferManager(); boolean isWorkingCopy = isWorkingCopy(); IBuffer buffer = isWorkingCopy ? this.owner.createBuffer(this) : BufferManager.createBuffer(this); if (buffer == null) return null; ICompilationUnit original = null; boolean mustSetToOriginalContent = false; if (isWorkingCopy) { // ensure that isOpen() is called outside the bufManager synchronized block // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=237772 // GROOVY start /* old { mustSetToOriginalContent = !isPrimary() && (original = new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen() ; } new */ mustSetToOriginalContent = !isPrimary() && (original = LanguageSupportFactory.newCompilationUnit((PackageFragment) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen(); // GROOVY end } // synchronize to ensure that 2 threads are not putting 2 different buffers at the same time // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146331 synchronized (bufManager) { IBuffer existingBuffer = bufManager.getBuffer(this); if (existingBuffer != null) return existingBuffer; // set the buffer source if (buffer.getCharacters() == null) { if (isWorkingCopy) { if (mustSetToOriginalContent) { buffer.setContents(original.getSource()); } else { IFile file = (IFile) getResource(); if (file == null || !file.exists()) { // initialize buffer with empty contents buffer.setContents(CharOperation.NO_CHAR); } else { buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } } else { IFile file = (IFile) getResource(); if (file == null || !file.exists()) throw newNotPresentException(); buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } // add buffer to buffer cache // note this may cause existing buffers to be removed from the buffer cache, but only primary compilation unit's buffer // can be closed, thus no call to a client's IBuffer#close() can be done in this synchronized block. bufManager.addBuffer(buffer); // listen to buffer changes buffer.addBufferChangedListener(this); } return buffer; }
From source file:org.sf.feeling.decompiler.editor.ClassFileSourceMap.java
License:Open Source License
private static void mapSource(JavaDecompilerBufferManager bufferManager, ClassFile cf, SourceMapper mapper, IBinaryType info, IClassFile bufferOwner, char[] markedSrc) { char[] contents = mapper.findSource(cf.getType(), info); if (Arrays.equals(markedSrc, contents)) return;// w ww. j a v a 2s .c o m contents = markedSrc; if (contents != null) { // create buffer IBuffer buffer = BufferManager.createBuffer(bufferOwner); if (buffer == null) return; JavaDecompilerBufferManager bufManager = bufferManager; bufManager.addBuffer(buffer); // set the buffer source if (buffer.getCharacters() == null) { buffer.setContents(contents); } // listen to buffer changes // buffer.addBufferChangedListener( cf ); // do the source mapping mapper.mapSource(getOuterMostEnclosingType(cf), contents, info); return; } else { // create buffer IBuffer buffer = BufferManager.createNullBuffer(bufferOwner); if (buffer == null) return; JavaDecompilerBufferManager bufManager = bufferManager; bufManager.addBuffer(buffer); // listen to buffer changes // buffer.addBufferChangedListener( cf ); return; } }
From source file:org.sf.feeling.decompiler.editor.JavaDecompilerClassFileEditor.java
License:Open Source License
private boolean doOpenBuffer(IEditorInput input, String type, boolean force, boolean reuseBuf, boolean always) throws JavaModelException { if (UIUtil.isDebugPerspective() || JavaDecompilerPlugin.getDefault().isDebugMode()) reuseBuf = false;/*from w w w . j a v a 2 s. co m*/ if (input instanceof IClassFileEditorInput) { boolean opened = false; IClassFile cf = ((IClassFileEditorInput) input).getClassFile(); String decompilerType = type; String origSrc = cf.getSource(); if (origSrc == null || (origSrc != null && always && (!origSrc.startsWith(MARK) || (origSrc.startsWith(MARK) && !reuseBuf))) || (origSrc != null && !always && !origSrc.startsWith(MARK) && !reuseBuf) || debugOptionChange(origSrc) || force) { DecompilerSourceMapper sourceMapper = SourceMapperFactory.getSourceMapper(decompilerType); char[] src = sourceMapper == null ? null : sourceMapper.findSource(cf.getType()); if (src == null) { if (DecompilerType.FernFlower.equals(decompilerType)) { src = SourceMapperFactory.getSourceMapper(DecompilerType.FernFlower) .findSource(cf.getType()); } else { IDecompilerDescriptor decompilerDescriptor = JavaDecompilerPlugin.getDefault() .getDecompilerDescriptor(decompilerType); if (decompilerDescriptor != null) { src = decompilerDescriptor.getDecompilerSourceMapper().findSource(cf.getType()); } } } if (src == null) { return false; } char[] markedSrc = src; classBuffer = BufferManager.createBuffer(cf); classBuffer.setContents(markedSrc); getBufferManager().addBuffer(classBuffer); sourceMapper.mapSource(cf.getType(), markedSrc, true); ClassFileSourceMap.updateSource(getBufferManager(), (ClassFile) cf, markedSrc); opened = true; } return opened; } return false; }