org.eclipse.search.ui.text.Match Java Examples

The following examples show how to use org.eclipse.search.ui.text.Match. 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: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
	IEditorPart editor= fEditorOpener.openMatch(match);

	if (editor != null && activate)
		editor.getEditorSite().getPage().activate(editor);
	Object element= match.getElement();
	if (editor instanceof ITextEditor) {
		ITextEditor textEditor= (ITextEditor) editor;
		textEditor.selectAndReveal(offset, length);
	} else if (editor != null) {
		if (element instanceof IFile) {
			IFile file= (IFile) element;
			showWithMarker(editor, file, offset, length);
		}
	} else if (getInput() instanceof JavaSearchResult) {
		JavaSearchResult result= (JavaSearchResult) getInput();
		IMatchPresentation participant= result.getSearchParticpant(element);
		if (participant != null)
			participant.showMatch(match, offset, length, activate);
	}
}
 
Example #2
Source File: ModulaSearchResultPage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected void showMatch( Match match, int currentOffset
                        , int currentLength, boolean activate 
                        ) throws PartInitException 
{
    if (match instanceof ModulaSymbolMatch) {
        try {
            ModulaSymbolMatch em = (ModulaSymbolMatch)match;
            IFile f = em.getFile();
            IWorkbenchPage page = WorkbenchUtils.getActivePage();
            IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(f.getName());
            IEditorPart ep = page.openEditor(new FileEditorInput(f), desc.getId());
            ITextEditor te = (ITextEditor)ep;
            Control ctr = (Control)te.getAdapter(Control.class);
            ctr.setFocus();
            te.selectAndReveal(em.getOffset(), em.getLength());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #3
Source File: AbstractJavaSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void collectMatches(Set<Match> matches, IJavaElement element) {
	Match[] m= getMatches(element);
	if (m.length != 0) {
		for (int i= 0; i < m.length; i++) {
			matches.add(m[i]);
		}
	}
	if (element instanceof IParent) {
		IParent parent= (IParent) element;
		try {
			IJavaElement[] children= parent.getChildren();
			for (int i= 0; i < children.length; i++) {
				collectMatches(matches, children[i]);
			}
		} catch (JavaModelException e) {
			// we will not be tracking these results
		}
	}
}
 
Example #4
Source File: ModulaSearchQuery.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public IStatus run(IProgressMonitor monitor) {
	final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult();
	result.removeAll();
	ISearchResultCollector collector = new ISearchResultCollector() {
		public void accept(Object match) {
			if (match instanceof Match) {
				result.addMatch((Match)match); // match.getElement() is IFile
			}
		}
	};
	ModulaSearchOperation op = new ModulaSearchOperation(fSearchInput, collector);
	MultiStatus status = new MultiStatus(XdsPlugin.PLUGIN_ID, IStatus.OK, Messages.M2SearchQuery_SearchProblems, null);
	op.execute(monitor, status);
	monitor.done();
	return status;
}
 
Example #5
Source File: AbstractSearchResultTreePage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object getParent(Object element) {
    if (element instanceof Match) {
        Object f = ((Match)element).getElement();
        if (f instanceof IFile) {
            if (showProjectTree) {
                return resultModel.searchModelItemForFile((IFile)f);
            } else {
                return f;
            }
        }
    } else if (element instanceof ModelItem) {
        return ((ModelItem)element).getParent();
    } else if ((element instanceof IFile)) {
        ModelItem mit = resultModel.searchModelItemForFile((IFile)element);
        if (mit != null) {
            // it was stripped IFile (see stripIFiles() )
            return mit.getParent();
        }
    }
    // else - it is IFile with showProjectTree==false => it is root
    return null;
}
 
Example #6
Source File: AbstractSearchResultTreePage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void showMatch(final Match match, final boolean activateEditor) {
    ISafeRunnable runnable = new ISafeRunnable() {
        public void handleException(Throwable exception) {
            if (exception instanceof PartInitException) {
                PartInitException pie = (PartInitException) exception;
                ErrorDialog.openError(getSite().getShell(), "Show match", "Could not find an editor for the current match", pie.getStatus());
            }
        }

        public void run() throws Exception {
            IRegion location= getCurrentMatchLocation(match);
            showMatch(match, location.getOffset(), location.getLength(), activateEditor);
        }
    };
    SafeRunner.run(runnable);
}
 
Example #7
Source File: OccurrencesSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
	//TODO same code in JavaSearchResult
	IEditorInput editorInput= editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput)  {
		IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput;
		return computeContainedMatches(result, fileEditorInput.getFile());

	} else if (editorInput instanceof IClassFileEditorInput) {
		IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput;
		IClassFile classFile= classFileEditorInput.getClassFile();

		Object[] elements= getElements();
		if (elements.length == 0)
			return NO_MATCHES;
		//all matches from same file:
		JavaElementLine jel= (JavaElementLine) elements[0];
		if (jel.getJavaElement().equals(classFile))
			return collectMatches(elements);
	}
	return NO_MATCHES;
}
 
Example #8
Source File: OccurrencesSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isShownInEditor(Match match, IEditorPart editor) {
	Object element= match.getElement();
	IJavaElement je= ((JavaElementLine) element).getJavaElement();
	IEditorInput editorInput= editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput) {
		try {
			return ((IFileEditorInput)editorInput).getFile().equals(je.getCorrespondingResource());
		} catch (JavaModelException e) {
			return false;
		}
	} else if (editorInput instanceof IClassFileEditorInput) {
		return ((IClassFileEditorInput)editorInput).getClassFile().equals(je);
	}

	return false;
}
 
