Find fields with SearchEngine [message #336149] |
Tue, 26 May 2009 20:25 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
michel Labarre![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=michel.labarre%40helicom.fr) Messages: 7 Registered: July 2009 |
Junior Member |
|
|
Hello
My problem concerns the results of the SearchEngine used in a plugin
implementing CompletionAssist in javaEditor. My goal is obtain all fields
in a method. The following code permits to get all member class fields but
not the fields declared in the method. Is-it possible to do? What's failed
in my code ?
------------------------------------------------------------ ----------------
IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
IJavaElement element= JavaUI.getEditorInputJavaElement(
page.getActiveEditor().getEditorInput());
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(
new IJavaElement[] { element } ,true);
IEditorPart editor = page.getActiveEditor();
IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
IJavaProject project = JavaCore.create(file.getProject());
SearchPattern searchPattern = SearchPattern.createPattern(
"*",
IJavaSearchConstants.FIELD,
IJavaSearchConstants.DECLARATIONS,
SearchPattern.R_PATTERN_MATCH);
final List<Object> list = new ArrayList<Object>();
SearchRequestor requestor = new SearchRequestor() {
public void acceptSearchMatch(SearchMatch match) {
Object element = match.getElement();
list.add((Object)element);
if (element instanceof IJavaElement) {
logger.debug("element is IJavaElement");
IJavaElement e = (IJavaElement)element;
logger.debug(e.getAdapter(IJavaElement.class));
logger.debug(e.getClass());
}
}
};
SearchEngine searchEngine = new SearchEngine();
try {
searchEngine.search(searchPattern,
new SearchParticipant[] {
SearchEngine.getDefaultSearchParticipant()},
scope,
requestor,
new NullProgressMonitor());
} catch (CoreException e) {
logger.debug(e.getMessage());
}
------------------------------------------------------------ ---------------
So, editing the following sample class :
------------------------------------------------------------ ---------------
public class cc {
private Object1 obj1= null;
private Object2 obj2= null;
/**
* Main
*/
public static void main(String[] args) {
new cc();
}
/**
* Constructor
*/
public cc() {
try {
....
Object3 obj3 = new Object3();
// Fills input datas
obj3.get <---------------- completion
}
}
}
------------------------------------------------------------ --------------
... when I ask completion, my code is executed but only obj1 and obj2 are
found... not obj3 in constructor...
Thanks for your help
|
|
|
Re: Find fields with SearchEngine [message #336188 is a reply to message #336149] |
Thu, 28 May 2009 12:51 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Dani Megert![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=Daniel_Megert%40ch.ibm.com) Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
michel wrote:
> Hello
> My problem concerns the results of the SearchEngine used in a plugin
> implementing CompletionAssist in javaEditor. My goal is obtain all
> fields in a method. The following code permits to get all member class
> fields but not the fields declared in the method.
Fields cannot be declared inside a method.
Dani
> Is-it possible to do? What's failed in my code ?
>
> ------------------------------------------------------------ ----------------
>
> IWorkbenchPage
> page=PlatformUI.getWorkbench().getActiveWorkbenchWindow()
> .getActivePage();
> IJavaElement element= JavaUI.getEditorInputJavaElement(
> page.getActiveEditor().getEditorInput());
> IJavaSearchScope scope = SearchEngine.createJavaSearchScope(
> new IJavaElement[] { element } ,true);
> IEditorPart editor = page.getActiveEditor();
> IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
> IJavaProject project = JavaCore.create(file.getProject());
> SearchPattern searchPattern = SearchPattern.createPattern(
> "*",
> IJavaSearchConstants.FIELD,
> IJavaSearchConstants.DECLARATIONS,
> SearchPattern.R_PATTERN_MATCH);
> final List<Object> list = new ArrayList<Object>();
> SearchRequestor requestor = new SearchRequestor() {
> public void acceptSearchMatch(SearchMatch match) {
> Object element = match.getElement();
> list.add((Object)element);
> if (element instanceof IJavaElement) {
> logger.debug("element is IJavaElement");
> IJavaElement e = (IJavaElement)element;
> logger.debug(e.getAdapter(IJavaElement.class));
> logger.debug(e.getClass());
> }
> }
> };
> SearchEngine searchEngine = new SearchEngine();
> try {
> searchEngine.search(searchPattern, new
> SearchParticipant[] {
> SearchEngine.getDefaultSearchParticipant()},
> scope, requestor,
> new NullProgressMonitor());
> } catch (CoreException e) {
> logger.debug(e.getMessage());
> }
> ------------------------------------------------------------ ---------------
>
> So, editing the following sample class :
>
> ------------------------------------------------------------ ---------------
>
> public class cc {
> private Object1 obj1= null;
> private Object2 obj2= null;
>
> /**
> * Main
> */
> public static void main(String[] args) {
> new cc();
> }
> /**
> * Constructor
> */
> public cc() {
> try {
> ....
> Object3 obj3 = new Object3();
> // Fills input datas
> obj3.get <---------------- completion
> }
> }
> }
> ------------------------------------------------------------ --------------
>
> .. when I ask completion, my code is executed but only obj1 and obj2
> are found... not obj3 in constructor...
>
> Thanks for your help
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04100 seconds