use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.
the class BreakpointRulerAction method getResource.
public static final IResource getResource(IEditorInput input) {
IResource resource = null;
if (input instanceof IFileEditorInput)
resource = ((IFileEditorInput) input).getFile();
if (resource == null)
resource = input.getAdapter(IFile.class);
if (resource == null)
resource = input.getAdapter(IResource.class);
IEditorPart editorPart = null;
if (resource == null) {
IWorkbench workbench = SSEUIPlugin.getDefault().getWorkbench();
if (workbench != null) {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IPartService service = window.getPartService();
if (service != null) {
Object part = service.getActivePart();
if (part != null && part instanceof IEditorPart) {
editorPart = (IEditorPart) part;
if (editorPart != null) {
IStructuredModel model = null;
ITextEditor textEditor = null;
try {
if (editorPart instanceof ITextEditor) {
textEditor = (ITextEditor) editorPart;
}
if (textEditor == null) {
textEditor = editorPart.getAdapter(ITextEditor.class);
}
if (textEditor != null) {
IDocument textDocument = textEditor.getDocumentProvider().getDocument(input);
model = StructuredModelManager.getModelManager().getExistingModelForRead(textDocument);
if (model != null) {
resource = BreakpointProviderBuilder.getInstance().getResource(input, model.getContentTypeIdentifier(), getFileExtension(input));
}
}
if (resource == null) {
IBreakpointProvider[] providers = BreakpointProviderBuilder.getInstance().getBreakpointProviders(editorPart, null, getFileExtension(input));
for (int i = 0; i < providers.length && resource == null; i++) {
resource = providers[i].getResource(input);
}
}
} catch (Exception e) {
Logger.logException(e);
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
}
}
}
}
}
return resource;
}
use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.
the class BreakpointProviderBuilder method getBreakpointProviders.
/**
* Returns an array of breakpoint providers for a specified content type
* handler
*
* @param handler
* a content type handler
* @param ext
* file extension
* @return IBreakpointProvider[]
*/
public IBreakpointProvider[] getBreakpointProviders(IEditorPart editorpart, String contentTypeID, String ext) {
initCache();
// Get breakpoint providers for this content type handler
IBreakpointProvider[] providers1 = new IBreakpointProvider[0];
IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeID);
List holdProviders = new ArrayList(2);
while (contentType != null) {
IBreakpointProvider[] providers = (IBreakpointProvider[]) map.get(contentType.getId());
if (providers == null) {
providers = createBreakpointProviders(ATT_CONTENT_TYPES, contentType.getId());
if (providers != null) {
map.put(contentType.getId(), providers);
}
}
// providers were retrieved from cache or newly created
if (providers != null) {
holdProviders.addAll(Arrays.asList(providers));
}
contentType = contentType.getBaseType();
}
providers1 = (IBreakpointProvider[]) holdProviders.toArray(new IBreakpointProvider[holdProviders.size()]);
// Get breakpoint providers for this extension
IBreakpointProvider[] providers2 = new IBreakpointProvider[0];
if (ext != null) {
providers2 = (IBreakpointProvider[]) map.get(ext);
if (providers2 == null) {
providers2 = createBreakpointProviders(ATT_EXTENSIONS, ext);
if (providers2 != null) {
map.put(ext, providers2);
}
}
}
// create single hash set to remove duplication
Set s = new HashSet();
s.addAll(Arrays.asList(providers1));
s.addAll(Arrays.asList(providers2));
// create IBreakpointProvider[] to return
IBreakpointProvider[] providers = new IBreakpointProvider[s.size()];
Iterator itr = s.iterator();
int i = 0;
ISourceEditingTextTools tools = null;
if (editorpart != null && itr.hasNext())
tools = editorpart.getAdapter(ISourceEditingTextTools.class);
while (itr.hasNext()) {
providers[i] = (IBreakpointProvider) itr.next();
providers[i].setSourceEditingTextTools(tools);
i++;
}
return providers;
}
use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.
the class BreakpointProviderBuilder method getResource.
/**
* Returns corresponding resource from given parameters
*
* @param input
* @param handler
* @param ext
* @return IResource
*/
public IResource getResource(IEditorInput input, String contentType, String ext) {
IBreakpointProvider[] providers = getBreakpointProviders(null, contentType, ext);
IResource res = null;
for (int i = 0; i < providers.length; i++) {
res = providers[i].getResource(input);
if (res != null) {
break;
}
}
return res;
}
use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.
the class BreakpointProviderBuilder method createBreakpointProviders.
/*
* Creates an array of breakpoint providers matching the given key to the
* value of the IConfigurationElement attribute "attrName" @return
* IBreakpointProvider[]
*/
protected IBreakpointProvider[] createBreakpointProviders(String attrName, String key) {
if (cache == null)
return new IBreakpointProvider[0];
final int num = cache.size();
if (num == 0)
return new IBreakpointProvider[0];
IBreakpointProvider[] bp = new IBreakpointProvider[num];
int j = 0;
for (int i = 0; i < num; i++) {
Object obj = cache.get(i);
if (!(obj instanceof IConfigurationElement))
continue;
IConfigurationElement element = (IConfigurationElement) obj;
if (!TAG_PROVIDER.equals(element.getName()))
continue;
boolean doCreate = false;
String attrValues = element.getAttribute(attrName);
if (attrValues != null) {
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(attrValues, ",");
while (tokenizer.hasMoreTokens()) {
String type = tokenizer.nextToken();
if (type.trim().equalsIgnoreCase(key.trim())) {
doCreate = true;
break;
}
}
}
if (doCreate) {
IBreakpointProvider b = createBreakpointProvider(element);
if (b != null) {
bp[j] = b;
j++;
}
}
}
IBreakpointProvider[] bp2 = new IBreakpointProvider[j];
for (int i = 0; i < j; i++) {
bp2[i] = bp[i];
}
return bp2;
}
use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.
the class ToggleBreakpointAction method createBreakpoints.
protected boolean createBreakpoints(int lineNumber) {
/*
* Note: we'll always allow processing to continue, even for a "read
* only" IStorageEditorInput, for the ActiveScript debugger. But this
* means sometimes the ActiveScript provider might get an input from
* CVS or something that is not related to debugging.
*/
ITextEditor editor = getTextEditor();
IEditorInput input = editor.getEditorInput();
IDocument document = editor.getDocumentProvider().getDocument(input);
if (document == null)
return false;
String contentType = getContentType(document);
IBreakpointProvider[] providers = BreakpointProviderBuilder.getInstance().getBreakpointProviders(editor, contentType, getFileExtension(input));
int pos = -1;
ISourceEditingTextTools tools = editor.getAdapter(ISourceEditingTextTools.class);
if (tools != null) {
pos = tools.getCaretOffset();
}
final int n = providers.length;
List<IStatus> errors = new ArrayList<>(0);
for (int i = 0; i < n; i++) {
try {
if (Debug.debugBreakpoints)
// $NON-NLS-1$
System.out.println(providers[i].getClass().getName() + " adding breakpoint to line " + lineNumber);
IStatus status = providers[i].addBreakpoint(document, input, lineNumber, pos);
if (status != null && !status.isOK()) {
errors.add(status);
}
} catch (CoreException e) {
errors.add(e.getStatus());
} catch (Exception t) {
// $NON-NLS-1$
Logger.logException("exception while adding breakpoint", t);
}
}
IStatus status = null;
if (errors.size() > 0) {
Shell shell = editor.getSite().getShell();
if (errors.size() > 1) {
// $NON-NLS-1$
status = new MultiStatus(SSEUIPlugin.ID, IStatus.OK, errors.toArray(new IStatus[0]), SSEUIMessages.ManageBreakpoints_error_adding_message1, null);
} else {
status = errors.get(0);
}
if ((status.getSeverity() > IStatus.INFO) || (Platform.inDebugMode() && !status.isOK())) {
Platform.getLog(SSEUIPlugin.getDefault().getBundle()).log(status);
}
/*
* Show for conditions more severe than INFO or when no
* breakpoints were created
*/
if (status.getSeverity() > IStatus.INFO && getBreakpoints(getMarkers()).length < 1) {
// $NON-NLS-1$ //$NON-NLS-2$
ErrorDialog.openError(shell, SSEUIMessages.ManageBreakpoints_error_adding_title1, status.getMessage(), status);
return false;
}
}
/*
* Although no errors were reported, no breakpoints exist on this line
* after having run the existing providers. Run the fallback action.
*/
if ((status == null || status.getSeverity() < IStatus.WARNING) && fFallbackAction != null && !hasMarkers()) {
if (fFallbackAction instanceof ISelectionListener) {
((ISelectionListener) fFallbackAction).selectionChanged(null, null);
}
fFallbackAction.run();
}
return true;
}
Aggregations