1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.debug.ui.actions;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.List;
19 import net.sourceforge.phpdt.core.Flags;
20 import net.sourceforge.phpdt.core.ICompilationUnit;
21 import net.sourceforge.phpdt.core.IField;
22 import net.sourceforge.phpdt.core.IJavaElement;
23 import net.sourceforge.phpdt.core.IJavaProject;
24 import net.sourceforge.phpdt.core.IMember;
25 import net.sourceforge.phpdt.core.IMethod;
26 import net.sourceforge.phpdt.core.ISourceRange;
27 import net.sourceforge.phpdt.core.IType;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.JavaModelException;
30 import net.sourceforge.phpdt.core.Signature;
31 import net.sourceforge.phpdt.core.dom.CompilationUnit;
32 import net.sourceforge.phpdt.core.search.IJavaSearchConstants;
33 import net.sourceforge.phpdt.core.search.ITypeNameRequestor;
34 import net.sourceforge.phpdt.debug.core.PHPDebugModel;
35 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
36 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
37 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
38 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
39 import net.sourceforge.phpdt.ui.JavaUI;
41 import org.eclipse.core.resources.IProject;
42 import org.eclipse.core.resources.IResource;
43 import org.eclipse.core.resources.IWorkspace;
44 import org.eclipse.core.resources.ResourcesPlugin;
45 import org.eclipse.core.runtime.CoreException;
46 import org.eclipse.core.runtime.IStatus;
47 import org.eclipse.core.runtime.Status;
48 import org.eclipse.debug.core.DebugException;
49 import org.eclipse.debug.core.DebugPlugin;
50 import org.eclipse.debug.core.IBreakpointManager;
51 import org.eclipse.debug.core.ILaunch;
52 import org.eclipse.debug.core.ILaunchConfiguration;
53 import org.eclipse.debug.core.model.IBreakpoint;
54 import org.eclipse.debug.internal.ui.actions.ActionMessages;
55 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
56 import org.eclipse.jface.text.BadLocationException;
57 import org.eclipse.jface.text.IDocument;
58 import org.eclipse.jface.text.IRegion;
59 import org.eclipse.jface.text.ITextSelection;
60 import org.eclipse.jface.viewers.ISelection;
61 import org.eclipse.jface.viewers.IStructuredSelection;
62 import org.eclipse.jface.viewers.StructuredSelection;
63 import org.eclipse.ui.IEditorInput;
64 import org.eclipse.ui.IEditorPart;
65 import org.eclipse.ui.IFileEditorInput;
66 import org.eclipse.ui.IWorkbenchPart;
67 import org.eclipse.ui.texteditor.IEditorStatusLine;
68 import org.eclipse.ui.texteditor.ITextEditor;
71 * Toggles a line breakpoint in a Java editor.
75 public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
77 protected void report(String message, IWorkbenchPart part) {
78 IEditorStatusLine statusLine= (IEditorStatusLine) part.getAdapter(IEditorStatusLine.class);
79 if (statusLine != null) {
80 if (message != null) {
81 statusLine.setMessage(true, message, null);
83 statusLine.setMessage(true, null, null);
86 if (message != null && PHPDebugUiPlugin.getActiveWorkbenchShell() != null) {
87 PHPDebugUiPlugin.getActiveWorkbenchShell().getDisplay().beep();
91 // protected IType getType(ITextSelection selection) {
92 // IMember member= ActionDelegateHelper.getDefault().getCurrentMember(selection);
94 // if (member instanceof IType) {
95 // type = (IType)member;
96 // } else if (member != null) {
97 // type= member.getDeclaringType();
99 // // bug 52385: we don't want local and anonymous types from compilation unit,
100 // // we are getting 'not-always-correct' names for them.
102 // while (type != null && !type.isBinary() && type.isLocal()) {
103 // type= type.getDeclaringType();
105 // } catch (JavaModelException e) {
106 // PHPDebugUiPlugin.log(e);
112 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(IWorkbenchPart, ISelection)
114 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
115 if (selection instanceof ITextSelection) {
117 IEditorPart editorPart = (IEditorPart)part;
118 ITextSelection textSelection = (ITextSelection)selection;
119 // IType type = getType(textSelection);
120 IEditorInput editorInput = editorPart.getEditorInput();
121 IDocument document= ((ITextEditor)editorPart).getDocumentProvider().getDocument(editorInput);
122 int lineNumber= textSelection.getStartLine() + 1;
123 int offset= textSelection.getOffset();
125 // if (type == null) {
126 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
127 // if (classFile != null) {
128 // type= classFile.getType();
129 // // bug 34856 - if this is an inner type, ensure the breakpoint is not
130 // // being added to the outer type
131 // if (type.getDeclaringType() != null) {
132 // ISourceRange sourceRange= type.getSourceRange();
133 // int start= sourceRange.getOffset();
134 // int end= start + sourceRange.getLength();
135 // if (offset < start || offset > end) {
136 // // not in the inner type
137 // IStatusLineManager statusLine = editorPart.getEditorSite().getActionBars().getStatusLineManager();
138 // statusLine .setErrorMessage(MessageFormat.format(ActionMessages.getString("ManageBreakpointRulerAction.Breakpoints_can_only_be_created_within_the_type_associated_with_the_editor__{0}._1"), new String[] { type.getTypeQualifiedName()})); //$NON-NLS-1$
139 // Display.getCurrent().beep();
146 // String typeName= null;
148 PHPLineBreakpoint breakpoint= null;
149 // if (type == null) {
150 if (editorInput instanceof IFileEditorInput) {
151 resource= ((IFileEditorInput)editorInput).getFile();
153 resource= ResourcesPlugin.getWorkspace().getRoot();
156 // typeName= type.getFullyQualifiedName();
157 // PHPLineBreakpoint breakpoint=PHPDebugModel.lineBreakpointExists(lineNumber);
158 // if (breakpoint==null)
159 // PHPDebugModel.createLineBreakpoint(getFile(), lineNumber, 0, true, null);
161 // DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
163 PHPLineBreakpoint existingBreakpoint= PHPDebugModel.lineBreakpointExists(lineNumber); //typeName, lineNumber);
164 if (existingBreakpoint != null) {
165 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(existingBreakpoint, true);
168 breakpoint = PHPDebugModel.createLineBreakpoint(resource, lineNumber, 0, true, null);
171 // new BreakpointLocationVerifierJob(document, breakpoint, lineNumber, typeName, type, resource, (IEditorStatusLine) editorPart.getAdapter(IEditorStatusLine.class)).schedule();
172 } catch (CoreException ce) {
173 ExceptionHandler.handle(ce, ActionMessages.getString("ManageBreakpointActionDelegate.error.title1"), ActionMessages.getString("ManageBreakpointActionDelegate.error.message1")); //$NON-NLS-1$ //$NON-NLS-2$
179 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(IWorkbenchPart, ISelection)
181 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
182 return selection instanceof ITextSelection;
186 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
188 public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
189 // report(null, part);
190 // selection = translateToMembers(part, selection);
191 // if (selection instanceof ITextSelection) {
192 // ITextSelection textSelection = (ITextSelection) selection;
193 // if (selection != null) {
194 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
195 // if (compilationUnit != null) {
196 // BreakpointMethodLocator locator= new BreakpointMethodLocator(textSelection.getOffset());
197 // compilationUnit.accept(locator);
198 // String methodName= locator.getMethodName();
199 // if (methodName == null) {
200 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
203 // String typeName= locator.getTypeName();
204 // String methodSignature= locator.getMethodSignature();
205 // if (methodSignature == null) {
206 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.methodNonAvailable"), part); //$NON-NLS-1$
209 // // check if this method breakpoint already exist. If yes, remove it.
210 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
211 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
212 // for (int i= 0; i < breakpoints.length; i++) {
213 // IBreakpoint breakpoint= breakpoints[i];
214 // if (breakpoint instanceof IJavaMethodBreakpoint) {
215 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
216 // if (typeName.equals(methodBreakpoint.getTypeName())
217 // && methodName.equals(methodBreakpoint.getMethodName())
218 // && methodSignature.equals(methodBreakpoint.getMethodSignature())) {
219 // breakpointManager.removeBreakpoint(methodBreakpoint, true);
224 // // add the breakpoint
225 // JDIDebugModel.createMethodBreakpoint(getResource((IEditorPart)part), typeName, methodName, methodSignature, true, false, false, -1, -1, -1, 0, true, new HashMap(10));
228 // } else if (selection instanceof IStructuredSelection) {
229 // IMethod[] members= getMethods((IStructuredSelection)selection);
230 // if (members.length == 0) {
231 // report(ActionMessages.getString("ToggleBreakpointAdapter.9"), part); //$NON-NLS-1$
234 // // add or remove the breakpoint
235 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
236 // for (int i= 0, length= members.length; i < length; i++) {
237 // IMethod method= members[i];
238 // IJavaBreakpoint breakpoint= getBreakpoint(method);
239 // if (breakpoint == null) {
243 // ISourceRange range = method.getNameRange();
244 // if (range != null) {
245 // start = range.getOffset();
246 // end = start + range.getLength();
248 // Map attributes = new HashMap(10);
249 // BreakpointUtils.addJavaBreakpointAttributes(attributes, method);
250 // String methodName = method.getElementName();
251 // if (method.isConstructor()) {
252 // methodName = "<init>"; //$NON-NLS-1$
254 // IType type= method.getDeclaringType();
255 // String methodSignature= method.getSignature();
256 // if (!type.isBinary()) {
257 // //resolve the type names
258 // methodSignature= resolveMethodSignature(type, methodSignature);
259 // if (methodSignature == null) {
260 // IStatus status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Source method signature could not be resolved", null); //$NON-NLS-1$
261 // throw new CoreException(status);
264 // JDIDebugModel.createMethodBreakpoint(BreakpointUtils.getBreakpointResource(method), type.getFullyQualifiedName(), methodName, methodSignature, true, false, false, -1, start, end, 0, true, attributes);
266 // // remove breakpoint
267 // breakpointManager.removeBreakpoint(breakpoint, true);
274 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
276 public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
277 if (selection instanceof IStructuredSelection) {
278 IStructuredSelection ss = (IStructuredSelection) selection;
279 return getMethods(ss).length > 0;
281 return selection instanceof ITextSelection;
285 protected IMethod[] getMethods(IStructuredSelection selection) {
286 if (selection.isEmpty()) {
287 return new IMethod[0];
289 List methods = new ArrayList(selection.size());
290 Iterator iterator = selection.iterator();
291 while (iterator.hasNext()) {
292 Object thing = iterator.next();
294 if (thing instanceof IMethod && !Flags.isAbstract(((IMethod)thing).getFlags())) {
297 } catch (JavaModelException e) {
300 return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
304 // protected IField[] getFields(IStructuredSelection selection) {
305 // if (selection.isEmpty()) {
306 // return new IField[0];
308 // List fields = new ArrayList(selection.size());
309 // Iterator iterator = selection.iterator();
310 // while (iterator.hasNext()) {
311 // Object thing = iterator.next();
312 // if (thing instanceof IField) {
313 // fields.add(thing);
314 // } else if (thing instanceof IJavaFieldVariable) {
315 // IField field= getField((IJavaFieldVariable) thing);
316 // if (field != null) {
317 // fields.add(field);
321 // return (IField[]) fields.toArray(new IField[fields.size()]);
326 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
328 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
329 // report(null, part);
330 // selection = translateToMembers(part, selection);
331 // if (selection instanceof ITextSelection) {
332 // ITextSelection textSelection= (ITextSelection) selection;
333 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
334 // if (compilationUnit != null) {
335 // BreakpointFieldLocator locator= new BreakpointFieldLocator(textSelection.getOffset());
336 // compilationUnit.accept(locator);
337 // String fieldName= locator.getFieldName();
338 // if (fieldName == null) {
339 // report(ActionMessages.getString("ManageWatchpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
342 // String typeName= locator.getTypeName();
343 // // check if the watchpoint already exists. If yes, remove it
344 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
345 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
346 // for (int i= 0; i < breakpoints.length; i++) {
347 // IBreakpoint breakpoint= breakpoints[i];
348 // if (breakpoint instanceof IJavaWatchpoint) {
349 // IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
350 // if (typeName.equals(watchpoint.getTypeName()) && fieldName.equals(watchpoint.getFieldName())) {
351 // breakpointManager.removeBreakpoint(watchpoint, true);
356 // // add the watchpoint
357 // JDIDebugModel.createWatchpoint(getResource((IEditorPart)part), typeName, fieldName, -1, -1, -1, 0, true, new HashMap(10));
359 // } else if (selection instanceof IStructuredSelection) {
360 // IField[] members = getFields((IStructuredSelection)selection);
361 // if (members.length == 0) {
362 // report(ActionMessages.getString("ToggleBreakpointAdapter.10"), part); //$NON-NLS-1$
365 // // add or remove watchpoint
366 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
367 // for (int i= 0, length= members.length; i < length; i++) {
368 // IField element= members[i];
369 // IJavaBreakpoint breakpoint= getBreakpoint(element);
370 // if (breakpoint == null) {
371 // IType type = element.getDeclaringType();
374 // ISourceRange range = element.getNameRange();
375 // if (range != null) {
376 // start = range.getOffset();
377 // end = start + range.getLength();
379 // Map attributes = new HashMap(10);
380 // BreakpointUtils.addJavaBreakpointAttributes(attributes, element);
381 // JDIDebugModel.createWatchpoint(BreakpointUtils.getBreakpointResource(type), type.getFullyQualifiedName(), element.getElementName(), -1, start, end, 0, true, attributes);
383 // // remove breakpoint
384 // breakpointManager.removeBreakpoint(breakpoint, true);
390 public static String resolveMethodSignature(IType type, String methodSignature) throws JavaModelException {
391 String[] parameterTypes= Signature.getParameterTypes(methodSignature);
392 int length= length= parameterTypes.length;
393 String[] resolvedParameterTypes= new String[length];
395 for (int i = 0; i < length; i++) {
396 resolvedParameterTypes[i]= resolveType(type, parameterTypes[i]);
397 if (resolvedParameterTypes[i] == null) {
402 String resolvedReturnType= resolveType(type, Signature.getReturnType(methodSignature));
403 if (resolvedReturnType == null) {
407 return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
410 private static String resolveType(IType type, String typeSignature) throws JavaModelException {
411 // int count= Signature.getArrayCount(typeSignature);
412 // String elementTypeSignature= Signature.getElementType(typeSignature);
413 // if (elementTypeSignature.length() == 1) {
414 // // no need to resolve primitive types
415 // return typeSignature;
417 // String elementTypeName= Signature.toString(elementTypeSignature);
418 // String[][] resolvedElementTypeNames= type.resolveType(elementTypeName);
419 // if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) {
420 // // the type name cannot be resolved
423 // String resolvedElementTypeName= Signature.toQualifiedName(resolvedElementTypeNames[0]);
424 // String resolvedElementTypeSignature= Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/');
425 // return Signature.createArraySignature(resolvedElementTypeSignature, count);
429 protected static IResource getResource(IEditorPart editor) {
431 IEditorInput editorInput = editor.getEditorInput();
432 if (editorInput instanceof IFileEditorInput) {
433 resource= ((IFileEditorInput)editorInput).getFile();
435 resource= ResourcesPlugin.getWorkspace().getRoot();
441 * Returns a handle to the specified method or <code>null</code> if none.
443 * @param editorPart the editor containing the method
447 * @return handle or <code>null</code>
449 protected IMethod getMethodHandle(IEditorPart editorPart, String typeName, String methodName, String signature) throws CoreException {
450 IJavaElement element = (IJavaElement) editorPart.getEditorInput().getAdapter(IJavaElement.class);
452 if (element instanceof ICompilationUnit) {
453 IType[] types = ((ICompilationUnit)element).getAllTypes();
454 for (int i = 0; i < types.length; i++) {
455 if (types[i].getFullyQualifiedName().equals(typeName)) {
461 // else if (element instanceof IClassFile) {
462 // type = ((IClassFile)element).getType();
465 String[] sigs = Signature.getParameterTypes(signature);
466 return type.getMethod(methodName, sigs);
471 // protected IJavaBreakpoint getBreakpoint(IMember element) {
472 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
473 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
474 // if (element instanceof IMethod) {
475 // IMethod method= (IMethod)element;
476 // for (int i= 0; i < breakpoints.length; i++) {
477 // IBreakpoint breakpoint= breakpoints[i];
478 // if (breakpoint instanceof IJavaMethodBreakpoint) {
479 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
480 // IMember container = null;
482 // container= BreakpointUtils.getMember(methodBreakpoint);
483 // } catch (CoreException e) {
484 // JDIDebugUIPlugin.log(e);
487 // if (container == null) {
489 // if (method.getDeclaringType().getFullyQualifiedName().equals(methodBreakpoint.getTypeName())
490 // && method.getElementName().equals(methodBreakpoint.getMethodName())
491 // && method.getSignature().equals(methodBreakpoint.getMethodSignature())) {
492 // return methodBreakpoint;
494 // } catch (CoreException e) {
495 // JDIDebugUIPlugin.log(e);
498 // if (container instanceof IMethod) {
499 // if (method.getDeclaringType().getFullyQualifiedName().equals(container.getDeclaringType().getFullyQualifiedName())) {
500 // if (method.isSimilar((IMethod)container)) {
501 // return methodBreakpoint;
508 // } else if (element instanceof IField) {
509 // for (int i= 0; i < breakpoints.length; i++) {
510 // IBreakpoint breakpoint= breakpoints[i];
511 // if (breakpoint instanceof IJavaWatchpoint) {
513 // if (equalFields(element, (IJavaWatchpoint)breakpoint))
514 // return (IJavaBreakpoint)breakpoint;
515 // } catch (CoreException e) {
516 // JDIDebugUIPlugin.log(e);
525 * Compare two fields. The default <code>equals()</code>
526 * method for <code>IField</code> doesn't give the comparison desired.
528 // private boolean equalFields(IMember breakpointField, IJavaWatchpoint watchpoint) throws CoreException {
529 // return (breakpointField.getElementName().equals(watchpoint.getFieldName()) &&
530 // breakpointField.getDeclaringType().getFullyQualifiedName().equals(watchpoint.getTypeName()));
533 // protected CompilationUnit parseCompilationUnit(ITextEditor editor) {
534 // IEditorInput editorInput = editor.getEditorInput();
535 // IDocument document= editor.getDocumentProvider().getDocument(editorInput);
536 // ASTParser parser = ASTParser.newParser(AST.JLS2);
537 // parser.setSource(document.get().toCharArray());
538 // return (CompilationUnit) parser.createAST(null);
542 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
544 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
545 // if (selection instanceof IStructuredSelection) {
546 // IStructuredSelection ss = (IStructuredSelection) selection;
547 // return getFields(ss).length > 0;
549 // return selection instanceof ITextSelection;
555 * Returns a selection of the member in the given text selection,
556 * or the original selection if none.
560 * @return a structured selection of the member in the given text selection,
561 * or the original selection if none
562 * @exception CoreException if an exceptoin occurrs
564 // protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException {
565 // if (selection instanceof ITextSelection && part instanceof IEditorPart) {
566 // ITextSelection textSelection = (ITextSelection)selection;
567 // IEditorPart editorPart = (IEditorPart) part;
568 // IEditorInput editorInput = editorPart.getEditorInput();
570 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
571 // if (classFile != null) {
572 // IJavaElement e= classFile.getElementAt(textSelection.getOffset());
573 // if (e instanceof IMember) {
577 // IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
578 // ICompilationUnit unit= manager.getWorkingCopy(editorInput);
579 // if (unit != null) {
580 // synchronized (unit) {
581 // unit.reconcile(ICompilationUnit.NO_AST /*don't create ast*/, false/*don't force problem detection*/, null/*use primary owner*/, null/*no progress monitor*/);
583 // IJavaElement e = unit.getElementAt(textSelection.getOffset());
584 // if (e instanceof IMember) {
590 // return new StructuredSelection(m);
597 * Returns a list of matching types (IType - Java model) that correspond to the
598 * declaring type (ReferenceType - JDI model) of the given variable.
600 // protected static List searchForDeclaringType(IJavaFieldVariable variable) {
601 // List types= new ArrayList();
602 // ILaunch launch = variable.getDebugTarget().getLaunch();
603 // if (launch == null) {
607 // ILaunchConfiguration configuration= launch.getLaunchConfiguration();
608 // IJavaProject[] javaProjects = null;
609 // IWorkspace workspace= ResourcesPlugin.getWorkspace();
610 // if (configuration != null) {
611 // // Launch configuration support
613 // String projectName= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
614 // if (projectName.length() != 0) {
615 // javaProjects= new IJavaProject[] {JavaCore.create(workspace.getRoot().getProject(projectName))};
617 // IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
619 // List projectList= new ArrayList();
620 // for (int i= 0, numProjects= projects.length; i < numProjects; i++) {
621 // project= projects[i];
622 // if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
623 // projectList.add(JavaCore.create(project));
626 // javaProjects= new IJavaProject[projectList.size()];
627 // projectList.toArray(javaProjects);
629 // } catch (CoreException e) {
630 // JDIDebugUIPlugin.log(e);
633 // if (javaProjects == null) {
637 // SearchEngine engine= new SearchEngine();
638 // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(javaProjects, true);
639 // String declaringType= null;
641 // declaringType= variable.getDeclaringType().getName();
642 // } catch (DebugException x) {
643 // JDIDebugUIPlugin.log(x);
646 // ArrayList typeRefsFound= new ArrayList(3);
647 // ITypeNameRequestor requestor= new TypeInfoRequestor(typeRefsFound);
649 // engine.searchAllTypeNames(
650 // getPackage(declaringType),
651 // getTypeName(declaringType),
652 // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
653 // IJavaSearchConstants.CLASS,
656 // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
658 // } catch (JavaModelException x) {
659 // JDIDebugUIPlugin.log(x);
662 // Iterator iter= typeRefsFound.iterator();
663 // TypeInfo typeInfo= null;
664 // while (iter.hasNext()) {
665 // typeInfo= (TypeInfo)iter.next();
667 // types.add(typeInfo.resolveType(scope));
668 // } catch (JavaModelException jme) {
669 // JDIDebugUIPlugin.log(jme);
676 * Returns the package name of the given fully qualified type name.
677 * The package name is assumed to be the dot-separated prefix of the
680 // protected static char[] getPackage(String fullyQualifiedName) {
681 // int index= fullyQualifiedName.lastIndexOf('.');
682 // if (index == -1) {
683 // return new char[0];
685 // return fullyQualifiedName.substring(0, index).toCharArray();
689 // * Returns a simple type name from the given fully qualified type name.
690 // * The type name is assumed to be the last contiguous segment of the
691 // * fullyQualifiedName not containing a '.' or '$'
693 // protected static char[] getTypeName(String fullyQualifiedName) {
694 // int index= fullyQualifiedName.lastIndexOf('.');
695 // String typeName= fullyQualifiedName.substring(index + 1);
696 // int lastInnerClass= typeName.lastIndexOf('$');
697 // if (lastInnerClass != -1) {
698 // typeName= typeName.substring(lastInnerClass + 1);
700 // return typeName.toCharArray();
704 // * Return the associated IField (Java model) for the given
705 // * IJavaFieldVariable (JDI model)
707 // private IField getField(IJavaFieldVariable variable) {
708 // String varName= null;
710 // varName= variable.getName();
711 // } catch (DebugException x) {
712 // JDIDebugUIPlugin.log(x);
716 // List types= searchForDeclaringType(variable);
717 // Iterator iter= types.iterator();
718 // while (iter.hasNext()) {
719 // IType type= (IType)iter.next();
720 // field= type.getField(varName);
721 // if (field.exists()) {