1 11 package org.eclipse.debug.core.sourcelookup; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.MultiStatus; 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; 21 22 23 30 public abstract class AbstractSourceLookupParticipant implements ISourceLookupParticipant { 31 32 private ISourceLookupDirector fDirector; 33 34 protected static final Object [] EMPTY = new Object [0]; 35 36 39 public void init(ISourceLookupDirector director) { 40 fDirector = director; 41 } 42 43 46 public void dispose() { 47 fDirector = null; 48 } 49 50 53 public Object [] findSourceElements(Object object) throws CoreException { 54 List results = null; 55 CoreException single = null; 56 MultiStatus multiStatus = null; 57 if (isFindDuplicates()) { 58 results = new ArrayList (); 59 } 60 String name = getSourceName(object); 61 if (name != null) { 62 ISourceContainer[] containers = getSourceContainers(); 63 for (int i = 0; i < containers.length; i++) { 64 try { 65 ISourceContainer container = getDelegateContainer(containers[i]); 66 if (container != null) { 67 Object [] objects = container.findSourceElements(name); 68 if (objects.length > 0) { 69 if (isFindDuplicates()) { 70 for (int j = 0; j < objects.length; j++) { 71 results.add(objects[j]); 72 } 73 } else { 74 if (objects.length == 1) { 75 return objects; 76 } 77 return new Object []{objects[0]}; 78 } 79 } 80 } 81 } catch (CoreException e) { 82 if (single == null) { 83 single = e; 84 } else if (multiStatus == null) { 85 multiStatus = new MultiStatus(DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{single.getStatus()}, SourceLookupMessages.CompositeSourceContainer_0, null); 86 multiStatus.add(e.getStatus()); 87 } else { 88 multiStatus.add(e.getStatus()); 89 } 90 } 91 } 92 } 93 if (results == null) { 94 if (multiStatus != null) { 95 throw new CoreException(multiStatus); 96 } else if (single != null) { 97 throw single; 98 } 99 return EMPTY; 100 } 101 return results.toArray(); 102 } 103 104 114 protected ISourceContainer getDelegateContainer(ISourceContainer container) { 115 return container; 116 } 117 118 125 protected ISourceLookupDirector getDirector() { 126 return fDirector; 127 } 128 129 136 protected boolean isFindDuplicates() { 137 ISourceLookupDirector director = getDirector(); 138 if (director != null) { 139 return director.isFindDuplicates(); 140 } 141 return false; 142 } 143 144 151 protected ISourceContainer[] getSourceContainers() { 152 ISourceLookupDirector director = getDirector(); 153 if (director != null) { 154 return director.getSourceContainers(); 155 } 156 return new ISourceContainer[0]; 157 } 158 159 162 public void sourceContainersChanged(ISourceLookupDirector director) { 163 } 164 } 165 | Popular Tags |