List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants WAIT_UNTIL_READY_TO_SEARCH
int WAIT_UNTIL_READY_TO_SEARCH
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants WAIT_UNTIL_READY_TO_SEARCH.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java
License:Open Source License
private void createSubtypeProposals(final ContentAssistRequest contentAssistRequest, final CompletionProposalInvocationContext context, IType superType) { IJavaProject jproject = findProject(contentAssistRequest); try {/*from w w w . j ava2 s . c om*/ IJavaSearchScope hierarchyScope = SearchEngine.createHierarchyScope(superType); IJavaSearchScope projectScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { jproject }); IJavaSearchScope scope = new IntersectingJavaSearchScope(projectScope, hierarchyScope); SearchEngine searchEngine = new SearchEngine(); char[] typeName = null; char[] packageName = null; if (!contentAssistRequest.getMatchString().isEmpty()) { typeName = contentAssistRequest.getMatchString().toCharArray(); } searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { String sPackageName = new String(packageName); int priority = PRIORITY_LOWER_1; if (sPackageName.startsWith("com.sun.javafx")) { priority -= 10; } StyledString s = new StyledString(new String(simpleTypeName)); s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER); FXMLCompletionProposal prop = createElementProposal(contentAssistRequest, context, sPackageName + "." + new String(simpleTypeName) + " ", s, false, priority, IconKeys.getIcon(IconKeys.CLASS_KEY), FQN_MATCHER); if (prop != null) { prop.setMatcher(FQN_MATCHER); prop.setTextApplier(new IReplacementTextApplier() { @Override public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException { String proposalReplacementString = proposal.getReplacementString(); List<String> s = getImportedTypes(contentAssistRequest); String shortened = proposalReplacementString .substring(proposalReplacementString.lastIndexOf('.') + 1); if (s.contains(proposalReplacementString.trim())) { proposal.setCursorPosition(shortened.length()); document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), shortened); } else { DocumentRewriteSession rewriteSession = null; try { if (document instanceof IDocumentExtension4) { rewriteSession = ((IDocumentExtension4) document) .startRewriteSession( DocumentRewriteSessionType.UNRESTRICTED_SMALL); } } finally { if (rewriteSession != null) { ((IDocumentExtension4) document) .stopRewriteSession(rewriteSession); } // if (viewerExtension != null) // viewerExtension.setRedraw(true); } boolean startWithLineBreak = true; boolean endWithLineBreak = false; Document xmlDoc = contentAssistRequest.getNode().getOwnerDocument(); NodeList list = xmlDoc.getChildNodes(); int offset = 0; List<Node> prs = new ArrayList<Node>(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { prs.add(n); } } if (!prs.isEmpty()) { offset = ((IDOMNode) prs.get(prs.size() - 1)).getEndOffset(); } offset = Math.min(proposal.getReplacementOffset(), offset); proposal.setCursorPosition(shortened.length()); document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), shortened); String importStatement = (startWithLineBreak ? "\n<?import " : "import ") + proposalReplacementString.trim(); importStatement += "?>"; if (endWithLineBreak) importStatement += "\n\n"; document.replace(offset, 0, importStatement.toString()); proposal.setCursorPosition( proposal.getCursorPosition() + importStatement.length()); } } }); contentAssistRequest.addProposal(prop); } } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java
License:Open Source License
@Override protected void addAttributeValueProposals(final ContentAssistRequest contentAssistRequest, final CompletionProposalInvocationContext context) { IDOMNode n = (IDOMNode) contentAssistRequest.getNode(); if (Character.isUpperCase(n.getNodeName().charAt(0))) { NamedNodeMap m = n.getAttributes(); IDOMNode attribute = null;/*from w w w.j a va2s .co m*/ for (int i = 0; i < m.getLength(); i++) { IDOMNode a = (IDOMNode) m.item(i); if (a.contains(contentAssistRequest.getStartOffset())) { attribute = a; } } if (attribute != null) { if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) { if ("constant".equals(attribute.getLocalName())) { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { try { List<IField> fields = new ArrayList<IField>(); collectStaticFields(fields, type); for (IField f : fields) { StyledString s = new StyledString(f.getElementName() + " : " + Signature.getSimpleName(Signature.toString(f.getTypeSignature()))); String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName(); s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + f.getElementName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if ("controller".equals(attribute.getLocalName())) { IJavaProject jproject = findProject(contentAssistRequest); char[] typeName = null; char[] packageName = null; if (!contentAssistRequest.getMatchString().isEmpty()) { if (contentAssistRequest.getMatchString().startsWith("\"")) { typeName = contentAssistRequest.getMatchString().substring(1).toCharArray(); } else { typeName = contentAssistRequest.getMatchString().toCharArray(); } } IJavaSearchScope searchScope = SearchEngine .createJavaSearchScope(new IJavaElement[] { jproject }); SearchEngine searchEngine = new SearchEngine(); try { searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.TYPE, searchScope, new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { String sPackageName = new String(packageName); int priority = PRIORITY_LOWER_1; if (sPackageName.startsWith("com.sun")) { priority -= 10; } StyledString s = new StyledString(new String(simpleTypeName)); s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + sPackageName + "." + new String(simpleTypeName), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if (attribute.getNodeName().contains(".")) { String[] parts = attribute.getNodeName().split("\\."); IType type = findType(parts[0], contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getStaticProperty(parts[1]); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } } } } else { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getProperty(attribute.getNodeName()); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } else if (p instanceof IFXEventHandlerProperty) { createAttributeValueEventHandlerProposals(contentAssistRequest, context, (IFXEventHandlerProperty) p); } } } } } } }
From source file:ca.ubc.cs.ferret.tests.support.TestProject.java
License:Open Source License
public void waitForIndexer() throws JavaModelException { new SearchEngine().searchAllTypeNames(null, null, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS, SearchEngine.createJavaSearchScope(new IJavaElement[0]), new TypeNameRequestor() { // nothing needs to be done here...we accept everything }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.EventsTab.java
License:Open Source License
private static Set<IType> findTypeInWorkspace(String typeName) throws CoreException { int dot = typeName.lastIndexOf('.'); char[][] qualifications; String simpleName;//from ww w . ja v a2 s. co m if (dot != -1) { qualifications = new char[][] { typeName.substring(0, dot).toCharArray() }; simpleName = typeName.substring(dot + 1); } else { qualifications = null; simpleName = typeName; } char[][] typeNames = new char[][] { simpleName.toCharArray() }; ContrastTypeNameMatchRequestor contrastTypeNameMatchRequestor = new ContrastTypeNameMatchRequestor(); new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(), contrastTypeNameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return contrastTypeNameMatchRequestor.getTypeNameMatches(); }
From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java
License:Open Source License
public List<TypeNameMatch> searchRawClassInfo(String className) throws JavaModelException { final List<TypeNameMatch> results = new ArrayList<TypeNameMatch>(); TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override/*from ww w. j a va2 s . co m*/ public void acceptTypeNameMatch(TypeNameMatch match) { results.add(match); } }; new SearchEngine().searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, className.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return results; }
From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java
License:Open Source License
public List<TypeNameMatch> searchRawClassesInfo(String... classNames) throws JavaModelException { // name/*from w w w . ja va 2 s . c o m*/ char[][] charClassNames = new char[classNames.length][]; for (int i = 0; i < charClassNames.length; i++) charClassNames[i] = classNames[i].toCharArray(); // requestor final List<TypeNameMatch> results = new ArrayList<TypeNameMatch>(); TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { results.add(match); } }; new SearchEngine().searchAllTypeNames(null, charClassNames, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return results; }
From source file:com.siteview.mde.internal.ui.editor.contentassist.TypePackageCompletionProcessor.java
License:Open Source License
protected void generateTypeProposals(String currentContent, IProject project, final Collection c, final int startOffset, final int length, int typeScope) { // Dynamically adjust the search scope depending on the current // state of the project IJavaSearchScope scope = PDEJavaHelper.getSearchScope(project); char[] packageName = null; char[] typeName = null; int index = currentContent.lastIndexOf('.'); if (index == -1) { // There is no package qualification // Perform the search only on the type name typeName = currentContent.toCharArray(); } else if ((index + 1) == currentContent.length()) { // There is a package qualification and the last character is a // dot/*w w w . jav a 2 s. co m*/ // Perform the search for all types under the given package // Pattern for all types typeName = "".toCharArray(); //$NON-NLS-1$ // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } else { // There is a package qualification, followed by a dot, and // a type fragment // Type name without the package qualification typeName = currentContent.substring(index + 1).toCharArray(); // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } try { TypeNameRequestor req = new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Accept search results from the JDT SearchEngine String cName = new String(simpleTypeName); String pName = new String(packageName); String label = cName + " - " + pName; //$NON-NLS-1$ String content = pName + "." + cName; //$NON-NLS-1$ Image image = (Flags.isInterface(modifiers)) ? MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_INTERFACE) : MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_CLASS); addProposalToCollection(c, startOffset, length, label, content, image); } }; // Note: Do not use the search() method, its performance is // bad compared to the searchAllTypeNames() method fSearchEngine.searchAllTypeNames(packageName, SearchPattern.R_EXACT_MATCH, typeName, SearchPattern.R_PREFIX_MATCH, typeScope, scope, req, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { fErrorMessage = e.getMessage(); } }
From source file:com.technophobia.substeps.junit.action.OpenEditorAction.java
License:Open Source License
protected final IType findType(final IJavaProject project, final String testClassName) { final IType[] result = { null }; final String dottedName = testClassName.replace('$', '.'); // for nested // classes... try {//ww w.j av a 2 s . c o m PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (project != null) { result[0] = internalFindType(project, dottedName, new HashSet<IJavaProject>(), monitor); } if (result[0] == null) { final int lastDot = dottedName.lastIndexOf('.'); final TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(final TypeNameMatch match) { result[0] = match.getType(); } }; new SearchEngine().searchAllTypeNames( lastDot >= 0 ? dottedName.substring(0, lastDot).toCharArray() : null, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, (lastDot >= 0 ? dottedName.substring(lastDot + 1) : dottedName).toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } } catch (final JavaModelException e) { throw new InvocationTargetException(e); } } }); } catch (final InvocationTargetException e) { FeatureRunnerPlugin.log(e); } catch (final InterruptedException e) { // user cancelled } return result[0]; }
From source file:dacapo.eclipse.EclipseIndexTests.java
License:Open Source License
protected static void waitUntilIndexesReady() { /**/*from ww w . j a v a2 s . c o m*/ * Simple Job which does nothing */ class DoNothing implements IJob { /** * Answer true if the job belongs to a given family (tag) */ public boolean belongsTo(String jobFamily) { return true; } /** * Asks this job to cancel its execution. The cancellation * can take an undertermined amount of time. */ public void cancel() { // nothing to cancel } /** * Ensures that this job is ready to run. */ public void ensureReadyToRun() { // always ready to do nothing } /** * Execute the current job, answer whether it was successful. */ public boolean execute(IProgressMonitor progress) { // always succeed to do nothing return true; } } // Run simple job which does nothing but wait for indexing end indexManager.performConcurrentJob(new DoNothing(), IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); // assertEquals("Index manager should not have remaining jobs!", 0, indexManager.awaitingJobsCount()); //$NON-NLS-1$ }
From source file:de.jcup.egradle.eclipse.gradleeditor.jdt.JDTDataAccess.java
License:Apache License
/** * Find type/*w w w . j a v a 2s. c o m*/ * * @param className * @param monitor * @return type or <code>null</code> */ public IType findType(String className, IProgressMonitor monitor) { final IType[] result = { null }; TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { result[0] = match.getType(); } }; int lastDot = className.lastIndexOf('.'); char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null; char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray(); SearchEngine engine = new SearchEngine(); int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; try { engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { EGradleUtil.log(e); } return result[0]; }