List of usage examples for org.eclipse.jdt.internal.core DefaultWorkingCopyOwner PRIMARY
DefaultWorkingCopyOwner PRIMARY
To view the source code for org.eclipse.jdt.internal.core DefaultWorkingCopyOwner PRIMARY.
Click Source Link
From source file:ar.com.tadp.xml.rinzo.jdt.contentassist.processors.ClassNameProcessor.java
License:Open Source License
private IJavaCompletionProposal[] createJavaClassesProposals(String prefix) throws JavaModelException { if (prefix != null && !Utils.isEmpty(prefix.trim())) { CompletionProposalCollector collector = new CompletionProposalCollector(this.getProject()); ICompilationUnit unit = getTemporaryCompilationUnit(this.getProject()); String source = TEMPORAL_CLASS_START + prefix + "}}"; setContentsToCU(unit, source);/*w w w . ja va 2 s .c o m*/ unit.codeComplete(source.length() - 2, collector, DefaultWorkingCopyOwner.PRIMARY); IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals(); return proposals; } else { return new IJavaCompletionProposal[] {}; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
public IJavaElement getPrimaryElement(boolean checkOwner) { if (checkOwner && isPrimary()) return this; return new CompilationUnit((PackageFragment) getParent(), manager, getElementName(), DefaultWorkingCopyOwner.PRIMARY); }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
public boolean isPrimary() { return this.owner == DefaultWorkingCopyOwner.PRIMARY; }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
/** * @see Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor, Object) *//*from w w w . j a v a 2s .c om*/ 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 mustSetToOriginalContent = !isPrimary() && (original = new CompilationUnit((PackageFragment) getParent(), manager, getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen(); } // 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 { File file = resource(); if (file == null || !file.exists()) { // initialize buffer with empty contents buffer.setContents(CharOperation.NO_CHAR); } else { buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } } else { File file = resource(); 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:com.codenvy.ide.ext.java.server.internal.core.NamedMember.java
License:Open Source License
/** * @see IType#resolveType(String)// ww w. jav a 2 s .c om */ public String[][] resolveType(String typeName) throws JavaModelException { return resolveType(typeName, DefaultWorkingCopyOwner.PRIMARY); }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see Openable/*w w w. j a v a2 s .co m*/ */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, File underlyingResource) throws JavaModelException { // add compilation units/class files from resources HashSet vChildren = new HashSet(); int kind = getKind(); PackageFragmentRoot root = getPackageFragmentRoot(); char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); File[] members = underlyingResource.listFiles(); { int length = members.length; if (length > 0) { IJavaProject project = getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { File child = members[i]; if (child.isFile() && !Util.isExcluded(new Path(child.getAbsolutePath()), inclusionPatterns, exclusionPatterns, false)) { IJavaElement childElement; if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) { childElement = new CompilationUnit(this, manager, child.getName(), DefaultWorkingCopyOwner.PRIMARY); vChildren.add(childElement); } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) { childElement = getClassFile(child.getName()); vChildren.add(childElement); } } } } } if (kind == IPackageFragmentRoot.K_SOURCE) { // add primary compilation units ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY); for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) { ICompilationUnit primary = primaryCompilationUnits[i]; vChildren.add(primary); } } IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IPackageFragment#getCompilationUnit(String) * @exception IllegalArgumentException if the name does not end with ".java" *///from ww w . j a v a 2 s. c om public ICompilationUnit getCompilationUnit(String cuName) { if (!Util.isJavaLikeFileName(cuName)) { throw new IllegalArgumentException(Messages.convention_unit_notJavaName); } return new CompilationUnit(this, manager, cuName, DefaultWorkingCopyOwner.PRIMARY); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
/** * @see org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope(org.eclipse.jdt.core.IType) for detailed comment. *//*from ww w.j a va 2 s.co m*/ public static IJavaSearchScope createHierarchyScope(IType type) throws JavaModelException { return createHierarchyScope(type, DefaultWorkingCopyOwner.PRIMARY); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
private ICompilationUnit[] getWorkingCopies() { ICompilationUnit[] copies;/*from w ww. j a va 2 s .c om*/ if (this.workingCopies != null) { if (this.workingCopyOwner == null) { copies = JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false/*don't add primary WCs a second time*/); if (copies == null) { copies = this.workingCopies; } else { HashMap pathToCUs = new HashMap(); for (int i = 0, length = copies.length; i < length; i++) { ICompilationUnit unit = copies[i]; pathToCUs.put(unit.getPath(), unit); } for (int i = 0, length = this.workingCopies.length; i < length; i++) { ICompilationUnit unit = this.workingCopies[i]; pathToCUs.put(unit.getPath(), unit); } int length = pathToCUs.size(); copies = new ICompilationUnit[length]; pathToCUs.values().toArray(copies); } } else { copies = this.workingCopies; } } else if (this.workingCopyOwner != null) { copies = JavaModelManager.getJavaModelManager().getWorkingCopies(this.workingCopyOwner, true/*add primary WCs*/); } else { copies = JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false/*don't add primary WCs a second time*/); } if (copies == null) return null; // filter out primary working copies that are saved ICompilationUnit[] result = null; int length = copies.length; int index = 0; for (int i = 0; i < length; i++) { CompilationUnit copy = (CompilationUnit) copies[i]; try { if (!copy.isPrimary() || copy.hasUnsavedChanges() || copy.hasResourceChanged()) { if (result == null) { result = new ICompilationUnit[length]; } result[index++] = copy; } } catch (JavaModelException e) { // copy doesn't exist: ignore } } if (index != length && result != null) { System.arraycopy(result, 0, result = new ICompilationUnit[index], 0, index); } return result; }
From source file:edu.illinois.compositerefactorings.refactorings.createnewtoplevelsuperclass.CreateNewTopLevelSuperClassRefactoring.java
License:Open Source License
private static RefactoringStatus callInitializeWithDefaultWorkingCopyOwner(ExtractSupertypeProcessor processor, JavaRefactoringArguments arguments) { WorkingCopyOwner originalOwner;/*from w w w. j a va 2s.c o m*/ try { originalOwner = setOwner(processor, DefaultWorkingCopyOwner.PRIMARY); RefactoringStatus status = callInitialize(processor, arguments); setOwner(processor, originalOwner); return status; } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (SecurityException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }