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.Iterator;
15 import java.util.List;
17 import net.sourceforge.phpdt.core.Flags;
18 import net.sourceforge.phpdt.core.ICompilationUnit;
19 import net.sourceforge.phpdt.core.IJavaElement;
20 import net.sourceforge.phpdt.core.IMethod;
21 import net.sourceforge.phpdt.core.IType;
22 import net.sourceforge.phpdt.core.JavaModelException;
23 import net.sourceforge.phpdt.core.Signature;
24 import net.sourceforge.phpdt.debug.core.PHPDebugModel;
25 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
26 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
28 import org.eclipse.core.resources.IResource;
29 import org.eclipse.core.resources.ResourcesPlugin;
30 import org.eclipse.core.runtime.CoreException;
31 import org.eclipse.debug.core.DebugPlugin;
32 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
33 import org.eclipse.jface.text.IDocument;
34 import org.eclipse.jface.text.ITextSelection;
35 import org.eclipse.jface.viewers.ISelection;
36 import org.eclipse.jface.viewers.IStructuredSelection;
37 import org.eclipse.ui.IEditorInput;
38 import org.eclipse.ui.IEditorPart;
39 import org.eclipse.ui.IFileEditorInput;
40 import org.eclipse.ui.IWorkbenchPart;
41 import org.eclipse.ui.texteditor.IEditorStatusLine;
42 import org.eclipse.ui.texteditor.ITextEditor;
45 * Toggles a line breakpoint in a Java editor.
49 public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
51 protected void report(String message, IWorkbenchPart part) {
52 IEditorStatusLine statusLine = (IEditorStatusLine) part
53 .getAdapter(IEditorStatusLine.class);
54 if (statusLine != null) {
55 if (message != null) {
56 statusLine.setMessage(true, message, null);
58 statusLine.setMessage(true, null, null);
62 && PHPDebugUiPlugin.getActiveWorkbenchShell() != null) {
63 PHPDebugUiPlugin.getActiveWorkbenchShell().getDisplay().beep();
67 // protected IType getType(ITextSelection selection) {
69 // ActionDelegateHelper.getDefault().getCurrentMember(selection);
71 // if (member instanceof IType) {
72 // type = (IType)member;
73 // } else if (member != null) {
74 // type= member.getDeclaringType();
76 // // bug 52385: we don't want local and anonymous types from compilation
78 // // we are getting 'not-always-correct' names for them.
80 // while (type != null && !type.isBinary() && type.isLocal()) {
81 // type= type.getDeclaringType();
83 // } catch (JavaModelException e) {
84 // PHPDebugUiPlugin.log(e);
92 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(IWorkbenchPart,
95 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
96 throws CoreException {
97 if (selection instanceof ITextSelection) {
99 IEditorPart editorPart = (IEditorPart) part;
100 ITextSelection textSelection = (ITextSelection) selection;
101 // IType type = getType(textSelection);
102 IEditorInput editorInput = editorPart.getEditorInput();
103 IDocument document = ((ITextEditor) editorPart)
104 .getDocumentProvider().getDocument(editorInput);
105 int lineNumber = textSelection.getStartLine() + 1;
106 int offset = textSelection.getOffset();
108 // if (type == null) {
109 // IClassFile classFile=
110 // (IClassFile)editorInput.getAdapter(IClassFile.class);
111 // if (classFile != null) {
112 // type= classFile.getType();
113 // // bug 34856 - if this is an inner type, ensure the
115 // // being added to the outer type
116 // if (type.getDeclaringType() != null) {
117 // ISourceRange sourceRange= type.getSourceRange();
118 // int start= sourceRange.getOffset();
119 // int end= start + sourceRange.getLength();
120 // if (offset < start || offset > end) {
121 // // not in the inner type
122 // IStatusLineManager statusLine =
123 // editorPart.getEditorSite().getActionBars().getStatusLineManager();
125 // .setErrorMessage(MessageFormat.format(ActionMessages.getString("ManageBreakpointRulerAction.Breakpoints_can_only_be_created_within_the_type_associated_with_the_editor__{0}._1"),
126 // new String[] { type.getTypeQualifiedName()})); //$NON-NLS-1$
127 // Display.getCurrent().beep();
134 // String typeName= null;
136 PHPLineBreakpoint breakpoint = null;
137 // if (type == null) {
138 if (editorInput instanceof IFileEditorInput) {
139 resource = ((IFileEditorInput) editorInput).getFile();
141 resource = ResourcesPlugin.getWorkspace().getRoot();
144 // typeName= type.getFullyQualifiedName();
146 // breakpoint=PHPDebugModel.lineBreakpointExists(lineNumber);
147 // if (breakpoint==null)
148 // PHPDebugModel.createLineBreakpoint(getFile(), lineNumber, 0,
151 // DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(
152 // breakpoint, true );
154 PHPLineBreakpoint existingBreakpoint = PHPDebugModel
155 .lineBreakpointExists(resource, lineNumber); // typeName,
157 if (existingBreakpoint != null) {
158 DebugPlugin.getDefault().getBreakpointManager()
159 .removeBreakpoint(existingBreakpoint, true);
162 breakpoint = PHPDebugModel.createLineBreakpoint(resource,
163 lineNumber, 0, true, null);
166 // new BreakpointLocationVerifierJob(document, breakpoint,
167 // lineNumber, typeName, type, resource, (IEditorStatusLine)
168 // editorPart.getAdapter(IEditorStatusLine.class)).schedule();
169 } catch (CoreException ce) {
170 // TODO: no message in ActionMessages
171 // ExceptionHandler.handle(ce,
172 // ActionMessages.getString("ManageBreakpointActionDelegate.error.title1"),
173 // ActionMessages.getString("ManageBreakpointActionDelegate.error.message1"));
174 // //$NON-NLS-1$ //$NON-NLS-2$
183 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(IWorkbenchPart,
186 public boolean canToggleLineBreakpoints(IWorkbenchPart part,
187 ISelection selection) {
188 return selection instanceof ITextSelection;
194 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart,
195 * org.eclipse.jface.viewers.ISelection)
197 public void toggleMethodBreakpoints(IWorkbenchPart part,
198 ISelection selection) throws CoreException {
199 // report(null, part);
200 // selection = translateToMembers(part, selection);
201 // if (selection instanceof ITextSelection) {
202 // ITextSelection textSelection = (ITextSelection) selection;
203 // if (selection != null) {
204 // CompilationUnit compilationUnit=
205 // parseCompilationUnit((ITextEditor)part);
206 // if (compilationUnit != null) {
207 // BreakpointMethodLocator locator= new
208 // BreakpointMethodLocator(textSelection.getOffset());
209 // compilationUnit.accept(locator);
210 // String methodName= locator.getMethodName();
211 // if (methodName == null) {
212 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.CantAdd"),
213 // part); //$NON-NLS-1$
216 // String typeName= locator.getTypeName();
217 // String methodSignature= locator.getMethodSignature();
218 // if (methodSignature == null) {
219 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.methodNonAvailable"),
220 // part); //$NON-NLS-1$
223 // // check if this method breakpoint already exist. If yes, remove it.
224 // IBreakpointManager breakpointManager=
225 // DebugPlugin.getDefault().getBreakpointManager();
226 // IBreakpoint[] breakpoints=
227 // breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
228 // for (int i= 0; i < breakpoints.length; i++) {
229 // IBreakpoint breakpoint= breakpoints[i];
230 // if (breakpoint instanceof IJavaMethodBreakpoint) {
231 // IJavaMethodBreakpoint methodBreakpoint=
232 // (IJavaMethodBreakpoint)breakpoint;
233 // if (typeName.equals(methodBreakpoint.getTypeName())
234 // && methodName.equals(methodBreakpoint.getMethodName())
235 // && methodSignature.equals(methodBreakpoint.getMethodSignature())) {
236 // breakpointManager.removeBreakpoint(methodBreakpoint, true);
241 // // add the breakpoint
242 // JDIDebugModel.createMethodBreakpoint(getResource((IEditorPart)part),
243 // typeName, methodName, methodSignature, true, false, false, -1, -1,
244 // -1, 0, true, new HashMap(10));
247 // } else if (selection instanceof IStructuredSelection) {
248 // IMethod[] members= getMethods((IStructuredSelection)selection);
249 // if (members.length == 0) {
250 // report(ActionMessages.getString("ToggleBreakpointAdapter.9"), part);
254 // // add or remove the breakpoint
255 // IBreakpointManager breakpointManager=
256 // DebugPlugin.getDefault().getBreakpointManager();
257 // for (int i= 0, length= members.length; i < length; i++) {
258 // IMethod method= members[i];
259 // IJavaBreakpoint breakpoint= getBreakpoint(method);
260 // if (breakpoint == null) {
264 // ISourceRange range = method.getNameRange();
265 // if (range != null) {
266 // start = range.getOffset();
267 // end = start + range.getLength();
269 // Map attributes = new HashMap(10);
270 // BreakpointUtils.addJavaBreakpointAttributes(attributes, method);
271 // String methodName = method.getElementName();
272 // if (method.isConstructor()) {
273 // methodName = "<init>"; //$NON-NLS-1$
275 // IType type= method.getDeclaringType();
276 // String methodSignature= method.getSignature();
277 // if (!type.isBinary()) {
278 // //resolve the type names
279 // methodSignature= resolveMethodSignature(type, methodSignature);
280 // if (methodSignature == null) {
281 // IStatus status = new Status(IStatus.ERROR,
282 // JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Source method
283 // signature could not be resolved", null); //$NON-NLS-1$
284 // throw new CoreException(status);
287 // JDIDebugModel.createMethodBreakpoint(BreakpointUtils.getBreakpointResource(method),
288 // type.getFullyQualifiedName(), methodName, methodSignature, true,
289 // false, false, -1, start, end, 0, true, attributes);
291 // // remove breakpoint
292 // breakpointManager.removeBreakpoint(breakpoint, true);
301 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart,
302 * org.eclipse.jface.viewers.ISelection)
304 public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
305 ISelection selection) {
306 // if (selection instanceof IStructuredSelection) {
307 // IStructuredSelection ss = (IStructuredSelection) selection;
308 // return getMethods(ss).length > 0;
310 // return selection instanceof ITextSelection;
315 protected IMethod[] getMethods(IStructuredSelection selection) {
316 if (selection.isEmpty()) {
317 return new IMethod[0];
319 List methods = new ArrayList(selection.size());
320 Iterator iterator = selection.iterator();
321 while (iterator.hasNext()) {
322 Object thing = iterator.next();
324 if (thing instanceof IMethod
325 && !Flags.isAbstract(((IMethod) thing).getFlags())) {
328 } catch (JavaModelException e) {
331 return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
335 // protected IField[] getFields(IStructuredSelection selection) {
336 // if (selection.isEmpty()) {
337 // return new IField[0];
339 // List fields = new ArrayList(selection.size());
340 // Iterator iterator = selection.iterator();
341 // while (iterator.hasNext()) {
342 // Object thing = iterator.next();
343 // if (thing instanceof IField) {
344 // fields.add(thing);
345 // } else if (thing instanceof IJavaFieldVariable) {
346 // IField field= getField((IJavaFieldVariable) thing);
347 // if (field != null) {
348 // fields.add(field);
352 // return (IField[]) fields.toArray(new IField[fields.size()]);
359 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart,
360 * org.eclipse.jface.viewers.ISelection)
362 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
363 throws CoreException {
364 // report(null, part);
365 // selection = translateToMembers(part, selection);
366 // if (selection instanceof ITextSelection) {
367 // ITextSelection textSelection= (ITextSelection) selection;
368 // CompilationUnit compilationUnit=
369 // parseCompilationUnit((ITextEditor)part);
370 // if (compilationUnit != null) {
371 // BreakpointFieldLocator locator= new
372 // BreakpointFieldLocator(textSelection.getOffset());
373 // compilationUnit.accept(locator);
374 // String fieldName= locator.getFieldName();
375 // if (fieldName == null) {
376 // report(ActionMessages.getString("ManageWatchpointActionDelegate.CantAdd"),
377 // part); //$NON-NLS-1$
380 // String typeName= locator.getTypeName();
381 // // check if the watchpoint already exists. If yes, remove it
382 // IBreakpointManager breakpointManager=
383 // DebugPlugin.getDefault().getBreakpointManager();
384 // IBreakpoint[] breakpoints=
385 // breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
386 // for (int i= 0; i < breakpoints.length; i++) {
387 // IBreakpoint breakpoint= breakpoints[i];
388 // if (breakpoint instanceof IJavaWatchpoint) {
389 // IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
390 // if (typeName.equals(watchpoint.getTypeName()) &&
391 // fieldName.equals(watchpoint.getFieldName())) {
392 // breakpointManager.removeBreakpoint(watchpoint, true);
397 // // add the watchpoint
398 // JDIDebugModel.createWatchpoint(getResource((IEditorPart)part),
399 // typeName, fieldName, -1, -1, -1, 0, true, new HashMap(10));
401 // } else if (selection instanceof IStructuredSelection) {
402 // IField[] members = getFields((IStructuredSelection)selection);
403 // if (members.length == 0) {
404 // report(ActionMessages.getString("ToggleBreakpointAdapter.10"), part);
408 // // add or remove watchpoint
409 // IBreakpointManager breakpointManager=
410 // DebugPlugin.getDefault().getBreakpointManager();
411 // for (int i= 0, length= members.length; i < length; i++) {
412 // IField element= members[i];
413 // IJavaBreakpoint breakpoint= getBreakpoint(element);
414 // if (breakpoint == null) {
415 // IType type = element.getDeclaringType();
418 // ISourceRange range = element.getNameRange();
419 // if (range != null) {
420 // start = range.getOffset();
421 // end = start + range.getLength();
423 // Map attributes = new HashMap(10);
424 // BreakpointUtils.addJavaBreakpointAttributes(attributes, element);
425 // JDIDebugModel.createWatchpoint(BreakpointUtils.getBreakpointResource(type),
426 // type.getFullyQualifiedName(), element.getElementName(), -1, start,
427 // end, 0, true, attributes);
429 // // remove breakpoint
430 // breakpointManager.removeBreakpoint(breakpoint, true);
436 public static String resolveMethodSignature(IType type,
437 String methodSignature) throws JavaModelException {
438 String[] parameterTypes = Signature.getParameterTypes(methodSignature);
439 int length = parameterTypes.length;
440 String[] resolvedParameterTypes = new String[length];
442 for (int i = 0; i < length; i++) {
443 resolvedParameterTypes[i] = resolveType(type, parameterTypes[i]);
444 if (resolvedParameterTypes[i] == null) {
449 String resolvedReturnType = resolveType(type, Signature
450 .getReturnType(methodSignature));
451 if (resolvedReturnType == null) {
455 return Signature.createMethodSignature(resolvedParameterTypes,
459 private static String resolveType(IType type, String typeSignature)
460 throws JavaModelException {
461 // int count= Signature.getArrayCount(typeSignature);
462 // String elementTypeSignature= Signature.getElementType(typeSignature);
463 // if (elementTypeSignature.length() == 1) {
464 // // no need to resolve primitive types
465 // return typeSignature;
467 // String elementTypeName= Signature.toString(elementTypeSignature);
468 // String[][] resolvedElementTypeNames=
469 // type.resolveType(elementTypeName);
470 // if (resolvedElementTypeNames == null ||
471 // resolvedElementTypeNames.length != 1) {
472 // // the type name cannot be resolved
475 // String resolvedElementTypeName=
476 // Signature.toQualifiedName(resolvedElementTypeNames[0]);
477 // String resolvedElementTypeSignature=
478 // Signature.createTypeSignature(resolvedElementTypeName,
479 // true).replace('.', '/');
480 // return Signature.createArraySignature(resolvedElementTypeSignature,
485 protected static IResource getResource(IEditorPart editor) {
487 IEditorInput editorInput = editor.getEditorInput();
488 if (editorInput instanceof IFileEditorInput) {
489 resource = ((IFileEditorInput) editorInput).getFile();
491 resource = ResourcesPlugin.getWorkspace().getRoot();
497 * Returns a handle to the specified method or <code>null</code> if none.
500 * the editor containing the method
504 * @return handle or <code>null</code>
506 protected IMethod getMethodHandle(IEditorPart editorPart, String typeName,
507 String methodName, String signature) throws CoreException {
508 IJavaElement element = (IJavaElement) editorPart.getEditorInput()
509 .getAdapter(IJavaElement.class);
511 if (element instanceof ICompilationUnit) {
512 IType[] types = ((ICompilationUnit) element).getAllTypes();
513 for (int i = 0; i < types.length; i++) {
514 if (types[i].getFullyQualifiedName().equals(typeName)) {
520 // else if (element instanceof IClassFile) {
521 // type = ((IClassFile)element).getType();
524 String[] sigs = Signature.getParameterTypes(signature);
525 return type.getMethod(methodName, sigs);
530 // protected IJavaBreakpoint getBreakpoint(IMember element) {
531 // IBreakpointManager breakpointManager=
532 // DebugPlugin.getDefault().getBreakpointManager();
533 // IBreakpoint[] breakpoints=
534 // breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
535 // if (element instanceof IMethod) {
536 // IMethod method= (IMethod)element;
537 // for (int i= 0; i < breakpoints.length; i++) {
538 // IBreakpoint breakpoint= breakpoints[i];
539 // if (breakpoint instanceof IJavaMethodBreakpoint) {
540 // IJavaMethodBreakpoint methodBreakpoint=
541 // (IJavaMethodBreakpoint)breakpoint;
542 // IMember container = null;
544 // container= BreakpointUtils.getMember(methodBreakpoint);
545 // } catch (CoreException e) {
546 // JDIDebugUIPlugin.log(e);
549 // if (container == null) {
552 // (method.getDeclaringType().getFullyQualifiedName().equals(methodBreakpoint.getTypeName())
553 // && method.getElementName().equals(methodBreakpoint.getMethodName())
554 // && method.getSignature().equals(methodBreakpoint.getMethodSignature())) {
555 // return methodBreakpoint;
557 // } catch (CoreException e) {
558 // JDIDebugUIPlugin.log(e);
561 // if (container instanceof IMethod) {
563 // (method.getDeclaringType().getFullyQualifiedName().equals(container.getDeclaringType().getFullyQualifiedName()))
565 // if (method.isSimilar((IMethod)container)) {
566 // return methodBreakpoint;
573 // } else if (element instanceof IField) {
574 // for (int i= 0; i < breakpoints.length; i++) {
575 // IBreakpoint breakpoint= breakpoints[i];
576 // if (breakpoint instanceof IJavaWatchpoint) {
578 // if (equalFields(element, (IJavaWatchpoint)breakpoint))
579 // return (IJavaBreakpoint)breakpoint;
580 // } catch (CoreException e) {
581 // JDIDebugUIPlugin.log(e);
590 * Compare two fields. The default <code>equals()</code> method for
591 * <code>IField</code> doesn't give the comparison desired.
593 // private boolean equalFields(IMember breakpointField, IJavaWatchpoint
594 // watchpoint) throws CoreException {
596 // (breakpointField.getElementName().equals(watchpoint.getFieldName()) &&
597 // breakpointField.getDeclaringType().getFullyQualifiedName().equals(watchpoint.getTypeName()));
600 // protected CompilationUnit parseCompilationUnit(ITextEditor editor) {
601 // IEditorInput editorInput = editor.getEditorInput();
602 // IDocument document=
603 // editor.getDocumentProvider().getDocument(editorInput);
604 // ASTParser parser = ASTParser.newParser(AST.JLS2);
605 // parser.setSource(document.get().toCharArray());
606 // return (CompilationUnit) parser.createAST(null);
611 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart,
612 * org.eclipse.jface.viewers.ISelection)
614 public boolean canToggleWatchpoints(IWorkbenchPart part,
615 ISelection selection) {
616 // if (selection instanceof IStructuredSelection) {
617 // IStructuredSelection ss = (IStructuredSelection) selection;
618 // return getFields(ss).length > 0;
620 // return selection instanceof ITextSelection;
626 * Returns a selection of the member in the given text selection, or the
627 * original selection if none.
631 * @return a structured selection of the member in the given text selection,
632 * or the original selection if none
633 * @exception CoreException
634 * if an exceptoin occurrs
636 // protected ISelection translateToMembers(IWorkbenchPart part, ISelection
637 // selection) throws CoreException {
638 // if (selection instanceof ITextSelection && part instanceof IEditorPart) {
639 // ITextSelection textSelection = (ITextSelection)selection;
640 // IEditorPart editorPart = (IEditorPart) part;
641 // IEditorInput editorInput = editorPart.getEditorInput();
643 // IClassFile classFile=
644 // (IClassFile)editorInput.getAdapter(IClassFile.class);
645 // if (classFile != null) {
646 // IJavaElement e= classFile.getElementAt(textSelection.getOffset());
647 // if (e instanceof IMember) {
651 // IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
652 // ICompilationUnit unit= manager.getWorkingCopy(editorInput);
653 // if (unit != null) {
654 // synchronized (unit) {
655 // unit.reconcile(ICompilationUnit.NO_AST /*don't create ast*/, false/*don't
656 // force problem detection*/, null/*use primary owner*/, null/*no progress
659 // IJavaElement e = unit.getElementAt(textSelection.getOffset());
660 // if (e instanceof IMember) {
666 // return new StructuredSelection(m);
672 * Returns a list of matching types (IType - Java model) that correspond to
673 * the declaring type (ReferenceType - JDI model) of the given variable.
675 // protected static List searchForDeclaringType(IJavaFieldVariable variable)
677 // List types= new ArrayList();
678 // ILaunch launch = variable.getDebugTarget().getLaunch();
679 // if (launch == null) {
683 // ILaunchConfiguration configuration= launch.getLaunchConfiguration();
684 // IJavaProject[] javaProjects = null;
685 // IWorkspace workspace= ResourcesPlugin.getWorkspace();
686 // if (configuration != null) {
687 // // Launch configuration support
689 // String projectName=
690 // configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
691 // ""); //$NON-NLS-1$
692 // if (projectName.length() != 0) {
693 // javaProjects= new IJavaProject[]
694 // {JavaCore.create(workspace.getRoot().getProject(projectName))};
696 // IProject[] projects=
697 // ResourcesPlugin.getWorkspace().getRoot().getProjects();
699 // List projectList= new ArrayList();
700 // for (int i= 0, numProjects= projects.length; i < numProjects; i++) {
701 // project= projects[i];
702 // if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
703 // projectList.add(JavaCore.create(project));
706 // javaProjects= new IJavaProject[projectList.size()];
707 // projectList.toArray(javaProjects);
709 // } catch (CoreException e) {
710 // JDIDebugUIPlugin.log(e);
713 // if (javaProjects == null) {
717 // SearchEngine engine= new SearchEngine();
718 // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(javaProjects,
720 // String declaringType= null;
722 // declaringType= variable.getDeclaringType().getName();
723 // } catch (DebugException x) {
724 // JDIDebugUIPlugin.log(x);
727 // ArrayList typeRefsFound= new ArrayList(3);
728 // ITypeNameRequestor requestor= new TypeInfoRequestor(typeRefsFound);
730 // engine.searchAllTypeNames(
731 // getPackage(declaringType),
732 // getTypeName(declaringType),
733 // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
734 // IJavaSearchConstants.CLASS,
737 // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
739 // } catch (JavaModelException x) {
740 // JDIDebugUIPlugin.log(x);
743 // Iterator iter= typeRefsFound.iterator();
744 // TypeInfo typeInfo= null;
745 // while (iter.hasNext()) {
746 // typeInfo= (TypeInfo)iter.next();
748 // types.add(typeInfo.resolveType(scope));
749 // } catch (JavaModelException jme) {
750 // JDIDebugUIPlugin.log(jme);
756 * Returns the package name of the given fully qualified type name. The
757 * package name is assumed to be the dot-separated prefix of the type name.
759 // protected static char[] getPackage(String fullyQualifiedName) {
760 // int index= fullyQualifiedName.lastIndexOf('.');
761 // if (index == -1) {
762 // return new char[0];
764 // return fullyQualifiedName.substring(0, index).toCharArray();
768 // * Returns a simple type name from the given fully qualified type name.
769 // * The type name is assumed to be the last contiguous segment of the
770 // * fullyQualifiedName not containing a '.' or '$'
772 // protected static char[] getTypeName(String fullyQualifiedName) {
773 // int index= fullyQualifiedName.lastIndexOf('.');
774 // String typeName= fullyQualifiedName.substring(index + 1);
775 // int lastInnerClass= typeName.lastIndexOf('$');
776 // if (lastInnerClass != -1) {
777 // typeName= typeName.substring(lastInnerClass + 1);
779 // return typeName.toCharArray();
783 // * Return the associated IField (Java model) for the given
784 // * IJavaFieldVariable (JDI model)
786 // private IField getField(IJavaFieldVariable variable) {
787 // String varName= null;
789 // varName= variable.getName();
790 // } catch (DebugException x) {
791 // JDIDebugUIPlugin.log(x);
795 // List types= searchForDeclaringType(variable);
796 // Iterator iter= types.iterator();
797 // while (iter.hasNext()) {
798 // IType type= (IType)iter.next();
799 // field= type.getField(varName);
800 // if (field.exists()) {