Example #9
Source File: NLSSearchResultRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addMatch(FileEntry groupElement, String propertyName) {
	/*
	 * TODO (bug 63794): Should read in .properties file with our own reader and not
	 * with Properties.load(InputStream) . Then, we can remember start position and
	 * original version (not interpreting escape characters) for each property.
	 *
	 * The current workaround is to escape the key again before searching in the
	 * .properties file. However, this can fail if the key is escaped in a different
	 * manner than what PropertyFileDocumentModel.unwindEscapeChars(.) produces.
	 */
	String escapedPropertyName= PropertyFileDocumentModel.escape(propertyName, false);
	int start= findPropertyNameStartPosition(escapedPropertyName);
	int length;
	if (start == -1) { // not found -> report at beginning
		start= 0;
		length= 0;
	} else {
		length= escapedPropertyName.length();
	}
	fResult.addMatch(new Match(groupElement, start, length));
}
 
Example #10
Source File: ModulaSearchOperation.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void matchSymbolReferences( IModuleSymbol moduleSymbol
                                  , IModulaSymbol modulaSymbol
                                  , @SuppressWarnings("rawtypes") List<Class> expectedSymbolClasses
                                  , IFile f
                                  , List<Match> matches )
{
    boolean isOneOfTheExpected = expectedSymbolClasses == null;
    if (!isOneOfTheExpected) {
        for (Class<?> expectedSymbolClass : expectedSymbolClasses) {
            if (expectedSymbolClass.isAssignableFrom(modulaSymbol.getClass())) {
                isOneOfTheExpected = true;
                break;
            }
        }
    }
    if (isOneOfTheExpected && isSymbolNameMatches(modulaSymbol)) {
        createMatchesFromUsages(moduleSymbol, modulaSymbol, f, matches);
    }
}
 
Example #11
Source File: FileLabelProvider.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private int evaluateLineStart(Match[] matches, String lineContent, int lineOffset) {
    int max = lineContent.length();
    if (matches.length > 0) {
        FileMatch match = (FileMatch) matches[0];
        max = match.getOriginalOffset() - lineOffset;
        if (max < 0) {
            return 0;
        }
    }
    for (int i = 0; i < max; i++) {
        char ch = lineContent.charAt(i);
        if (!Character.isWhitespace(ch) || ch == '\n' || ch == '\r') {
            return i;
        }
    }
    return max;
}
 
Example #12
Source File: TypeScriptSearchTreeContentProvider.java    From typescript.java with MIT License 6 votes vote down vote up
private synchronized void initialize(AbstractTextSearchResult result) {
	fResult= result;
	fChildrenMap= new HashMap();
	boolean showLineMatches= true; //!((TypeScriptSearchQuery) fResult.getQuery()).isFileNameSearch();
	
	if (result != null) {
		Object[] elements= result.getElements();
		for (int i= 0; i < elements.length; i++) {
			if (showLineMatches) {
				Match[] matches= result.getMatches(elements[i]);
				for (int j= 0; j < matches.length; j++) {
					insert(((TypeScriptMatch) matches[j]).getLineElement(), false);
				}
			} else {
				insert(elements[i], false);
			}
		}
	}
}
 
