From: Stephan R. <ste...@us...> - 2005-01-08 14:36:57
|
Update of /cvsroot/e-p-i-c/org.epic.debug/src/org/epic/debug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24359/src/org/epic/debug Modified Files: PerlDB.java PerlRegExpBreakpoint.java Added Files: RegExpBPSettingsDalog.java ManageRegExpBreakpointRulerPropertyActionDelegate.java ManageRegExpBreakpointRulerPropertyAction.java Log Message: Property settings RegExpBreakpoints --- NEW FILE: ManageRegExpBreakpointRulerPropertyAction.java --- /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Common Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/cpl-v10.html * * Contributors: IBM Corporation - initial API and implementation ******************************************************************************/ package org.epic.debug; import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.jface.action.Action; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.IUpdate; public class ManageRegExpBreakpointRulerPropertyAction extends Action implements IUpdate { protected IVerticalRulerInfo fRuler; protected ITextEditor fTextEditor; private String fMarkerType; protected List fMarkers; public ManageRegExpBreakpointRulerPropertyAction(IVerticalRulerInfo ruler, ITextEditor editor) { fRuler = ruler; fTextEditor = editor; fMarkerType = IBreakpoint.BREAKPOINT_MARKER; } /** * Returns the resource for which to create the marker, or <code>null</code> * if there is no applicable resource. * * @return the resource for which to create the marker or <code>null</code> */ protected IResource getResource() { IEditorInput input = fTextEditor.getEditorInput(); IResource resource = (IResource) input.getAdapter(IFile.class); if (resource == null) { resource = (IResource) input.getAdapter(IResource.class); } return resource; } /** * Checks whether a position includes the ruler's line of activity. * * @param position * the position to be checked * @param document * the document the position refers to * @return <code>true</code> if the line is included by the given position */ protected boolean includesRulerLine(Position position, IDocument document) { if (position != null) { try { int markerLine = document.getLineOfOffset(position.getOffset()); int line = fRuler.getLineOfLastMouseButtonActivity(); if (line == markerLine) { return true; } } catch (BadLocationException x) { } } return false; } /** * Returns this action's vertical ruler info. * * @return this action's vertical ruler */ protected IVerticalRulerInfo getVerticalRulerInfo() { return fRuler; } /** * Returns this action's editor. * * @return this action's editor */ protected ITextEditor getTextEditor() { return fTextEditor; } /** * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's * input. * * @return the marker annotation model */ protected AbstractMarkerAnnotationModel getAnnotationModel() { IDocumentProvider provider = fTextEditor.getDocumentProvider(); IAnnotationModel model = provider.getAnnotationModel(fTextEditor .getEditorInput()); if (model instanceof AbstractMarkerAnnotationModel) { return (AbstractMarkerAnnotationModel) model; } return null; } /** * Returns the <code>IDocument</code> of the editor's input. * * @return the document of the editor's input */ protected IDocument getDocument() { IDocumentProvider provider = fTextEditor.getDocumentProvider(); return provider.getDocument(fTextEditor.getEditorInput()); } /** * @see IUpdate#update() */ public void update() { setEnabled(getMarker() != null); } /** * @see Action#run() */ public void run() { Shell shell = getTextEditor().getEditorSite().getShell(); RegExpBPSettingsDalog dialog = new RegExpBPSettingsDalog(shell, ((PerlRegExpBreakpoint)getBP(getMarker()))); dialog.open(); } protected IMarker getMarker() { IResource resource = getResource(); IDocument document = getDocument(); AbstractMarkerAnnotationModel model = getAnnotationModel(); if (model != null) { try { IMarker[] markers = null; if (resource instanceof IFile) markers = resource.findMarkers( IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); else { IWorkspaceRoot root = ResourcesPlugin.getWorkspace() .getRoot(); markers = root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); } if (markers != null) { IBreakpointManager breakpointManager = DebugPlugin .getDefault().getBreakpointManager(); for (int i = 0; i < markers.length; i++) { IBreakpoint breakpoint = breakpointManager .getBreakpoint(markers[i]); if (breakpoint != null && breakpointManager.isRegistered(breakpoint) && includesRulerLine(model .getMarkerPosition(markers[i]), document) && breakpoint instanceof PerlRegExpBreakpoint) return (markers[i]); } } } catch (CoreException x) { DebugPlugin.log(x.getStatus()); } } return null; } protected void addMarker() { IEditorInput editorInput = getTextEditor().getEditorInput(); IDocument document = getDocument(); int rulerLine = getVerticalRulerInfo() .getLineOfLastMouseButtonActivity(); try { int line = getVerticalRulerInfo() .getLineOfLastMouseButtonActivity(); createBreakPoint(line + 1); } catch (Exception e) { PerlDebugPlugin.getDefault().logError( "ManageBreakpointRulerAction error adding Breakpoint", e); //$NON-NLS-1$ } } void createBreakPoint(int fLine) throws DebugException, CoreException { new PerlLineBreakpoint(getResource(), fLine); } protected IBreakpoint getBP(IMarker marker) { IBreakpointManager breakpointManager = DebugPlugin.getDefault() .getBreakpointManager(); return( breakpointManager.getBreakpoint(marker) ); } protected void removeMarkers(List markers) { IBreakpointManager breakpointManager = DebugPlugin.getDefault() .getBreakpointManager(); try { Iterator e = markers.iterator(); while (e.hasNext()) { IBreakpoint breakpoint = breakpointManager .getBreakpoint((IMarker) e.next()); breakpointManager.removeBreakpoint(breakpoint, true); } } catch (CoreException e) { PerlDebugPlugin.getDefault().logError( "ManageBreakpointRulerAction.error.removing.message1", e); //$NON-NLS-1$ } } } --- NEW FILE: RegExpBPSettingsDalog.java --- /* * Created on 07.01.2005 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package org.epic.debug; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * @author ST * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class RegExpBPSettingsDalog extends Dialog { PerlRegExpBreakpoint mBP; private Label fSourceLabel; private Text fSourceText; private Text fRegExpText; private Text fMatchText; private String mTitle; /** * @param parentShell */ public RegExpBPSettingsDalog(Shell parentShell, PerlRegExpBreakpoint fBP) { super(parentShell); mBP = fBP; mTitle = "Regular Expression Breakpoint Properties"; // TODO Auto-generated constructor stub } public RegExpBPSettingsDalog(Shell parentShell, PerlRegExpBreakpoint fBP, String fTitle) { super(parentShell); mBP = fBP; mTitle = fTitle; // TODO Auto-generated constructor stub } protected Control createDialogArea(Composite parent) { String val; Composite comp = (Composite)super.createDialogArea(parent); GridLayout topLayout = new GridLayout(); comp.setLayout(topLayout); GridData gd; fSourceText = createLine(comp,"Source Line:",false,mBP.getSourceLine()); fRegExpText = createLine(comp,"Regular Expression:",true,mBP.getRegExp()); fMatchText = createLine(comp,"Term to Match:",true,mBP.getMatchText()); return(comp); } protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(mTitle); } Text createLine(Composite fComp,String fText, boolean fWrite, String fVal) { Composite comp = new Composite(fComp, SWT.NONE); GridLayout sourceLayout = new GridLayout(); sourceLayout.numColumns = 3; sourceLayout.marginHeight = 0; sourceLayout.marginWidth = 0; sourceLayout.makeColumnsEqualWidth = true; comp.setLayout(sourceLayout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); comp.setLayoutData(gd); fSourceLabel = new Label(comp, SWT.NONE); fSourceLabel.setText(fText); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; fSourceLabel.setLayoutData(gd); Text text = new Text(fComp, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; text.setLayoutData(gd); text.setEditable(fWrite); if( fVal != null ) text.setText(fVal); return text; } protected void okPressed() { mBP.setRegExp(fRegExpText.getText()); mBP.setMatchText(fMatchText.getText()); super.okPressed(); } } Index: PerlDB.java =================================================================== RCS file: /cvsroot/e-p-i-c/org.epic.debug/src/org/epic/debug/PerlDB.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- PerlDB.java 4 Jan 2005 15:40:55 -0000 1.35 +++ PerlDB.java 8 Jan 2005 14:36:47 -0000 1.36 @@ -139,8 +139,8 @@ private final static String mLineSeparator = System .getProperty("line.separator"); private org.epic.debug.util.PathMapper mPathMapper; - StringBuffer mRegExp = new StringBuffer(); - StringBuffer mText = new StringBuffer(); + String mRegExp ; + String mText; private String mPerlVersion; private class CommandThread extends Thread { @@ -899,10 +899,11 @@ if (bp != null) { if (bp instanceof PerlRegExpBreakpoint) { - mRegExp = new StringBuffer(); - mText = new StringBuffer(); + ((PerlRegExpBreakpoint)(bp)).calculateRegExp(); + mRegExp = ((PerlRegExpBreakpoint)(bp)).getRegExp(); + mText = ((PerlRegExpBreakpoint)(bp)).getMatchText(); - this.getRegExp(pos, mRegExp, mText); + // show view Shell shell = PerlDebugPlugin.getActiveWorkbenchShell(); if (shell != null) { @@ -918,8 +919,8 @@ // TODO Auto-generated catch block e.printStackTrace(); } - view.setRegExpText(mRegExp.toString()); - view.setMatchText(mText.toString()); + view.setRegExpText(mRegExp); + view.setMatchText(mText); } Index: PerlRegExpBreakpoint.java =================================================================== RCS file: /cvsroot/e-p-i-c/org.epic.debug/src/org/epic/debug/PerlRegExpBreakpoint.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- PerlRegExpBreakpoint.java 5 Jun 2004 14:07:56 -0000 1.1 +++ PerlRegExpBreakpoint.java 8 Jan 2005 14:36:47 -0000 1.2 @@ -6,46 +6,222 @@ */ package org.epic.debug; +import gnu.regexp.RE; +import gnu.regexp.REException; +import gnu.regexp.REMatch; +import gnu.regexp.RESyntax; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.util.Map; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; - +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.epic.regexp.views.RegExpView; /** * @author ruehl - * + * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ +public class PerlRegExpBreakpoint extends PerlLineBreakpoint { -public class PerlRegExpBreakpoint extends PerlLineBreakpoint{ - private static final String Perl_REGEXP_BREAKPOINT = "org.epic.debug.perlRegExpBreakpointMarker"; //$NON-NLS-1$ - - + private static final String SOURCE_LINE = "EPIC_SOURCE_LINE"; + private static final String REG_EXP = "EPIC_REG_EXP"; + private static final String MATCH_TEXT = "EPIC_MATCH_TEXT"; + private IResource mResource; + private RegExpBPSettingsDalog dialog; + public PerlRegExpBreakpoint() { - super(); - - } - - public PerlRegExpBreakpoint(IResource resource, int lineNumber) throws DebugException, CoreException { - super(resource, lineNumber); - } + super(); + + } + + public PerlRegExpBreakpoint(IResource resource, int lineNumber) + throws DebugException, CoreException { + super(resource, lineNumber); + mResource = resource; + calculateRegExp(); + } + + public PerlRegExpBreakpoint(IResource resource, int lineNumber, + int charStart, int charEnd, boolean add, Map attributes) + throws DebugException, CoreException { + super(resource, lineNumber, charStart, charEnd, add, attributes); + mResource = resource; + calculateRegExp(); + } + + String getMarkerID() { + return (Perl_REGEXP_BREAKPOINT); + } + + public String getSourceLine() { + return (String) getAttribute(SOURCE_LINE); + } + + private Object getAttribute(String fID) { + try { + return (String) (getMarker().getAttribute(fID)); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + public String getRegExp() { + return (String) getAttribute(REG_EXP); + } + + public String getMatchText() { + return (String) getAttribute(MATCH_TEXT); + } + + private void setAttributeValue(String fID, Object fValue) { + try { + getMarker().setAttribute(fID, fValue); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setMatchText(String fText) { + setAttributeValue(MATCH_TEXT, fText); + } + + public void setRegExp(String fText) { + setAttributeValue(REG_EXP, fText); + } + + public void setSourceLine(String fText) { + setAttributeValue(SOURCE_LINE, fText); + } + + public boolean isStoredDataValid() { + return isStoredDataValid(getCurrentSourceLine()); + + } + + public boolean isStoredDataValid(String fCurrentSourceLine) { + String lineStored = getSourceLine(); + + return (fCurrentSourceLine != null && lineStored != null && fCurrentSourceLine + .equals(lineStored) && getRegExp()!= null && getMatchText() != null ); + + } +void calculateRegExp() { + + + String lineCurrent = getCurrentSourceLine(); + if( !isStoredDataValid(lineCurrent)) + { + extractRegExp(lineCurrent); + setSourceLine(lineCurrent); + Shell shell = PerlDebugPlugin.getActiveWorkbenchShell(); + dialog = new RegExpBPSettingsDalog(shell, this,"Could not extract Regular Expression..."); + if (shell != null) { + shell.getDisplay().syncExec(new Runnable() { + public void run() { + dialog.open(); + } + + }); + - - public PerlRegExpBreakpoint(IResource resource, int lineNumber, int charStart, int charEnd, boolean add, Map attributes) - throws DebugException,CoreException { - super(resource, lineNumber, charStart, charEnd, add, attributes); + } } - String getMarkerID() - { - return(Perl_REGEXP_BREAKPOINT); + + } + private boolean extractRegExp(String line) { + + try { + String delim; + + RE findDelim = new RE("[$%@].+[\\s]*=~[\\s]*[m]?(.)", 0, + RESyntax.RE_SYNTAX_PERL5); + + REMatch match = findDelim.getMatch(line); + if (match == null) + return false; + delim = match.toString(1); + if (delim == null) + return false; + String temp = line; + temp.replaceAll("\\" + delim, "xx"); + RE findRegExp = new RE("([$%@][^\\s]+)[\\s]*=~[\\s]*[m]?" + delim + + "(.*)" + delim, 0, RESyntax.RE_SYNTAX_PERL5); + match = findRegExp.getMatch(temp); + String var = line.substring(match.getStartIndex(1), match + .getEndIndex(1)); + String text = line.substring(match.getStartIndex(2), match + .getEndIndex(2)); + + //System.out.println("\n" + var + ":" + text + "\n"); + setRegExp(text); + setMatchText(var); + } catch (REException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } + return (true); + } + private String getCurrentSourceLine() { - -} + StringBuffer sourceCode = new StringBuffer(); + + int BUF_SIZE = 1024; + + // Get the file content + char[] buf = new char[BUF_SIZE]; + File inputFile = new File(mResource.getLocation().toString()); + BufferedReader in; + try { + in = new BufferedReader(new FileReader(inputFile)); + + int read = 0; + while ((read = in.read(buf)) > 0) { + sourceCode.append(buf, 0, read); + } + in.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + String line = null; + Document doc = new Document(sourceCode.toString()); + try { + int length = doc.getLineLength(getLineNumber()-1); + int offset = doc.getLineOffset(getLineNumber()-1); + line = doc.get(offset, length); + } catch (BadLocationException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return null; + } + + return line.trim(); + } + +} \ No newline at end of file --- NEW FILE: ManageRegExpBreakpointRulerPropertyActionDelegate.java --- /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.epic.debug; import org.eclipse.jface.action.IAction; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.texteditor.AbstractRulerActionDelegate; import org.eclipse.ui.texteditor.ITextEditor; public class ManageRegExpBreakpointRulerPropertyActionDelegate extends AbstractRulerActionDelegate { /** * @see AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo) */ protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { return new ManageRegExpBreakpointRulerPropertyAction(rulerInfo, editor); } } |