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;
261 protected IMethod[] getMethods(IStructuredSelection selection) {
262 if (selection.isEmpty()) {
263 return new IMethod[0];
265 List methods = new ArrayList(selection.size());
266 Iterator iterator = selection.iterator();
267 while (iterator.hasNext()) {
268 Object thing = iterator.next();
270 if (thing instanceof IMethod && !Flags.isAbstract(((IMethod)thing).getFlags())) {
273 } catch (JavaModelException e) {
276 return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
280 // protected IField[] getFields(IStructuredSelection selection) {
281 // if (selection.isEmpty()) {
282 // return new IField[0];
284 // List fields = new ArrayList(selection.size());
285 // Iterator iterator = selection.iterator();
286 // while (iterator.hasNext()) {
287 // Object thing = iterator.next();
288 // if (thing instanceof IField) {
289 // fields.add(thing);
290 // } else if (thing instanceof IJavaFieldVariable) {
291 // IField field= getField((IJavaFieldVariable) thing);
292 // if (field != null) {
293 // fields.add(field);
297 // return (IField[]) fields.toArray(new IField[fields.size()]);
302 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
304 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
305 // report(null, part);
306 // selection = translateToMembers(part, selection);
307 // if (selection instanceof ITextSelection) {
308 // ITextSelection textSelection= (ITextSelection) selection;
309 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
310 // if (compilationUnit != null) {
311 // BreakpointFieldLocator locator= new BreakpointFieldLocator(textSelection.getOffset());
312 // compilationUnit.accept(locator);
313 // String fieldName= locator.getFieldName();
314 // if (fieldName == null) {
315 // report(ActionMessages.getString("ManageWatchpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
318 // String typeName= locator.getTypeName();
319 // // check if the watchpoint already exists. If yes, remove it
320 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
321 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
322 // for (int i= 0; i < breakpoints.length; i++) {
323 // IBreakpoint breakpoint= breakpoints[i];
324 // if (breakpoint instanceof IJavaWatchpoint) {
325 // IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
326 // if (typeName.equals(watchpoint.getTypeName()) && fieldName.equals(watchpoint.getFieldName())) {
327 // breakpointManager.removeBreakpoint(watchpoint, true);
332 // // add the watchpoint
333 // JDIDebugModel.createWatchpoint(getResource((IEditorPart)part), typeName, fieldName, -1, -1, -1, 0, true, new HashMap(10));
335 // } else if (selection instanceof IStructuredSelection) {
336 // IField[] members = getFields((IStructuredSelection)selection);
337 // if (members.length == 0) {
338 // report(ActionMessages.getString("ToggleBreakpointAdapter.10"), part); //$NON-NLS-1$
341 // // add or remove watchpoint
342 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
343 // for (int i= 0, length= members.length; i < length; i++) {
344 // IField element= members[i];
345 // IJavaBreakpoint breakpoint= getBreakpoint(element);
346 // if (breakpoint == null) {
347 // IType type = element.getDeclaringType();
350 // ISourceRange range = element.getNameRange();
351 // if (range != null) {
352 // start = range.getOffset();
353 // end = start + range.getLength();
355 // Map attributes = new HashMap(10);
356 // BreakpointUtils.addJavaBreakpointAttributes(attributes, element);
357 // JDIDebugModel.createWatchpoint(BreakpointUtils.getBreakpointResource(type), type.getFullyQualifiedName(), element.getElementName(), -1, start, end, 0, true, attributes);
359 // // remove breakpoint
360 // breakpointManager.removeBreakpoint(breakpoint, true);
366 public static String resolveMethodSignature(IType type, String methodSignature) throws JavaModelException {
367 String[] parameterTypes= Signature.getParameterTypes(methodSignature);
368 int length= length= parameterTypes.length;
369 String[] resolvedParameterTypes= new String[length];
371 for (int i = 0; i < length; i++) {
372 resolvedParameterTypes[i]= resolveType(type, parameterTypes[i]);
373 if (resolvedParameterTypes[i] == null) {
378 String resolvedReturnType= resolveType(type, Signature.getReturnType(methodSignature));
379 if (resolvedReturnType == null) {
383 return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
386 private static String resolveType(IType type, String typeSignature) throws JavaModelException {
387 // int count= Signature.getArrayCount(typeSignature);
388 // String elementTypeSignature= Signature.getElementType(typeSignature);
389 // if (elementTypeSignature.length() == 1) {
390 // // no need to resolve primitive types
391 // return typeSignature;
393 // String elementTypeName= Signature.toString(elementTypeSignature);
394 // String[][] resolvedElementTypeNames= type.resolveType(elementTypeName);
395 // if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) {
396 // // the type name cannot be resolved
399 // String resolvedElementTypeName= Signature.toQualifiedName(resolvedElementTypeNames[0]);
400 // String resolvedElementTypeSignature= Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/');
401 // return Signature.createArraySignature(resolvedElementTypeSignature, count);
405 protected static IResource getResource(IEditorPart editor) {
407 IEditorInput editorInput = editor.getEditorInput();
408 if (editorInput instanceof IFileEditorInput) {
409 resource= ((IFileEditorInput)editorInput).getFile();
411 resource= ResourcesPlugin.getWorkspace().getRoot();
417 * Returns a handle to the specified method or <code>null</code> if none.
419 * @param editorPart the editor containing the method
423 * @return handle or <code>null</code>
425 protected IMethod getMethodHandle(IEditorPart editorPart, String typeName, String methodName, String signature) throws CoreException {
426 IJavaElement element = (IJavaElement) editorPart.getEditorInput().getAdapter(IJavaElement.class);
428 if (element instanceof ICompilationUnit) {
429 IType[] types = ((ICompilationUnit)element).getAllTypes();
430 for (int i = 0; i < types.length; i++) {
431 if (types[i].getFullyQualifiedName().equals(typeName)) {
437 // else if (element instanceof IClassFile) {
438 // type = ((IClassFile)element).getType();
441 String[] sigs = Signature.getParameterTypes(signature);
442 return type.getMethod(methodName, sigs);
447 // protected IJavaBreakpoint getBreakpoint(IMember element) {
448 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
449 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
450 // if (element instanceof IMethod) {
451 // IMethod method= (IMethod)element;
452 // for (int i= 0; i < breakpoints.length; i++) {
453 // IBreakpoint breakpoint= breakpoints[i];
454 // if (breakpoint instanceof IJavaMethodBreakpoint) {
455 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
456 // IMember container = null;
458 // container= BreakpointUtils.getMember(methodBreakpoint);
459 // } catch (CoreException e) {
460 // JDIDebugUIPlugin.log(e);
463 // if (container == null) {
465 // if (method.getDeclaringType().getFullyQualifiedName().equals(methodBreakpoint.getTypeName())
466 // && method.getElementName().equals(methodBreakpoint.getMethodName())
467 // && method.getSignature().equals(methodBreakpoint.getMethodSignature())) {
468 // return methodBreakpoint;
470 // } catch (CoreException e) {
471 // JDIDebugUIPlugin.log(e);
474 // if (container instanceof IMethod) {
475 // if (method.getDeclaringType().getFullyQualifiedName().equals(container.getDeclaringType().getFullyQualifiedName())) {
476 // if (method.isSimilar((IMethod)container)) {
477 // return methodBreakpoint;
484 // } else if (element instanceof IField) {
485 // for (int i= 0; i < breakpoints.length; i++) {
486 // IBreakpoint breakpoint= breakpoints[i];
487 // if (breakpoint instanceof IJavaWatchpoint) {
489 // if (equalFields(element, (IJavaWatchpoint)breakpoint))
490 // return (IJavaBreakpoint)breakpoint;
491 // } catch (CoreException e) {
492 // JDIDebugUIPlugin.log(e);
501 * Compare two fields. The default <code>equals()</code>
502 * method for <code>IField</code> doesn't give the comparison desired.
504 // private boolean equalFields(IMember breakpointField, IJavaWatchpoint watchpoint) throws CoreException {
505 // return (breakpointField.getElementName().equals(watchpoint.getFieldName()) &&
506 // breakpointField.getDeclaringType().getFullyQualifiedName().equals(watchpoint.getTypeName()));
509 // protected CompilationUnit parseCompilationUnit(ITextEditor editor) {
510 // IEditorInput editorInput = editor.getEditorInput();
511 // IDocument document= editor.getDocumentProvider().getDocument(editorInput);
512 // ASTParser parser = ASTParser.newParser(AST.JLS2);
513 // parser.setSource(document.get().toCharArray());
514 // return (CompilationUnit) parser.createAST(null);
518 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
520 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
521 // if (selection instanceof IStructuredSelection) {
522 // IStructuredSelection ss = (IStructuredSelection) selection;
523 // return getFields(ss).length > 0;
525 // return selection instanceof ITextSelection;
531 * Returns a selection of the member in the given text selection,
532 * or the original selection if none.
536 * @return a structured selection of the member in the given text selection,
537 * or the original selection if none
538 * @exception CoreException if an exceptoin occurrs
540 // protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException {
541 // if (selection instanceof ITextSelection && part instanceof IEditorPart) {
542 // ITextSelection textSelection = (ITextSelection)selection;
543 // IEditorPart editorPart = (IEditorPart) part;
544 // IEditorInput editorInput = editorPart.getEditorInput();
546 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
547 // if (classFile != null) {
548 // IJavaElement e= classFile.getElementAt(textSelection.getOffset());
549 // if (e instanceof IMember) {
553 // IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
554 // ICompilationUnit unit= manager.getWorkingCopy(editorInput);
555 // if (unit != null) {
556 // synchronized (unit) {
557 // unit.reconcile(ICompilationUnit.NO_AST /*don't create ast*/, false/*don't force problem detection*/, null/*use primary owner*/, null/*no progress monitor*/);
559 // IJavaElement e = unit.getElementAt(textSelection.getOffset());
560 // if (e instanceof IMember) {
566 // return new StructuredSelection(m);
573 * Returns a list of matching types (IType - Java model) that correspond to the
574 * declaring type (ReferenceType - JDI model) of the given variable.
576 // protected static List searchForDeclaringType(IJavaFieldVariable variable) {
577 // List types= new ArrayList();
578 // ILaunch launch = variable.getDebugTarget().getLaunch();
579 // if (launch == null) {
583 // ILaunchConfiguration configuration= launch.getLaunchConfiguration();
584 // IJavaProject[] javaProjects = null;
585 // IWorkspace workspace= ResourcesPlugin.getWorkspace();
586 // if (configuration != null) {
587 // // Launch configuration support
589 // String projectName= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
590 // if (projectName.length() != 0) {
591 // javaProjects= new IJavaProject[] {JavaCore.create(workspace.getRoot().getProject(projectName))};
593 // IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
595 // List projectList= new ArrayList();
596 // for (int i= 0, numProjects= projects.length; i < numProjects; i++) {
597 // project= projects[i];
598 // if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
599 // projectList.add(JavaCore.create(project));
602 // javaProjects= new IJavaProject[projectList.size()];
603 // projectList.toArray(javaProjects);
605 // } catch (CoreException e) {
606 // JDIDebugUIPlugin.log(e);
609 // if (javaProjects == null) {
613 // SearchEngine engine= new SearchEngine();
614 // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(javaProjects, true);
615 // String declaringType= null;
617 // declaringType= variable.getDeclaringType().getName();
618 // } catch (DebugException x) {
619 // JDIDebugUIPlugin.log(x);
622 // ArrayList typeRefsFound= new ArrayList(3);
623 // ITypeNameRequestor requestor= new TypeInfoRequestor(typeRefsFound);
625 // engine.searchAllTypeNames(
626 // getPackage(declaringType),
627 // getTypeName(declaringType),
628 // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
629 // IJavaSearchConstants.CLASS,
632 // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
634 // } catch (JavaModelException x) {
635 // JDIDebugUIPlugin.log(x);
638 // Iterator iter= typeRefsFound.iterator();
639 // TypeInfo typeInfo= null;
640 // while (iter.hasNext()) {
641 // typeInfo= (TypeInfo)iter.next();
643 // types.add(typeInfo.resolveType(scope));
644 // } catch (JavaModelException jme) {
645 // JDIDebugUIPlugin.log(jme);
652 * Returns the package name of the given fully qualified type name.
653 * The package name is assumed to be the dot-separated prefix of the
656 // protected static char[] getPackage(String fullyQualifiedName) {
657 // int index= fullyQualifiedName.lastIndexOf('.');
658 // if (index == -1) {
659 // return new char[0];
661 // return fullyQualifiedName.substring(0, index).toCharArray();
665 // * Returns a simple type name from the given fully qualified type name.
666 // * The type name is assumed to be the last contiguous segment of the
667 // * fullyQualifiedName not containing a '.' or '$'
669 // protected static char[] getTypeName(String fullyQualifiedName) {
670 // int index= fullyQualifiedName.lastIndexOf('.');
671 // String typeName= fullyQualifiedName.substring(index + 1);
672 // int lastInnerClass= typeName.lastIndexOf('$');
673 // if (lastInnerClass != -1) {
674 // typeName= typeName.substring(lastInnerClass + 1);
676 // return typeName.toCharArray();
680 // * Return the associated IField (Java model) for the given
681 // * IJavaFieldVariable (JDI model)
683 // private IField getField(IJavaFieldVariable variable) {
684 // String varName= null;
686 // varName= variable.getName();
687 // } catch (DebugException x) {
688 // JDIDebugUIPlugin.log(x);
692 // List types= searchForDeclaringType(variable);
693 // Iterator iter= types.iterator();
694 // while (iter.hasNext()) {
695 // IType type= (IType)iter.next();
696 // field= type.getField(varName);
697 // if (field.exists()) {