Example #13
Source File: TypeScriptSearchLabelProvider.java    From typescript.java with MIT License 6 votes vote down vote up
private int evaluateLineStart(Match[] matches, String lineContent, int lineOffset) {
	int max= lineContent.length();
	if (matches.length > 0) {
		TypeScriptMatch match= (TypeScriptMatch) matches[0];
		max= match.getOriginalOffset() - lineOffset;
		if (max < 0) {
			return 0;
		}
	}
	for (int i= 0; i < max; i++) {
		char ch= lineContent.charAt(i);
		if (!Character.isWhitespace(ch) || ch == '\n' || ch == '\r') {
			return i;
		}
	}
	return max;
}
 
Example #14
Source File: SearchResultUpdater.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDelta(IResourceDelta d) {
    try {
        d.accept(new IResourceDeltaVisitor() {
            @Override
            public boolean visit(IResourceDelta delta) throws CoreException {
                switch (delta.getKind()) {
                    case IResourceDelta.ADDED:
                        return false;
                    case IResourceDelta.REMOVED:
                        IResource res = delta.getResource();
                        if (res instanceof IFile) {
                            Match[] matches = fResult.getMatches(res);
                            fResult.removeMatches(matches);
                        }
                        break;
                    case IResourceDelta.CHANGED:
                        // handle changed resource
                        break;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        Log.log(e);
    }
}
 
Example #15
Source File: ReplaceRefactoring.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isSkipped(Match match) {
    if (this.fSkipMatch != null) {
        if (this.fSkipMatch.call(match)) {
            return true;
        }
    }
    return !fSkipFiltered && match.isFiltered();
}
 
Example #16
Source File: ReplaceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the replace action to be
 * @param shell the parent shell
 * @param result the file search page to
 * @param selection the selected entries or <code>null</code> to replace all
 * @param skipFiltered if set to <code>true</code>, filtered matches will not be replaced
 */
public ReplaceAction(Shell shell, AbstractTextSearchResult result, Object[] selection, boolean skipFiltered,
        ICallback<Boolean, Match> skipMatch) {
    fShell = shell;
    fResult = result;
    fSelection = selection;
    fSkipFiltered = skipFiltered;
    fSkipMatch = skipMatch;
}
 
Example #17
Source File: SearchIndexLabelProvider.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private int getCharsToCut(int contentLength, Match[] matches) {
    if (contentLength <= 256 || !"win32".equals(SWT.getPlatform()) || matches.length == 0) { //$NON-NLS-1$
        return 0; // no shortening required
    }
    // XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=38519
    return contentLength - 256 + Math.max(matches.length * fgEllipses.length(), 100);
}
 
Example #18
Source File: ReplaceRefactoring.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private Collection<Match> getBucket(IFile file) {
    Set<Match> col = fMatches.get(file);
    if (col == null) {
        col = new HashSet<>();
        fMatches.put(file, col);
    }
    return col;
}
 
Example #19
Source File: AbstractSearchIndexTreeContentProvider.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    elementToTreeNode.clear();
    if (newInput instanceof AbstractTextSearchResult) {
        AbstractTextSearchResult abstractTextSearchResult = (AbstractTextSearchResult) newInput;
        this.fResult = abstractTextSearchResult;
        root = new TreeNode<>(null, newInput);
        Object[] elements = abstractTextSearchResult.getElements();
        int elementsLen = elements.length;
        for (int i = 0; i < elementsLen; i++) {
            Object object = elements[i];
            Match[] matches = abstractTextSearchResult.getMatches(object);
            int matchesLen = matches.length;
            for (int j = 0; j < matchesLen; j++) {
                Match match = matches[j];
                if (match instanceof ICustomMatch) {
                    ICustomMatch moduleMatch = (ICustomMatch) match;
                    obtainTeeNodeElement(moduleMatch.getLineElement());
                } else {
                    Log.log("Expecting ICustomMatch. Found:" + match.getClass() + " - " + match);
                }
            }
        }
    } else {
        this.clear();
    }
}
 
Example #20
Source File: SearchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final int getNumberOfPotentialMatches(Object element) {
	int res= 0;
	AbstractTextSearchResult result= fPage.getInput();
	if (result != null) {
		Match[] matches= result.getMatches(element);
		for (int i = 0; i < matches.length; i++) {
			if ((matches[i]) instanceof JavaElementMatch) {
				if (((JavaElementMatch)matches[i]).getAccuracy() == SearchMatch.A_INACCURATE)
					res++;
			}
		}
	}
	return res;
}
 
Example #21
Source File: JavaSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
boolean addMatch(Match match, IMatchPresentation participant) {
	Object element= match.getElement();
	if (fElementsToParticipants.get(element) != null) {
		// TODO must access the participant id / label to properly report the error.
		JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, "A second search participant was found for an element", null)); //$NON-NLS-1$
		return false;
	}
	fElementsToParticipants.put(element, participant);
	addMatch(match);
	return true;
}
 
Example #22
Source File: AbstractJavaSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isShownInEditor(Match match, IEditorPart editor) {
	Object element= match.getElement();
	if (element instanceof IJavaElement) {
		element= ((IJavaElement) element).getOpenable(); // class file or compilation unit
		return element != null && element.equals(editor.getEditorInput().getAdapter(IJavaElement.class));
	} else if (element instanceof IFile) {
		return element.equals(editor.getEditorInput().getAdapter(IFile.class));
	}
	return false;
}
 
Example #23
Source File: ReplaceRefactoring.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public int getNumberOfMatches() {
    int count = 0;
    for (Iterator<Set<Match>> iterator = fMatches.values().iterator(); iterator.hasNext();) {
        Collection<Match> bucket = iterator.next();
        count += bucket.size();
    }
    return count;
}
 
Example #24
Source File: JavaSearchQuery.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void reportMatch(Match match) {
	IMatchPresentation participant= fParticipant.getUIParticipant();
	if (participant == null || match.getElement() instanceof IJavaElement || match.getElement() instanceof IResource) {
		fSearchResult.addMatch(match);
	} else {
		fSearchResult.addMatch(match, participant);
	}
}
 
Example #25
Source File: NLSSearchEditorOpener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object getElementToOpen(Match match) {
	Object element= match.getElement();
	if (element instanceof IJavaElement) {
		return element;
	} else if (element instanceof FileEntry) {
		FileEntry fileEntry= (FileEntry) element;
		return fileEntry.getPropertiesFile();
	} else if (element instanceof CompilationUnitEntry) {
		return ((CompilationUnitEntry)element).getCompilationUnit();
	}
	// this should not happen
	return null;
}
 
Example #26
Source File: SearchIndexResult.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
    IEditorInput ei = editor.getEditorInput();
    if (ei instanceof IFileEditorInput) {
        IFileEditorInput fi = (IFileEditorInput) ei;
        return getMatches(fi.getFile());
    }
    return EMPTY_ARR;
}
 
