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;
27 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
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.internal.ui.actions.ActionMessages;
33 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
34 import org.eclipse.jface.text.IDocument;
35 import org.eclipse.jface.text.ITextSelection;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.jface.viewers.IStructuredSelection;
38 import org.eclipse.ui.IEditorInput;
39 import org.eclipse.ui.IEditorPart;
40 import org.eclipse.ui.IFileEditorInput;
41 import org.eclipse.ui.IWorkbenchPart;
42 import org.eclipse.ui.texteditor.IEditorStatusLine;
43 import org.eclipse.ui.texteditor.ITextEditor;
46 * Toggles a line breakpoint in a Java editor.
50 public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
52 protected void report(String message, IWorkbenchPart part) {
53 IEditorStatusLine statusLine= (IEditorStatusLine) part.getAdapter(IEditorStatusLine.class);
54 if (statusLine != null) {
55 if (message != null) {
56 statusLine.setMessage(true, message, null);
58 statusLine.setMessage(true, null, null);
61 if (message != null && PHPDebugUiPlugin.getActiveWorkbenchShell() != null) {
62 PHPDebugUiPlugin.getActiveWorkbenchShell().getDisplay().beep();
66 // protected IType getType(ITextSelection selection) {
67 // IMember member= ActionDelegateHelper.getDefault().getCurrentMember(selection);
69 // if (member instanceof IType) {
70 // type = (IType)member;
71 // } else if (member != null) {
72 // type= member.getDeclaringType();
74 // // bug 52385: we don't want local and anonymous types from compilation unit,
75 // // we are getting 'not-always-correct' names for them.
77 // while (type != null && !type.isBinary() && type.isLocal()) {
78 // type= type.getDeclaringType();
80 // } catch (JavaModelException e) {
81 // PHPDebugUiPlugin.log(e);
87 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(IWorkbenchPart, ISelection)
89 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
90 if (selection instanceof ITextSelection) {
92 IEditorPart editorPart = (IEditorPart)part;
93 ITextSelection textSelection = (ITextSelection)selection;
94 // IType type = getType(textSelection);
95 IEditorInput editorInput = editorPart.getEditorInput();
96 IDocument document= ((ITextEditor)editorPart).getDocumentProvider().getDocument(editorInput);
97 int lineNumber= textSelection.getStartLine() + 1;
98 int offset= textSelection.getOffset();
100 // if (type == null) {
101 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
102 // if (classFile != null) {
103 // type= classFile.getType();
104 // // bug 34856 - if this is an inner type, ensure the breakpoint is not
105 // // being added to the outer type
106 // if (type.getDeclaringType() != null) {
107 // ISourceRange sourceRange= type.getSourceRange();
108 // int start= sourceRange.getOffset();
109 // int end= start + sourceRange.getLength();
110 // if (offset < start || offset > end) {
111 // // not in the inner type
112 // IStatusLineManager statusLine = editorPart.getEditorSite().getActionBars().getStatusLineManager();
113 // 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$
114 // Display.getCurrent().beep();
121 // String typeName= null;
123 PHPLineBreakpoint breakpoint= null;
124 // if (type == null) {
125 if (editorInput instanceof IFileEditorInput) {
126 resource= ((IFileEditorInput)editorInput).getFile();
128 resource= ResourcesPlugin.getWorkspace().getRoot();
131 // typeName= type.getFullyQualifiedName();
132 // PHPLineBreakpoint breakpoint=PHPDebugModel.lineBreakpointExists(lineNumber);
133 // if (breakpoint==null)
134 // PHPDebugModel.createLineBreakpoint(getFile(), lineNumber, 0, true, null);
136 // DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
138 PHPLineBreakpoint existingBreakpoint= PHPDebugModel.lineBreakpointExists(lineNumber); //typeName, lineNumber);
139 if (existingBreakpoint != null) {
140 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(existingBreakpoint, true);
143 breakpoint = PHPDebugModel.createLineBreakpoint(resource, lineNumber, 0, true, null);
146 // new BreakpointLocationVerifierJob(document, breakpoint, lineNumber, typeName, type, resource, (IEditorStatusLine) editorPart.getAdapter(IEditorStatusLine.class)).schedule();
147 } catch (CoreException ce) {
148 ExceptionHandler.handle(ce, ActionMessages.getString("ManageBreakpointActionDelegate.error.title1"), ActionMessages.getString("ManageBreakpointActionDelegate.error.message1")); //$NON-NLS-1$ //$NON-NLS-2$
154 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(IWorkbenchPart, ISelection)
156 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
157 return selection instanceof ITextSelection;
161 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
163 public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
164 // report(null, part);
165 // selection = translateToMembers(part, selection);
166 // if (selection instanceof ITextSelection) {
167 // ITextSelection textSelection = (ITextSelection) selection;
168 // if (selection != null) {
169 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
170 // if (compilationUnit != null) {
171 // BreakpointMethodLocator locator= new BreakpointMethodLocator(textSelection.getOffset());
172 // compilationUnit.accept(locator);
173 // String methodName= locator.getMethodName();
174 // if (methodName == null) {
175 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
178 // String typeName= locator.getTypeName();
179 // String methodSignature= locator.getMethodSignature();
180 // if (methodSignature == null) {
181 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.methodNonAvailable"), part); //$NON-NLS-1$
184 // // check if this method breakpoint already exist. If yes, remove it.
185 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
186 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
187 // for (int i= 0; i < breakpoints.length; i++) {
188 // IBreakpoint breakpoint= breakpoints[i];
189 // if (breakpoint instanceof IJavaMethodBreakpoint) {
190 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
191 // if (typeName.equals(methodBreakpoint.getTypeName())
192 // && methodName.equals(methodBreakpoint.getMethodName())
193 // && methodSignature.equals(methodBreakpoint.getMethodSignature())) {
194 // breakpointManager.removeBreakpoint(methodBreakpoint, true);
199 // // add the breakpoint
200 // JDIDebugModel.createMethodBreakpoint(getResource((IEditorPart)part), typeName, methodName, methodSignature, true, false, false, -1, -1, -1, 0, true, new HashMap(10));
203 // } else if (selection instanceof IStructuredSelection) {
204 // IMethod[] members= getMethods((IStructuredSelection)selection);
205 // if (members.length == 0) {
206 // report(ActionMessages.getString("ToggleBreakpointAdapter.9"), part); //$NON-NLS-1$
209 // // add or remove the breakpoint
210 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
211 // for (int i= 0, length= members.length; i < length; i++) {
212 // IMethod method= members[i];
213 // IJavaBreakpoint breakpoint= getBreakpoint(method);
214 // if (breakpoint == null) {
218 // ISourceRange range = method.getNameRange();
219 // if (range != null) {
220 // start = range.getOffset();
221 // end = start + range.getLength();
223 // Map attributes = new HashMap(10);
224 // BreakpointUtils.addJavaBreakpointAttributes(attributes, method);
225 // String methodName = method.getElementName();
226 // if (method.isConstructor()) {
227 // methodName = "<init>"; //$NON-NLS-1$
229 // IType type= method.getDeclaringType();
230 // String methodSignature= method.getSignature();
231 // if (!type.isBinary()) {
232 // //resolve the type names
233 // methodSignature= resolveMethodSignature(type, methodSignature);
234 // if (methodSignature == null) {
235 // IStatus status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Source method signature could not be resolved", null); //$NON-NLS-1$
236 // throw new CoreException(status);
239 // JDIDebugModel.createMethodBreakpoint(BreakpointUtils.getBreakpointResource(method), type.getFullyQualifiedName(), methodName, methodSignature, true, false, false, -1, start, end, 0, true, attributes);
241 // // remove breakpoint
242 // breakpointManager.removeBreakpoint(breakpoint, true);
249 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
251 public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
252 if (selection instanceof IStructuredSelection) {
253 IStructuredSelection ss = (IStructuredSelection) selection;
254 return getMethods(ss).length > 0;
256 return selection instanceof ITextSelection;
260 protected IMethod[] getMethods(IStructuredSelection selection) {
261 if (selection.isEmpty()) {
262 return new IMethod[0];
264 List methods = new ArrayList(selection.size());
265 Iterator iterator = selection.iterator();
266 while (iterator.hasNext()) {
267 Object thing = iterator.next();
269 if (thing instanceof IMethod && !Flags.isAbstract(((IMethod)thing).getFlags())) {
272 } catch (JavaModelException e) {
275 return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
279 // protected IField[] getFields(IStructuredSelection selection) {
280 // if (selection.isEmpty()) {
281 // return new IField[0];
283 // List fields = new ArrayList(selection.size());
284 // Iterator iterator = selection.iterator();
285 // while (iterator.hasNext()) {
286 // Object thing = iterator.next();
287 // if (thing instanceof IField) {
288 // fields.add(thing);
289 // } else if (thing instanceof IJavaFieldVariable) {
290 // IField field= getField((IJavaFieldVariable) thing);
291 // if (field != null) {
292 // fields.add(field);
296 // return (IField[]) fields.toArray(new IField[fields.size()]);
301 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
303 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
304 // report(null, part);
305 // selection = translateToMembers(part, selection);
306 // if (selection instanceof ITextSelection) {
307 // ITextSelection textSelection= (ITextSelection) selection;
308 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
309 // if (compilationUnit != null) {
310 // BreakpointFieldLocator locator= new BreakpointFieldLocator(textSelection.getOffset());
311 // compilationUnit.accept(locator);
312 // String fieldName= locator.getFieldName();
313 // if (fieldName == null) {
314 // report(ActionMessages.getString("ManageWatchpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
317 // String typeName= locator.getTypeName();
318 // // check if the watchpoint already exists. If yes, remove it
319 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
320 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
321 // for (int i= 0; i < breakpoints.length; i++) {
322 // IBreakpoint breakpoint= breakpoints[i];
323 // if (breakpoint instanceof IJavaWatchpoint) {
324 // IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
325 // if (typeName.equals(watchpoint.getTypeName()) && fieldName.equals(watchpoint.getFieldName())) {
326 // breakpointManager.removeBreakpoint(watchpoint, true);
331 // // add the watchpoint
332 // JDIDebugModel.createWatchpoint(getResource((IEditorPart)part), typeName, fieldName, -1, -1, -1, 0, true, new HashMap(10));
334 // } else if (selection instanceof IStructuredSelection) {
335 // IField[] members = getFields((IStructuredSelection)selection);
336 // if (members.length == 0) {
337 // report(ActionMessages.getString("ToggleBreakpointAdapter.10"), part); //$NON-NLS-1$
340 // // add or remove watchpoint
341 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
342 // for (int i= 0, length= members.length; i < length; i++) {
343 // IField element= members[i];
344 // IJavaBreakpoint breakpoint= getBreakpoint(element);
345 // if (breakpoint == null) {
346 // IType type = element.getDeclaringType();
349 // ISourceRange range = element.getNameRange();
350 // if (range != null) {
351 // start = range.getOffset();
352 // end = start + range.getLength();
354 // Map attributes = new HashMap(10);
355 // BreakpointUtils.addJavaBreakpointAttributes(attributes, element);
356 // JDIDebugModel.createWatchpoint(BreakpointUtils.getBreakpointResource(type), type.getFullyQualifiedName(), element.getElementName(), -1, start, end, 0, true, attributes);
358 // // remove breakpoint
359 // breakpointManager.removeBreakpoint(breakpoint, true);
365 public static String resolveMethodSignature(IType type, String methodSignature) throws JavaModelException {
366 String[] parameterTypes= Signature.getParameterTypes(methodSignature);
367 int length= length= parameterTypes.length;
368 String[] resolvedParameterTypes= new String[length];
370 for (int i = 0; i < length; i++) {
371 resolvedParameterTypes[i]= resolveType(type, parameterTypes[i]);
372 if (resolvedParameterTypes[i] == null) {
377 String resolvedReturnType= resolveType(type, Signature.getReturnType(methodSignature));
378 if (resolvedReturnType == null) {
382 return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
385 private static String resolveType(IType type, String typeSignature) throws JavaModelException {
386 // int count= Signature.getArrayCount(typeSignature);
387 // String elementTypeSignature= Signature.getElementType(typeSignature);
388 // if (elementTypeSignature.length() == 1) {
389 // // no need to resolve primitive types
390 // return typeSignature;
392 // String elementTypeName= Signature.toString(elementTypeSignature);
393 // String[][] resolvedElementTypeNames= type.resolveType(elementTypeName);
394 // if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) {
395 // // the type name cannot be resolved
398 // String resolvedElementTypeName= Signature.toQualifiedName(resolvedElementTypeNames[0]);
399 // String resolvedElementTypeSignature= Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/');
400 // return Signature.createArraySignature(resolvedElementTypeSignature, count);
404 protected static IResource getResource(IEditorPart editor) {
406 IEditorInput editorInput = editor.getEditorInput();
407 if (editorInput instanceof IFileEditorInput) {
408 resource= ((IFileEditorInput)editorInput).getFile();
410 resource= ResourcesPlugin.getWorkspace().getRoot();
416 * Returns a handle to the specified method or <code>null</code> if none.
418 * @param editorPart the editor containing the method
422 * @return handle or <code>null</code>
424 protected IMethod getMethodHandle(IEditorPart editorPart, String typeName, String methodName, String signature) throws CoreException {
425 IJavaElement element = (IJavaElement) editorPart.getEditorInput().getAdapter(IJavaElement.class);
427 if (element instanceof ICompilationUnit) {
428 IType[] types = ((ICompilationUnit)element).getAllTypes();
429 for (int i = 0; i < types.length; i++) {
430 if (types[i].getFullyQualifiedName().equals(typeName)) {
436 // else if (element instanceof IClassFile) {
437 // type = ((IClassFile)element).getType();
440 String[] sigs = Signature.getParameterTypes(signature);
441 return type.getMethod(methodName, sigs);
446 // protected IJavaBreakpoint getBreakpoint(IMember element) {
447 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
448 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
449 // if (element instanceof IMethod) {
450 // IMethod method= (IMethod)element;
451 // for (int i= 0; i < breakpoints.length; i++) {
452 // IBreakpoint breakpoint= breakpoints[i];
453 // if (breakpoint instanceof IJavaMethodBreakpoint) {
454 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
455 // IMember container = null;
457 // container= BreakpointUtils.getMember(methodBreakpoint);
458 // } catch (CoreException e) {
459 // JDIDebugUIPlugin.log(e);
462 // if (container == null) {
464 // if (method.getDeclaringType().getFullyQualifiedName().equals(methodBreakpoint.getTypeName())
465 // && method.getElementName().equals(methodBreakpoint.getMethodName())
466 // && method.getSignature().equals(methodBreakpoint.getMethodSignature())) {
467 // return methodBreakpoint;
469 // } catch (CoreException e) {
470 // JDIDebugUIPlugin.log(e);
473 // if (container instanceof IMethod) {
474 // if (method.getDeclaringType().getFullyQualifiedName().equals(container.getDeclaringType().getFullyQualifiedName())) {
475 // if (method.isSimilar((IMethod)container)) {
476 // return methodBreakpoint;
483 // } else if (element instanceof IField) {
484 // for (int i= 0; i < breakpoints.length; i++) {
485 // IBreakpoint breakpoint= breakpoints[i];
486 // if (breakpoint instanceof IJavaWatchpoint) {
488 // if (equalFields(element, (IJavaWatchpoint)breakpoint))
489 // return (IJavaBreakpoint)breakpoint;
490 // } catch (CoreException e) {
491 // JDIDebugUIPlugin.log(e);
500 * Compare two fields. The default <code>equals()</code>
501 * method for <code>IField</code> doesn't give the comparison desired.
503 // private boolean equalFields(IMember breakpointField, IJavaWatchpoint watchpoint) throws CoreException {
504 // return (breakpointField.getElementName().equals(watchpoint.getFieldName()) &&
505 // breakpointField.getDeclaringType().getFullyQualifiedName().equals(watchpoint.getTypeName()));
508 // protected CompilationUnit parseCompilationUnit(ITextEditor editor) {
509 // IEditorInput editorInput = editor.getEditorInput();
510 // IDocument document= editor.getDocumentProvider().getDocument(editorInput);
511 // ASTParser parser = ASTParser.newParser(AST.JLS2);
512 // parser.setSource(document.get().toCharArray());
513 // return (CompilationUnit) parser.createAST(null);
517 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
519 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
520 // if (selection instanceof IStructuredSelection) {
521 // IStructuredSelection ss = (IStructuredSelection) selection;
522 // return getFields(ss).length > 0;
524 // return selection instanceof ITextSelection;
530 * Returns a selection of the member in the given text selection,
531 * or the original selection if none.
535 * @return a structured selection of the member in the given text selection,
536 * or the original selection if none
537 * @exception CoreException if an exceptoin occurrs
539 // protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException {
540 // if (selection instanceof ITextSelection && part instanceof IEditorPart) {
541 // ITextSelection textSelection = (ITextSelection)selection;
542 // IEditorPart editorPart = (IEditorPart) part;
543 // IEditorInput editorInput = editorPart.getEditorInput();
545 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
546 // if (classFile != null) {
547 // IJavaElement e= classFile.getElementAt(textSelection.getOffset());
548 // if (e instanceof IMember) {
552 // IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
553 // ICompilationUnit unit= manager.getWorkingCopy(editorInput);
554 // if (unit != null) {
555 // synchronized (unit) {
556 // unit.reconcile(ICompilationUnit.NO_AST /*don't create ast*/, false/*don't force problem detection*/, null/*use primary owner*/, null/*no progress monitor*/);
558 // IJavaElement e = unit.getElementAt(textSelection.getOffset());
559 // if (e instanceof IMember) {
565 // return new StructuredSelection(m);
572 * Returns a list of matching types (IType - Java model) that correspond to the
573 * declaring type (ReferenceType - JDI model) of the given variable.
575 // protected static List searchForDeclaringType(IJavaFieldVariable variable) {
576 // List types= new ArrayList();
577 // ILaunch launch = variable.getDebugTarget().getLaunch();
578 // if (launch == null) {
582 // ILaunchConfiguration configuration= launch.getLaunchConfiguration();
583 // IJavaProject[] javaProjects = null;
584 // IWorkspace workspace= ResourcesPlugin.getWorkspace();
585 // if (configuration != null) {
586 // // Launch configuration support
588 // String projectName= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
589 // if (projectName.length() != 0) {
590 // javaProjects= new IJavaProject[] {JavaCore.create(workspace.getRoot().getProject(projectName))};
592 // IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
594 // List projectList= new ArrayList();
595 // for (int i= 0, numProjects= projects.length; i < numProjects; i++) {
596 // project= projects[i];
597 // if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
598 // projectList.add(JavaCore.create(project));
601 // javaProjects= new IJavaProject[projectList.size()];
602 // projectList.toArray(javaProjects);
604 // } catch (CoreException e) {
605 // JDIDebugUIPlugin.log(e);
608 // if (javaProjects == null) {
612 // SearchEngine engine= new SearchEngine();
613 // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(javaProjects, true);
614 // String declaringType= null;
616 // declaringType= variable.getDeclaringType().getName();
617 // } catch (DebugException x) {
618 // JDIDebugUIPlugin.log(x);
621 // ArrayList typeRefsFound= new ArrayList(3);
622 // ITypeNameRequestor requestor= new TypeInfoRequestor(typeRefsFound);
624 // engine.searchAllTypeNames(
625 // getPackage(declaringType),
626 // getTypeName(declaringType),
627 // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
628 // IJavaSearchConstants.CLASS,
631 // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
633 // } catch (JavaModelException x) {
634 // JDIDebugUIPlugin.log(x);
637 // Iterator iter= typeRefsFound.iterator();
638 // TypeInfo typeInfo= null;
639 // while (iter.hasNext()) {
640 // typeInfo= (TypeInfo)iter.next();
642 // types.add(typeInfo.resolveType(scope));
643 // } catch (JavaModelException jme) {
644 // JDIDebugUIPlugin.log(jme);
651 * Returns the package name of the given fully qualified type name.
652 * The package name is assumed to be the dot-separated prefix of the
655 // protected static char[] getPackage(String fullyQualifiedName) {
656 // int index= fullyQualifiedName.lastIndexOf('.');
657 // if (index == -1) {
658 // return new char[0];
660 // return fullyQualifiedName.substring(0, index).toCharArray();
664 // * Returns a simple type name from the given fully qualified type name.
665 // * The type name is assumed to be the last contiguous segment of the
666 // * fullyQualifiedName not containing a '.' or '$'
668 // protected static char[] getTypeName(String fullyQualifiedName) {
669 // int index= fullyQualifiedName.lastIndexOf('.');
670 // String typeName= fullyQualifiedName.substring(index + 1);
671 // int lastInnerClass= typeName.lastIndexOf('$');
672 // if (lastInnerClass != -1) {
673 // typeName= typeName.substring(lastInnerClass + 1);
675 // return typeName.toCharArray();
679 // * Return the associated IField (Java model) for the given
680 // * IJavaFieldVariable (JDI model)
682 // private IField getField(IJavaFieldVariable variable) {
683 // String varName= null;
685 // varName= variable.getName();
686 // } catch (DebugException x) {
687 // JDIDebugUIPlugin.log(x);
691 // List types= searchForDeclaringType(variable);
692 // Iterator iter= types.iterator();
693 // while (iter.hasNext()) {
694 // IType type= (IType)iter.next();
695 // field= type.getField(varName);
696 // if (field.exists()) {