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;
29 import org.eclipse.core.resources.IResource;
30 import org.eclipse.core.resources.ResourcesPlugin;
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.debug.core.DebugPlugin;
33 import org.eclipse.debug.internal.ui.actions.ActionMessages;
34 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
35 import org.eclipse.jface.text.IDocument;
36 import org.eclipse.jface.text.ITextSelection;
37 import org.eclipse.jface.viewers.ISelection;
38 import org.eclipse.jface.viewers.IStructuredSelection;
39 import org.eclipse.ui.IEditorInput;
40 import org.eclipse.ui.IEditorPart;
41 import org.eclipse.ui.IFileEditorInput;
42 import org.eclipse.ui.IWorkbenchPart;
43 import org.eclipse.ui.texteditor.IEditorStatusLine;
44 import org.eclipse.ui.texteditor.ITextEditor;
47 * Toggles a line breakpoint in a Java editor.
51 public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
53 protected void report(String message, IWorkbenchPart part) {
54 IEditorStatusLine statusLine= (IEditorStatusLine) part.getAdapter(IEditorStatusLine.class);
55 if (statusLine != null) {
56 if (message != null) {
57 statusLine.setMessage(true, message, null);
59 statusLine.setMessage(true, null, null);
62 if (message != null && PHPDebugUiPlugin.getActiveWorkbenchShell() != null) {
63 PHPDebugUiPlugin.getActiveWorkbenchShell().getDisplay().beep();
67 // protected IType getType(ITextSelection selection) {
68 // IMember member= ActionDelegateHelper.getDefault().getCurrentMember(selection);
70 // if (member instanceof IType) {
71 // type = (IType)member;
72 // } else if (member != null) {
73 // type= member.getDeclaringType();
75 // // bug 52385: we don't want local and anonymous types from compilation unit,
76 // // we are getting 'not-always-correct' names for them.
78 // while (type != null && !type.isBinary() && type.isLocal()) {
79 // type= type.getDeclaringType();
81 // } catch (JavaModelException e) {
82 // PHPDebugUiPlugin.log(e);
88 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(IWorkbenchPart, ISelection)
90 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
91 if (selection instanceof ITextSelection) {
93 IEditorPart editorPart = (IEditorPart)part;
94 ITextSelection textSelection = (ITextSelection)selection;
95 // IType type = getType(textSelection);
96 IEditorInput editorInput = editorPart.getEditorInput();
97 IDocument document= ((ITextEditor)editorPart).getDocumentProvider().getDocument(editorInput);
98 int lineNumber= textSelection.getStartLine() + 1;
99 int offset= textSelection.getOffset();
101 // if (type == null) {
102 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
103 // if (classFile != null) {
104 // type= classFile.getType();
105 // // bug 34856 - if this is an inner type, ensure the breakpoint is not
106 // // being added to the outer type
107 // if (type.getDeclaringType() != null) {
108 // ISourceRange sourceRange= type.getSourceRange();
109 // int start= sourceRange.getOffset();
110 // int end= start + sourceRange.getLength();
111 // if (offset < start || offset > end) {
112 // // not in the inner type
113 // IStatusLineManager statusLine = editorPart.getEditorSite().getActionBars().getStatusLineManager();
114 // 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$
115 // Display.getCurrent().beep();
122 // String typeName= null;
124 PHPLineBreakpoint breakpoint= null;
125 // if (type == null) {
126 if (editorInput instanceof IFileEditorInput) {
127 resource= ((IFileEditorInput)editorInput).getFile();
129 resource= ResourcesPlugin.getWorkspace().getRoot();
132 // typeName= type.getFullyQualifiedName();
133 // PHPLineBreakpoint breakpoint=PHPDebugModel.lineBreakpointExists(lineNumber);
134 // if (breakpoint==null)
135 // PHPDebugModel.createLineBreakpoint(getFile(), lineNumber, 0, true, null);
137 // DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
139 PHPLineBreakpoint existingBreakpoint= PHPDebugModel.lineBreakpointExists(lineNumber); //typeName, lineNumber);
140 if (existingBreakpoint != null) {
141 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(existingBreakpoint, true);
144 breakpoint = PHPDebugModel.createLineBreakpoint(resource, lineNumber, 0, true, null);
147 // new BreakpointLocationVerifierJob(document, breakpoint, lineNumber, typeName, type, resource, (IEditorStatusLine) editorPart.getAdapter(IEditorStatusLine.class)).schedule();
148 } catch (CoreException ce) {
149 ExceptionHandler.handle(ce, ActionMessages.getString("ManageBreakpointActionDelegate.error.title1"), ActionMessages.getString("ManageBreakpointActionDelegate.error.message1")); //$NON-NLS-1$ //$NON-NLS-2$
155 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(IWorkbenchPart, ISelection)
157 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
158 return selection instanceof ITextSelection;
162 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
164 public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
165 // report(null, part);
166 // selection = translateToMembers(part, selection);
167 // if (selection instanceof ITextSelection) {
168 // ITextSelection textSelection = (ITextSelection) selection;
169 // if (selection != null) {
170 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
171 // if (compilationUnit != null) {
172 // BreakpointMethodLocator locator= new BreakpointMethodLocator(textSelection.getOffset());
173 // compilationUnit.accept(locator);
174 // String methodName= locator.getMethodName();
175 // if (methodName == null) {
176 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
179 // String typeName= locator.getTypeName();
180 // String methodSignature= locator.getMethodSignature();
181 // if (methodSignature == null) {
182 // report(ActionMessages.getString("ManageMethodBreakpointActionDelegate.methodNonAvailable"), part); //$NON-NLS-1$
185 // // check if this method breakpoint already exist. If yes, remove it.
186 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
187 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
188 // for (int i= 0; i < breakpoints.length; i++) {
189 // IBreakpoint breakpoint= breakpoints[i];
190 // if (breakpoint instanceof IJavaMethodBreakpoint) {
191 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
192 // if (typeName.equals(methodBreakpoint.getTypeName())
193 // && methodName.equals(methodBreakpoint.getMethodName())
194 // && methodSignature.equals(methodBreakpoint.getMethodSignature())) {
195 // breakpointManager.removeBreakpoint(methodBreakpoint, true);
200 // // add the breakpoint
201 // JDIDebugModel.createMethodBreakpoint(getResource((IEditorPart)part), typeName, methodName, methodSignature, true, false, false, -1, -1, -1, 0, true, new HashMap(10));
204 // } else if (selection instanceof IStructuredSelection) {
205 // IMethod[] members= getMethods((IStructuredSelection)selection);
206 // if (members.length == 0) {
207 // report(ActionMessages.getString("ToggleBreakpointAdapter.9"), part); //$NON-NLS-1$
210 // // add or remove the breakpoint
211 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
212 // for (int i= 0, length= members.length; i < length; i++) {
213 // IMethod method= members[i];
214 // IJavaBreakpoint breakpoint= getBreakpoint(method);
215 // if (breakpoint == null) {
219 // ISourceRange range = method.getNameRange();
220 // if (range != null) {
221 // start = range.getOffset();
222 // end = start + range.getLength();
224 // Map attributes = new HashMap(10);
225 // BreakpointUtils.addJavaBreakpointAttributes(attributes, method);
226 // String methodName = method.getElementName();
227 // if (method.isConstructor()) {
228 // methodName = "<init>"; //$NON-NLS-1$
230 // IType type= method.getDeclaringType();
231 // String methodSignature= method.getSignature();
232 // if (!type.isBinary()) {
233 // //resolve the type names
234 // methodSignature= resolveMethodSignature(type, methodSignature);
235 // if (methodSignature == null) {
236 // IStatus status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Source method signature could not be resolved", null); //$NON-NLS-1$
237 // throw new CoreException(status);
240 // JDIDebugModel.createMethodBreakpoint(BreakpointUtils.getBreakpointResource(method), type.getFullyQualifiedName(), methodName, methodSignature, true, false, false, -1, start, end, 0, true, attributes);
242 // // remove breakpoint
243 // breakpointManager.removeBreakpoint(breakpoint, true);
250 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
252 public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
253 // if (selection instanceof IStructuredSelection) {
254 // IStructuredSelection ss = (IStructuredSelection) selection;
255 // return getMethods(ss).length > 0;
257 // return selection instanceof ITextSelection;
262 protected IMethod[] getMethods(IStructuredSelection selection) {
263 if (selection.isEmpty()) {
264 return new IMethod[0];
266 List methods = new ArrayList(selection.size());
267 Iterator iterator = selection.iterator();
268 while (iterator.hasNext()) {
269 Object thing = iterator.next();
271 if (thing instanceof IMethod && !Flags.isAbstract(((IMethod)thing).getFlags())) {
274 } catch (JavaModelException e) {
277 return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
281 // protected IField[] getFields(IStructuredSelection selection) {
282 // if (selection.isEmpty()) {
283 // return new IField[0];
285 // List fields = new ArrayList(selection.size());
286 // Iterator iterator = selection.iterator();
287 // while (iterator.hasNext()) {
288 // Object thing = iterator.next();
289 // if (thing instanceof IField) {
290 // fields.add(thing);
291 // } else if (thing instanceof IJavaFieldVariable) {
292 // IField field= getField((IJavaFieldVariable) thing);
293 // if (field != null) {
294 // fields.add(field);
298 // return (IField[]) fields.toArray(new IField[fields.size()]);
303 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
305 public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
306 // report(null, part);
307 // selection = translateToMembers(part, selection);
308 // if (selection instanceof ITextSelection) {
309 // ITextSelection textSelection= (ITextSelection) selection;
310 // CompilationUnit compilationUnit= parseCompilationUnit((ITextEditor)part);
311 // if (compilationUnit != null) {
312 // BreakpointFieldLocator locator= new BreakpointFieldLocator(textSelection.getOffset());
313 // compilationUnit.accept(locator);
314 // String fieldName= locator.getFieldName();
315 // if (fieldName == null) {
316 // report(ActionMessages.getString("ManageWatchpointActionDelegate.CantAdd"), part); //$NON-NLS-1$
319 // String typeName= locator.getTypeName();
320 // // check if the watchpoint already exists. If yes, remove it
321 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
322 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
323 // for (int i= 0; i < breakpoints.length; i++) {
324 // IBreakpoint breakpoint= breakpoints[i];
325 // if (breakpoint instanceof IJavaWatchpoint) {
326 // IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
327 // if (typeName.equals(watchpoint.getTypeName()) && fieldName.equals(watchpoint.getFieldName())) {
328 // breakpointManager.removeBreakpoint(watchpoint, true);
333 // // add the watchpoint
334 // JDIDebugModel.createWatchpoint(getResource((IEditorPart)part), typeName, fieldName, -1, -1, -1, 0, true, new HashMap(10));
336 // } else if (selection instanceof IStructuredSelection) {
337 // IField[] members = getFields((IStructuredSelection)selection);
338 // if (members.length == 0) {
339 // report(ActionMessages.getString("ToggleBreakpointAdapter.10"), part); //$NON-NLS-1$
342 // // add or remove watchpoint
343 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
344 // for (int i= 0, length= members.length; i < length; i++) {
345 // IField element= members[i];
346 // IJavaBreakpoint breakpoint= getBreakpoint(element);
347 // if (breakpoint == null) {
348 // IType type = element.getDeclaringType();
351 // ISourceRange range = element.getNameRange();
352 // if (range != null) {
353 // start = range.getOffset();
354 // end = start + range.getLength();
356 // Map attributes = new HashMap(10);
357 // BreakpointUtils.addJavaBreakpointAttributes(attributes, element);
358 // JDIDebugModel.createWatchpoint(BreakpointUtils.getBreakpointResource(type), type.getFullyQualifiedName(), element.getElementName(), -1, start, end, 0, true, attributes);
360 // // remove breakpoint
361 // breakpointManager.removeBreakpoint(breakpoint, true);
367 public static String resolveMethodSignature(IType type, String methodSignature) throws JavaModelException {
368 String[] parameterTypes= Signature.getParameterTypes(methodSignature);
369 int length= length= parameterTypes.length;
370 String[] resolvedParameterTypes= new String[length];
372 for (int i = 0; i < length; i++) {
373 resolvedParameterTypes[i]= resolveType(type, parameterTypes[i]);
374 if (resolvedParameterTypes[i] == null) {
379 String resolvedReturnType= resolveType(type, Signature.getReturnType(methodSignature));
380 if (resolvedReturnType == null) {
384 return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
387 private static String resolveType(IType type, String typeSignature) throws JavaModelException {
388 // int count= Signature.getArrayCount(typeSignature);
389 // String elementTypeSignature= Signature.getElementType(typeSignature);
390 // if (elementTypeSignature.length() == 1) {
391 // // no need to resolve primitive types
392 // return typeSignature;
394 // String elementTypeName= Signature.toString(elementTypeSignature);
395 // String[][] resolvedElementTypeNames= type.resolveType(elementTypeName);
396 // if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) {
397 // // the type name cannot be resolved
400 // String resolvedElementTypeName= Signature.toQualifiedName(resolvedElementTypeNames[0]);
401 // String resolvedElementTypeSignature= Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/');
402 // return Signature.createArraySignature(resolvedElementTypeSignature, count);
406 protected static IResource getResource(IEditorPart editor) {
408 IEditorInput editorInput = editor.getEditorInput();
409 if (editorInput instanceof IFileEditorInput) {
410 resource= ((IFileEditorInput)editorInput).getFile();
412 resource= ResourcesPlugin.getWorkspace().getRoot();
418 * Returns a handle to the specified method or <code>null</code> if none.
420 * @param editorPart the editor containing the method
424 * @return handle or <code>null</code>
426 protected IMethod getMethodHandle(IEditorPart editorPart, String typeName, String methodName, String signature) throws CoreException {
427 IJavaElement element = (IJavaElement) editorPart.getEditorInput().getAdapter(IJavaElement.class);
429 if (element instanceof ICompilationUnit) {
430 IType[] types = ((ICompilationUnit)element).getAllTypes();
431 for (int i = 0; i < types.length; i++) {
432 if (types[i].getFullyQualifiedName().equals(typeName)) {
438 // else if (element instanceof IClassFile) {
439 // type = ((IClassFile)element).getType();
442 String[] sigs = Signature.getParameterTypes(signature);
443 return type.getMethod(methodName, sigs);
448 // protected IJavaBreakpoint getBreakpoint(IMember element) {
449 // IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
450 // IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier());
451 // if (element instanceof IMethod) {
452 // IMethod method= (IMethod)element;
453 // for (int i= 0; i < breakpoints.length; i++) {
454 // IBreakpoint breakpoint= breakpoints[i];
455 // if (breakpoint instanceof IJavaMethodBreakpoint) {
456 // IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint;
457 // IMember container = null;
459 // container= BreakpointUtils.getMember(methodBreakpoint);
460 // } catch (CoreException e) {
461 // JDIDebugUIPlugin.log(e);
464 // if (container == null) {
466 // if (method.getDeclaringType().getFullyQualifiedName().equals(methodBreakpoint.getTypeName())
467 // && method.getElementName().equals(methodBreakpoint.getMethodName())
468 // && method.getSignature().equals(methodBreakpoint.getMethodSignature())) {
469 // return methodBreakpoint;
471 // } catch (CoreException e) {
472 // JDIDebugUIPlugin.log(e);
475 // if (container instanceof IMethod) {
476 // if (method.getDeclaringType().getFullyQualifiedName().equals(container.getDeclaringType().getFullyQualifiedName())) {
477 // if (method.isSimilar((IMethod)container)) {
478 // return methodBreakpoint;
485 // } else if (element instanceof IField) {
486 // for (int i= 0; i < breakpoints.length; i++) {
487 // IBreakpoint breakpoint= breakpoints[i];
488 // if (breakpoint instanceof IJavaWatchpoint) {
490 // if (equalFields(element, (IJavaWatchpoint)breakpoint))
491 // return (IJavaBreakpoint)breakpoint;
492 // } catch (CoreException e) {
493 // JDIDebugUIPlugin.log(e);
502 * Compare two fields. The default <code>equals()</code>
503 * method for <code>IField</code> doesn't give the comparison desired.
505 // private boolean equalFields(IMember breakpointField, IJavaWatchpoint watchpoint) throws CoreException {
506 // return (breakpointField.getElementName().equals(watchpoint.getFieldName()) &&
507 // breakpointField.getDeclaringType().getFullyQualifiedName().equals(watchpoint.getTypeName()));
510 // protected CompilationUnit parseCompilationUnit(ITextEditor editor) {
511 // IEditorInput editorInput = editor.getEditorInput();
512 // IDocument document= editor.getDocumentProvider().getDocument(editorInput);
513 // ASTParser parser = ASTParser.newParser(AST.JLS2);
514 // parser.setSource(document.get().toCharArray());
515 // return (CompilationUnit) parser.createAST(null);
519 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
521 public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
522 // if (selection instanceof IStructuredSelection) {
523 // IStructuredSelection ss = (IStructuredSelection) selection;
524 // return getFields(ss).length > 0;
526 // return selection instanceof ITextSelection;
532 * Returns a selection of the member in the given text selection,
533 * or the original selection if none.
537 * @return a structured selection of the member in the given text selection,
538 * or the original selection if none
539 * @exception CoreException if an exceptoin occurrs
541 // protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException {
542 // if (selection instanceof ITextSelection && part instanceof IEditorPart) {
543 // ITextSelection textSelection = (ITextSelection)selection;
544 // IEditorPart editorPart = (IEditorPart) part;
545 // IEditorInput editorInput = editorPart.getEditorInput();
547 // IClassFile classFile= (IClassFile)editorInput.getAdapter(IClassFile.class);
548 // if (classFile != null) {
549 // IJavaElement e= classFile.getElementAt(textSelection.getOffset());
550 // if (e instanceof IMember) {
554 // IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
555 // ICompilationUnit unit= manager.getWorkingCopy(editorInput);
556 // if (unit != null) {
557 // synchronized (unit) {
558 // unit.reconcile(ICompilationUnit.NO_AST /*don't create ast*/, false/*don't force problem detection*/, null/*use primary owner*/, null/*no progress monitor*/);
560 // IJavaElement e = unit.getElementAt(textSelection.getOffset());
561 // if (e instanceof IMember) {
567 // return new StructuredSelection(m);
574 * Returns a list of matching types (IType - Java model) that correspond to the
575 * declaring type (ReferenceType - JDI model) of the given variable.
577 // protected static List searchForDeclaringType(IJavaFieldVariable variable) {
578 // List types= new ArrayList();
579 // ILaunch launch = variable.getDebugTarget().getLaunch();
580 // if (launch == null) {
584 // ILaunchConfiguration configuration= launch.getLaunchConfiguration();
585 // IJavaProject[] javaProjects = null;
586 // IWorkspace workspace= ResourcesPlugin.getWorkspace();
587 // if (configuration != null) {
588 // // Launch configuration support
590 // String projectName= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
591 // if (projectName.length() != 0) {
592 // javaProjects= new IJavaProject[] {JavaCore.create(workspace.getRoot().getProject(projectName))};
594 // IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
596 // List projectList= new ArrayList();
597 // for (int i= 0, numProjects= projects.length; i < numProjects; i++) {
598 // project= projects[i];
599 // if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
600 // projectList.add(JavaCore.create(project));
603 // javaProjects= new IJavaProject[projectList.size()];
604 // projectList.toArray(javaProjects);
606 // } catch (CoreException e) {
607 // JDIDebugUIPlugin.log(e);
610 // if (javaProjects == null) {
614 // SearchEngine engine= new SearchEngine();
615 // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(javaProjects, true);
616 // String declaringType= null;
618 // declaringType= variable.getDeclaringType().getName();
619 // } catch (DebugException x) {
620 // JDIDebugUIPlugin.log(x);
623 // ArrayList typeRefsFound= new ArrayList(3);
624 // ITypeNameRequestor requestor= new TypeInfoRequestor(typeRefsFound);
626 // engine.searchAllTypeNames(
627 // getPackage(declaringType),
628 // getTypeName(declaringType),
629 // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
630 // IJavaSearchConstants.CLASS,
633 // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
635 // } catch (JavaModelException x) {
636 // JDIDebugUIPlugin.log(x);
639 // Iterator iter= typeRefsFound.iterator();
640 // TypeInfo typeInfo= null;
641 // while (iter.hasNext()) {
642 // typeInfo= (TypeInfo)iter.next();
644 // types.add(typeInfo.resolveType(scope));
645 // } catch (JavaModelException jme) {
646 // JDIDebugUIPlugin.log(jme);
653 * Returns the package name of the given fully qualified type name.
654 * The package name is assumed to be the dot-separated prefix of the
657 // protected static char[] getPackage(String fullyQualifiedName) {
658 // int index= fullyQualifiedName.lastIndexOf('.');
659 // if (index == -1) {
660 // return new char[0];
662 // return fullyQualifiedName.substring(0, index).toCharArray();
666 // * Returns a simple type name from the given fully qualified type name.
667 // * The type name is assumed to be the last contiguous segment of the
668 // * fullyQualifiedName not containing a '.' or '$'
670 // protected static char[] getTypeName(String fullyQualifiedName) {
671 // int index= fullyQualifiedName.lastIndexOf('.');
672 // String typeName= fullyQualifiedName.substring(index + 1);
673 // int lastInnerClass= typeName.lastIndexOf('$');
674 // if (lastInnerClass != -1) {
675 // typeName= typeName.substring(lastInnerClass + 1);
677 // return typeName.toCharArray();
681 // * Return the associated IField (Java model) for the given
682 // * IJavaFieldVariable (JDI model)
684 // private IField getField(IJavaFieldVariable variable) {
685 // String varName= null;
687 // varName= variable.getName();
688 // } catch (DebugException x) {
689 // JDIDebugUIPlugin.log(x);
693 // List types= searchForDeclaringType(variable);
694 // Iterator iter= types.iterator();
695 // while (iter.hasNext()) {
696 // IType type= (IType)iter.next();
697 // field= type.getField(varName);
698 // if (field.exists()) {