Example #27
Source File: NLSSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
	//TODO: copied from JavaSearchResult:
	IEditorInput editorInput= editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput)  {
		IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput;
		return computeContainedMatches(result, fileEditorInput.getFile());
	} else if (editorInput instanceof IClassFileEditorInput) {
		IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput;
		Set<Match> matches= new HashSet<Match>();
		collectMatches(matches, classFileEditorInput.getClassFile());
		return matches.toArray(new Match[matches.size()]);
	}
	return NO_MATCHES;
}
 
Example #28
Source File: NLSSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
	IEditorPart editor= fEditorOpener.openMatch(match);
	if (editor != null && activate)
		editor.getEditorSite().getPage().activate(editor);
	if (editor instanceof ITextEditor) {
		ITextEditor textEditor= (ITextEditor) editor;
		textEditor.selectAndReveal(currentOffset, currentLength);
	}
}
 
Example #29
Source File: FileSearchPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Match[] getDisplayedMatches(Object element) {
    if (showLineMatches()) {
        if (element instanceof LineElement) {
            LineElement lineEntry = (LineElement) element;
            return lineEntry.getMatches(getInput());
        }
        return new Match[0];
    }
    return super.getDisplayedMatches(element);
}
 
Example #30
Source File: ImplementationsSearchQuery.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@Override public IStatus run(IProgressMonitor monitor) {
	startTime = System.currentTimeMillis();
	// Cancel last references future if needed.
	if (references != null) {
		references.cancel(true);
	}
	AbstractTextSearchResult textResult = (AbstractTextSearchResult) getSearchResult();
	textResult.removeAll();

	try {
		// Execute LSP "references" service
		ReferenceParams params = new ReferenceParams();
		params.setContext(new ReferenceContext(true));
		params.setTextDocument(new TextDocumentIdentifier(info.getFileUri().toString()));
		params.setPosition(position);
		info.getInitializedLanguageClient().thenCompose(languageServer -> ((RLSServerInterface) languageServer).implementations(params)).thenAccept(locs -> {
			// Loop for each LSP Location and convert it to Match search.
			for (Location loc : locs) {
				Match match = toMatch(loc);
				result.addMatch(match);
			}
		});
		return Status.OK_STATUS;
	} catch (Exception ex) {
		return new Status(IStatus.ERROR, LanguageServerPlugin.getDefault().getBundle().getSymbolicName(), ex.getMessage(), ex);
	}
}