org.eclipse.jdt.core.WorkingCopyOwner Java Examples
The following examples show how to use
org.eclipse.jdt.core.WorkingCopyOwner.
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: JavaZipModule.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Gets tuples with the java element and the corresponding completion proposal for that element. * * @param contents the contents that should be set for doing the code-completion * @param completionOffset the offset where the code completion should be requested * @param filterCompletionName if specified, only return matches from elements that have the name passed (otherwise it should be null) * @return a list of tuples corresponding to the element and the proposal for the gotten elements * @throws JavaModelException */ @Override protected List<Tuple<IJavaElement, CompletionProposal>> getJavaCompletionProposals(String contents, int completionOffset, final String filterCompletionName) throws JavaModelException { final List<Tuple<IJavaElement, CompletionProposal>> ret = new ArrayList<Tuple<IJavaElement, CompletionProposal>>(); IClasspathEntry entries[] = getClasspathEntries(); //Using old version for compatibility with eclipse 3.2 ICompilationUnit unit = new WorkingCopyOwner() { }.newWorkingCopy(name, entries, null, new NullProgressMonitor()); unit.getBuffer().setContents(contents); CompletionProposalCollector collector = createCollector(filterCompletionName, ret, unit); unit.codeComplete(completionOffset, collector); //fill the completions while searching it return ret; }
Example #2
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) { switch (token.charAt(0)) { case JEM_PACKAGEFRAGMENTROOT: String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; token = null; while (memento.hasMoreTokens()) { token = memento.nextToken(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821 if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) { break; } rootPath += token; } JavaElement root = (JavaElement)getPackageFragmentRoot(new Path(rootPath)); if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT) { return root.getHandleFromMemento(token, memento, owner); } else { return root.getHandleFromMemento(memento, owner); } } return null; }
Example #3
Source File: ModelBasedCompletionEngine.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static void codeComplete(ICompilationUnit cu, int position, CompletionRequestor requestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { if (!(cu instanceof CompilationUnit)) { return; } if (requestor == null) { throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$ } IBuffer buffer = cu.getBuffer(); if (buffer == null) { return; } if (position < -1 || position > buffer.getLength()) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS)); } JavaProject project = (JavaProject) cu.getJavaProject(); ModelBasedSearchableEnvironment environment = new ModelBasedSearchableEnvironment(project, owner, requestor.isTestCodeExcluded()); environment.setUnitToSkip((CompilationUnit) cu); // code complete CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner, monitor); engine.complete((CompilationUnit) cu, position, 0, cu); }
Example #4
Source File: RippleMethodFinder2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep= fUnionFind.find(type); if (rep != null) { Collection<IType> collection= fRootReps.get(rep); for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) { IType root= iter.next(); ITypeHierarchy hierarchy= fRootHierarchies.get(root); if (hierarchy == null) { hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); fRootHierarchies.put(root, hierarchy); } if (hierarchy.contains(type)) return hierarchy; } } return null; }
Example #5
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override ParameterNameInitializer createParameterNameInitializer( IMethodBinding method, WorkingCopyOwner workingCopyOwner, JvmExecutable result, String handleIdentifier, String[] path, String name, SegmentSequence signaturex) { if (method.isConstructor() && method.getDeclaringClass().isEnum()) { String syntheticParams = "Ljava/lang/String;I"; String withoutSyntheticArgs = signaturex.toString(); // sometimes (don't really know when... JDT bug?) an enum constructor comes without synthetic arguments // this solution might wrongly strip off a (String,int) signature, but I don't see how this can be done differently here. if (withoutSyntheticArgs.startsWith(syntheticParams)) { withoutSyntheticArgs = withoutSyntheticArgs.substring(syntheticParams.length()); } return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, withoutSyntheticArgs); } return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); }
Example #6
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public InternalExtendedCompletionContext( InternalCompletionContext completionContext, ITypeRoot typeRoot, CompilationUnitDeclaration compilationUnitDeclaration, LookupEnvironment lookupEnvironment, Scope assistScope, ASTNode assistNode, ASTNode assistNodeParent, WorkingCopyOwner owner, CompletionParser parser) { this.completionContext = completionContext; this.typeRoot = typeRoot; this.compilationUnitDeclaration = compilationUnitDeclaration; this.lookupEnvironment = lookupEnvironment; this.assistScope = assistScope; this.assistNode = assistNode; this.assistNodeParent = assistNodeParent; this.owner = owner; this.parser = parser; }
Example #7
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IJavaElement findPackageFragment(String packageName) throws JavaModelException { NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/); IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false); if (pkgFragments == null) { return null; } else { // try to return one that is a child of this project for (int i = 0, length = pkgFragments.length; i < length; i++) { IPackageFragment pkgFragment = pkgFragments[i]; if (equals(pkgFragment.getParent().getParent())) { return pkgFragment; } } // default to the first one return pkgFragments[0]; } }
Example #8
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep= fUnionFind.find(type); if (rep != null) { Collection<IType> collection= fRootReps.get(rep); for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) { IType root= iter.next(); ITypeHierarchy hierarchy= fRootHierarchies.get(root); if (hierarchy == null) { hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); fRootHierarchies.put(root, hierarchy); } if (hierarchy.contains(type)) { return hierarchy; } } } return null; }
Example #9
Source File: MavenClasspathTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private WorkingCopyOwner getWorkingCopy(IProblemRequestor handler) { return new WorkingCopyOwner() { @Override public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { return handler; } }; }
Example #10
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static ICompilationUnit[] createNewWorkingCopies(ICompilationUnit[] compilationUnitsToModify, TextChangeManager manager, WorkingCopyOwner owner, SubProgressMonitor pm) throws CoreException { pm.beginTask("", compilationUnitsToModify.length); //$NON-NLS-1$ ICompilationUnit[] newWorkingCopies= new ICompilationUnit[compilationUnitsToModify.length]; for (int i= 0; i < compilationUnitsToModify.length; i++) { ICompilationUnit cu= compilationUnitsToModify[i]; newWorkingCopies[i]= createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1)); } pm.done(); return newWorkingCopies; }
Example #11
Source File: ReferenceFinderUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static SearchMatch[] getFieldReferencesIn(IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException { List<SearchMatch> referencedFields= new ArrayList<SearchMatch>(); pm.beginTask("", elements.length); //$NON-NLS-1$ for (int i = 0; i < elements.length; i++) { referencedFields.addAll(getFieldReferencesIn(elements[i], owner, new SubProgressMonitor(pm, 1))); } pm.done(); return referencedFields.toArray(new SearchMatch[referencedFields.size()]); }
Example #12
Source File: JavaPlugin.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void start(BundleContext context) throws Exception { super.start(context); fBundleContext= context; WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() { @Override public IBuffer createBuffer(ICompilationUnit workingCopy) { ICompilationUnit original= workingCopy.getPrimary(); IResource resource= original.getResource(); if (resource instanceof IFile) return new DocumentAdapter(workingCopy, (IFile) resource); return DocumentAdapter.NULL; } }); ensurePreferenceStoreBackwardsCompatibility(); // make sure org.eclipse.jdt.core.manipulation is loaded too // can be removed if JavaElementPropertyTester is moved down to jdt.core (bug 127085) JavaManipulation.class.toString(); if (PlatformUI.isWorkbenchRunning()) { // Initialize AST provider getASTProvider(); fThemeListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) JavaUIPreferenceInitializer.setThemeBasedPreferences(PreferenceConstants.getPreferenceStore(), true); } }; PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(fThemeListener); new InitializeAfterLoadJob().schedule(); // last call in start, see bug 191193 } }
Example #13
Source File: ASTCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) { ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setSource(cu); p.setResolveBindings(true); p.setWorkingCopyOwner(workingCopyOwner); p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu)); return (CompilationUnit) p.createAST(null); }
Example #14
Source File: ConstructorReferenceFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private SearchResultGroup[] getConstructorReferences(IProgressMonitor pm, WorkingCopyOwner owner, int limitTo, RefactoringStatus status) throws JavaModelException{ IJavaSearchScope scope= createSearchScope(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(fConstructors, limitTo); if (pattern == null){ if (fConstructors.length != 0) return new SearchResultGroup[0]; return getImplicitConstructorReferences(pm, owner, status); } return removeUnrealReferences(RefactoringSearchEngine.search(pattern, owner, scope, pm, status)); }
Example #15
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static CompilationUnit convert( CompilationUnitDeclaration compilationUnitDeclaration, char[] source, int apiLevel, Map options, boolean needToResolveBindings, WorkingCopyOwner owner, DefaultBindingResolver.BindingTables bindingTables, int flags, IProgressMonitor monitor, boolean fromJavaProject) { BindingResolver resolver = null; AST ast = AST.newAST(apiLevel); ast.setDefaultNodeFlag(ASTNode.ORIGINAL); CompilationUnit compilationUnit = null; ASTConverter converter = new ASTConverter(options, needToResolveBindings, monitor); if (needToResolveBindings) { resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, owner, bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, fromJavaProject); ast.setFlag(flags | AST.RESOLVED_BINDINGS); } else { resolver = new BindingResolver(); ast.setFlag(flags); } ast.setBindingResolver(resolver); converter.setAST(ast); compilationUnit = converter.convert(compilationUnitDeclaration, source); compilationUnit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions()); ast.setDefaultNodeFlag(0); ast.setOriginalModificationCount(ast.modificationCount()); return compilationUnit; }
Example #16
Source File: MavenClasspathTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testMain() throws Exception { IProject project = importMavenProject("classpathtest"); IJavaProject javaProject = JavaCore.create(project); IType type = javaProject.findType("main.App"); ICompilationUnit cu = type.getCompilationUnit(); openDocument(cu, cu.getSource(), 1); final DiagnosticsHandler handler = new DiagnosticsHandler(javaClient, cu); WorkingCopyOwner wcOwner = getWorkingCopy(handler); cu.reconcile(ICompilationUnit.NO_AST, true, wcOwner, null); assertTrue("There aren't any problems", handler.getProblems().size() == 1); }
Example #17
Source File: MavenClasspathTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testTest() throws Exception { IProject project = importMavenProject("classpathtest"); IJavaProject javaProject = JavaCore.create(project); IType type = javaProject.findType("test.AppTest"); ICompilationUnit cu = type.getCompilationUnit(); openDocument(cu, cu.getSource(), 1); final DiagnosticsHandler handler = new DiagnosticsHandler(javaClient, cu); WorkingCopyOwner wcOwner = getWorkingCopy(handler); cu.reconcile(ICompilationUnit.NO_AST, true, wcOwner, null); assertTrue("There is a problem", handler.getProblems().size() == 0); }
Example #18
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException { IRegion region= JavaCore.newRegion(); for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { IType declaringType= iter.next().getDeclaringType(); region.add(declaringType); } fHierarchy= JavaCore.newTypeHierarchy(region, owner, pm); }
Example #19
Source File: RippleMethodFinder.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static IMethod[] getRelatedMethods(IMethod method, IProgressMonitor pm, WorkingCopyOwner owner) throws CoreException { try { if (!isVirtual(method)) { return new IMethod[]{ method }; } return new RippleMethodFinder(method).getAllRippleMethods(pm, owner); } finally { pm.done(); } }
Example #20
Source File: ReferenceFinderUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static SearchMatch[] getMethodReferencesIn(IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException { List<SearchMatch> referencedMethods= new ArrayList<SearchMatch>(); pm.beginTask("", elements.length); //$NON-NLS-1$ for (int i = 0; i < elements.length; i++) { referencedMethods.addAll(getMethodReferencesIn(elements[i], owner, new SubProgressMonitor(pm, 1))); } pm.done(); return referencedMethods.toArray(new SearchMatch[referencedMethods.size()]); }
Example #21
Source File: RenameFieldProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private SearchResultGroup[] getNewReferences(IProgressMonitor pm, RefactoringStatus status, WorkingCopyOwner owner, ICompilationUnit[] newWorkingCopies) throws CoreException { pm.beginTask("", 2); //$NON-NLS-1$ ICompilationUnit declaringCuWorkingCopy= RenameAnalyzeUtil.findWorkingCopyForCu(newWorkingCopies, fField.getCompilationUnit()); if (declaringCuWorkingCopy == null) return new SearchResultGroup[0]; IField field= getFieldInWorkingCopy(declaringCuWorkingCopy, getNewElementName()); if (field == null || ! field.exists()) return new SearchResultGroup[0]; CollectingSearchRequestor requestor= null; if (fDelegateUpdating && RefactoringAvailabilityTester.isDelegateCreationAvailable(getField())) { // There will be two new matches inside the delegate (the invocation // and the javadoc) which are OK and must not be reported. final IField oldField= getFieldInWorkingCopy(declaringCuWorkingCopy, getCurrentElementName()); requestor= new CollectingSearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (!oldField.equals(match.getElement())) super.acceptSearchMatch(match); } }; } else requestor= new CollectingSearchRequestor(); SearchPattern newPattern= SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES); IJavaSearchScope scope= RefactoringScopeFactory.create(fField, true, true); return RefactoringSearchEngine.search(newPattern, owner, scope, requestor, new SubProgressMonitor(pm, 1), status); }
Example #22
Source File: ConstructorReferenceFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IType[] getNonBinarySubtypes(WorkingCopyOwner owner, IType type, IProgressMonitor monitor) throws JavaModelException{ ITypeHierarchy hierarchy= null; if (owner == null) hierarchy= type.newTypeHierarchy(monitor); else hierarchy= type.newSupertypeHierarchy(owner, monitor); IType[] subTypes= hierarchy.getAllSubtypes(type); List<IType> result= new ArrayList<IType>(subTypes.length); for (int i= 0; i < subTypes.length; i++) { if (! subTypes[i].isBinary()) { result.add(subTypes[i]); } } return result.toArray(new IType[result.size()]); }
Example #23
Source File: ASTParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Sets the working copy owner used when resolving bindings, where * <code>null</code> means the primary owner. Defaults to the primary owner. * * @param owner the owner of working copies that take precedence over underlying * compilation units, or <code>null</code> if the primary owner should be used */ public void setWorkingCopyOwner(WorkingCopyOwner owner) { if (owner == null) { this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY; } else { this.workingCopyOwner = owner; } }
Example #24
Source File: CustomGroovyLanguageSupport.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public CompilationUnit newCompilationUnit(PackageFragment parent, String name, WorkingCopyOwner owner) { if (ContentTypeUtils.isGroovyLikeFileName(name)) { return new BonitaScriptGroovyCompilationUnit(parent, name, owner) ; } else { return new CompilationUnit(parent, name, owner); } }
Example #25
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static IMethod[] getRelatedMethods(IMethod method, ReferencesInBinaryContext binaryRefs, IProgressMonitor pm, WorkingCopyOwner owner) throws CoreException { try { if (! MethodChecks.isVirtual(method)) { return new IMethod[]{ method }; } return new RippleMethodFinder2(method, binaryRefs).getAllRippleMethods(pm, owner); } finally{ pm.done(); } }
Example #26
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static IMethod[] getRelatedMethods(IMethod method, boolean excludeBinaries, IProgressMonitor pm, WorkingCopyOwner owner) throws CoreException { try{ if (! MethodChecks.isVirtual(method)) { return new IMethod[]{ method }; } return new RippleMethodFinder2(method, excludeBinaries).getAllRippleMethods(pm, owner); } finally{ pm.done(); } }
Example #27
Source File: RenameAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
static ICompilationUnit[] createNewWorkingCopies(ICompilationUnit[] compilationUnitsToModify, TextChangeManager manager, WorkingCopyOwner owner, SubProgressMonitor pm) throws CoreException { pm.beginTask("", compilationUnitsToModify.length); //$NON-NLS-1$ ICompilationUnit[] newWorkingCopies= new ICompilationUnit[compilationUnitsToModify.length]; for (int i= 0; i < compilationUnitsToModify.length; i++) { ICompilationUnit cu= compilationUnitsToModify[i]; newWorkingCopies[i]= createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1)); } pm.done(); return newWorkingCopies; }
Example #28
Source File: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) { this.newAstToOldAst = new HashMap(); this.astNodesToBlockScope = new HashMap(); this.bindingsToAstNodes = new HashMap(); this.bindingTables = bindingTables; this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment); this.workingCopyOwner = workingCopyOwner; this.isRecoveringBindings = isRecoveringBindings; this.fromJavaProject = fromJavaProject; }
Example #29
Source File: RippleMethodFinder2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException { IRegion region= JavaCore.newRegion(); for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { IType declaringType= iter.next().getDeclaringType(); region.add(declaringType); } fHierarchy= JavaCore.newTypeHierarchy(region, owner, pm); }
Example #30
Source File: DeclaringType.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override public void codeComplete(char[] snippet, int insertion, int position, char[][] localVariableTypeNames, char[][] localVariableNames, int[] localVariableModifiers, boolean isStatic, CompletionRequestor requestor, WorkingCopyOwner owner) throws JavaModelException { // TODO Auto-generated method stub }