本文整理汇总了Java中org.eclipse.jdt.core.search.SearchMatch.getElement方法的典型用法代码示例。如果您正苦于以下问题:Java SearchMatch.getElement方法的具体用法?Java SearchMatch.getElement怎么用?Java SearchMatch.getElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.search.SearchMatch
的用法示例。
在下文中一共展示了SearchMatch.getElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllDeclarations
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (!isBinary) {
fDeclarations.add(method);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
示例2: search
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private static List<Controller> search(IJavaProject project, SearchPattern namePattern) throws JavaModelException, CoreException {
List<Controller> controllers = new ArrayList<Controller>();
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(project.getPackageFragments());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
if (match.getElement() instanceof IJavaElement) {
IJavaElement element = (IJavaElement) match.getElement();
controllers.add(new Controller((IType) element));
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(namePattern, new SearchParticipant[] {SearchEngine
.getDefaultSearchParticipant()}, scope, requestor,
null);
return controllers;
}
示例3: searchForOuterTypesOfReferences
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm)
throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern =
RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor =
new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
return; // e.g. an IImportDeclaration for a static method import
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null) return;
IType outer = declaring.getDeclaringType();
if (outer != null) outerTypesOfReferences.add(declaring);
}
};
new SearchEngine()
.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
示例4: searchForDeclarationsOfClashingMethods
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm)
throws CoreException {
final List<IMethod> results = new ArrayList<IMethod>();
SearchPattern pattern = createNewMethodPattern();
IJavaSearchScope scope = RefactoringScopeFactory.create(getMethod().getJavaProject());
SearchRequestor requestor =
new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object method = match.getElement();
if (method
instanceof
IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws
// internal exception
results.add((IMethod) method);
else
JavaPlugin.logErrorMessage(
"Unexpected element in search match: " + match.toString()); // $NON-NLS-1$
}
};
new SearchEngine()
.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return results.toArray(new IMethod[results.size()]);
}
示例5: toString
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public String toString() {
StringBuffer buf = new StringBuffer(fResouce.getFullPath().toString());
buf.append('\n');
for (int i = 0; i < fSearchMatches.size(); i++) {
SearchMatch match = fSearchMatches.get(i);
buf.append(" ")
.append(match.getOffset())
.append(", ")
.append(match.getLength()); // $NON-NLS-1$//$NON-NLS-2$
buf.append(
match.getAccuracy() == SearchMatch.A_ACCURATE
? "; acc"
: "; inacc"); // $NON-NLS-1$//$NON-NLS-2$
if (match.isInsideDocComment()) buf.append("; inDoc"); // $NON-NLS-1$
if (match.getElement() instanceof IJavaElement)
buf.append("; in: ")
.append(((IJavaElement) match.getElement()).getElementName()); // $NON-NLS-1$
buf.append('\n');
}
return buf.toString();
}
示例6: getJavaProjectFromType
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
/**
* Get java project from type.
*
* @param fullyQualifiedTypeName
* fully qualified name of type
* @return java project
* @throws CoreException
* CoreException
*/
private static List<IJavaProject> getJavaProjectFromType(String fullyQualifiedTypeName) throws CoreException {
String[] splitItems = fullyQualifiedTypeName.split("/");
// If the main class name contains the module name, should trim the module info.
if (splitItems.length == 2) {
fullyQualifiedTypeName = splitItems[1];
}
final String moduleName = splitItems.length == 2 ? splitItems[0] : null;
SearchPattern pattern = SearchPattern.createPattern(
fullyQualifiedTypeName,
IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS,
SearchPattern.R_EXACT_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
ArrayList<IJavaProject> projects = new ArrayList<>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
Object element = match.getElement();
if (element instanceof IJavaElement) {
IJavaProject project = ((IJavaElement) element).getJavaProject();
if (moduleName == null || moduleName.equals(JdtUtils.getModuleName(project))) {
projects.add(project);
}
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] {
SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null /* progress monitor */);
return projects.stream().distinct().collect(Collectors.toList());
}
示例7: findParameters
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void findParameters(final int paramNumber, SearchPattern pattern)
throws CoreException {
final SearchRequestor requestor = new SearchRequestor() {
public void acceptSearchMatch(SearchMatch match)
throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE
&& !match.isInsideDocComment()) {
IJavaElement elem = (IJavaElement) match.getElement();
ASTNode node = Util.getASTNode(elem,
ASTNodeProcessor.this.monitor);
ParameterProcessingVisitor visitor = new ParameterProcessingVisitor(
paramNumber, match.getOffset());
node.accept(visitor);
ASTNodeProcessor.this.found.addAll(visitor.getElements());
for (Iterator it = visitor.getExpressions().iterator(); it
.hasNext();) {
Expression exp = (Expression) it.next();
ASTNodeProcessor.this.processExpression(exp);
}
}
}
};
final SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
.getDefaultSearchParticipant() }, this.scope, requestor, null);
}
示例8: adjustOutgoingVisibility
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
/**
* Adjusts the visibilities of the referenced element from the search match found in a compilation
* unit.
*
* @param match the search match representing the element declaration
* @param monitor the progress monitor to use
* @throws JavaModelException if the visibility could not be determined
*/
private void adjustOutgoingVisibility(final SearchMatch match, final IProgressMonitor monitor)
throws JavaModelException {
final Object element = match.getElement();
if (element instanceof IMember) {
final IMember member = (IMember) element;
if (!member.isBinary() && !member.isReadOnly() && !isInsideMovedMember(member)) {
adjustOutgoingVisibilityChain(member, monitor);
}
}
}
示例9: getOldSourceRange
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private static ISourceRange getOldSourceRange(SearchMatch newMatch) {
// cannot transfom offset in preview to offset in original -> just show enclosing method
IJavaElement newMatchElement = (IJavaElement) newMatch.getElement();
IJavaElement primaryElement = newMatchElement.getPrimaryElement();
ISourceRange range = null;
if (primaryElement.exists() && primaryElement instanceof ISourceReference) {
try {
range = ((ISourceReference) primaryElement).getSourceRange();
} catch (JavaModelException e) {
// can live without source range
}
}
return range;
}
示例10: findAllDeclarations
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner)
throws CoreException {
fDeclarations = new ArrayList<IMethod>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
fDeclarations.add(method);
}
if (isBinary && fBinaryRefs != null) {
fDeclarationToMatch.put(method, match);
}
}
}
int limitTo =
IJavaSearchConstants.DECLARATIONS
| IJavaSearchConstants.IGNORE_DECLARING_TYPE
| IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope =
RefactoringScopeFactory.createRelatedProjectsScope(
fMethod.getJavaProject(),
IJavaSearchScope.SOURCES
| IJavaSearchScope.APPLICATION_LIBRARIES
| IJavaSearchScope.SYSTEM_LIBRARIES);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, participants, scope, requestor, monitor);
}
示例11: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IJavaElement enclosingElement = (IJavaElement) match.getElement();
if (enclosingElement != null) {
if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE)) return;
boolean isWriteAccess = false;
boolean isReadAccess = false;
if (match instanceof FieldReferenceMatch) {
FieldReferenceMatch fieldRef = ((FieldReferenceMatch) match);
isWriteAccess = fieldRef.isWriteAccess();
isReadAccess = fieldRef.isReadAccess();
} else if (match instanceof FieldDeclarationMatch) {
isWriteAccess = true;
} else if (match instanceof LocalVariableReferenceMatch) {
LocalVariableReferenceMatch localVarRef = ((LocalVariableReferenceMatch) match);
isWriteAccess = localVarRef.isWriteAccess();
isReadAccess = localVarRef.isReadAccess();
} else if (match instanceof LocalVariableDeclarationMatch) {
isWriteAccess = true;
}
boolean isSuperInvocation = false;
if (match instanceof MethodReferenceMatch) {
MethodReferenceMatch methodRef = (MethodReferenceMatch) match;
isSuperInvocation = methodRef.isSuperInvocation();
}
fSearch.addMatch(
new JavaElementMatch(
enclosingElement,
match.getRule(),
match.getOffset(),
match.getLength(),
match.getAccuracy(),
isReadAccess,
isWriteAccess,
match.isInsideDocComment(),
isSuperInvocation));
}
}
示例12: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) {
Object element = match.getElement();
if (element instanceof IType || element instanceof IMethod) {
IMember member = (IMember) element;
IType type =
member.getElementType() == IJavaElement.TYPE
? (IType) member
: member.getDeclaringType();
addTypeAndSubtypes(type);
}
}
}
示例13: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.isInsideDocComment()) {
return;
}
if (match.getElement() != null && match.getElement() instanceof IJavaElement) {
IJavaElement member = (IJavaElement) match.getElement();
if(!searchElements.contains(member)) {
addMatch(match);
searchElements.add(member);
}
}
}
示例14: getExistingCategories
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private List<String> getExistingCategories() {
if(existingCategories==null) {
final Set<String> categories = new TreeSet<String>();
if(selectedJavaProject!=null) {
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if(match.getElement() instanceof IType) {
String fqn = ((IType) match.getElement()).getFullyQualifiedName();
if(!fqn.startsWith("net.sf.jasperreports.functions.standard")) {
// avoid to propose standard functions categories
categories.add(fqn);
}
}
}
};
IJavaElement[] elements= new IJavaElement[] { selectedJavaProject };
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);
int matchRule= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern fullAnnotationPattern= SearchPattern.createPattern(
"net.sf.jasperreports.functions.annotations.FunctionCategory", IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule);
SearchPattern simpleNamePattern= SearchPattern.createPattern(
"FunctionCategory", IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule);
SearchPattern annotationsPattern= SearchPattern.createOrPattern(fullAnnotationPattern, simpleNamePattern);
SearchParticipant[] searchParticipants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
try {
new SearchEngine().search(annotationsPattern, searchParticipants, scope, requestor,new NullProgressMonitor());
} catch (CoreException e) {
}
}
existingCategories = new ArrayList<String>(categories);
((NewFunctionsLibraryWizard)getWizard()).setAvailableCategories(existingCategories);
}
return existingCategories;
}
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:36,代码来源:FunctionsLibraryInformationPage.java
示例15: findElementsAtSelection
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
public static IJavaElement[] findElementsAtSelection(ITypeRoot unit, int line, int column)
throws JavaModelException, BadLocationException {
if (unit == null) {
return null;
}
int offset = toDocument(unit.getBuffer()).getLineOffset(line) + column;
if (offset > -1) {
return unit.codeSelect(offset, 0);
}
if (unit instanceof IClassFile) {
IClassFile classFile = (IClassFile) unit;
String contents = disassemble(classFile);
if (contents != null) {
IDocument document = new Document(contents);
try {
offset = document.getLineOffset(line) + column;
if (offset > -1) {
String name = parse(contents, offset);
if (name == null) {
return null;
}
SearchPattern pattern = SearchPattern.createPattern(name, IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH);
IJavaSearchScope scope = createSearchScope(unit.getJavaProject());
List<IJavaElement> elements = new ArrayList<>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
if (match.getElement() instanceof IJavaElement) {
elements.add((IJavaElement) match.getElement());
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern,
new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null);
return elements.toArray(new IJavaElement[0]);
}
} catch (BadLocationException | CoreException e) {
// JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
return null;
}