for long lines macro generate Error - Array index out of range: 3
Submitted by Monday, 18 October, 2004 - 17:10
on
Why this macro generate Error?
__________________________________________________________
I write this macro:
// Delete 3 chars at start of line for all except first line
// delete lines longer then 930 characters
textArea.goToBufferStart(false);
textArea.goToNextLine(false);
int textAreagetLineCount=textArea.getLineCount();
java.lang.String pos ="";
for(int j = 0; j < textAreagetLineCount; ++j)
{
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.deleteToStartOfLine();
textArea.goToStartOfLine(false);
if(textArea.getLineLength(j) >= 930)
{
textArea.deleteLine();
}
textArea.goToNextLine(false);
textArea.goToStartOfLine(false);
}
buffer.save(view,null,true);
jEdit.closeBuffer(view,buffer);
__________________________________________________________
and example of file:
----Begin of file---
title
g line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line
g line long line long line long line
---End of file---
__________________________________________________________
produce this error:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
at org.gjt.sp.jedit.Buffer.getLineEndOffset(Buffer.java:935)
at org.gjt.sp.jedit.Buffer.getLineLength(Buffer.java:958)
at org.gjt.sp.jedit.textarea.JEditTextArea.getLineLength(JEditTextArea.java:1280)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at bsh.Reflect.invokeOnMethod(Reflect.java:149)
at bsh.Reflect.invokeObjectMethod(Reflect.java:81)
at bsh.Name.invokeMethod(Name.java:856)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:72)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.BSHBinaryExpression.eval(BSHBinaryExpression.java:52)
at bsh.BSHIfStatement.evaluateCondition(BSHIfStatement.java:63)
at bsh.BSHIfStatement.eval(BSHIfStatement.java:46)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BSHBlock.eval(BSHBlock.java:46)
at bsh.BSHForStatement.eval(BSHForStatement.java:111)
at bsh.Interpreter.eval(Interpreter.java:641)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:355)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:284)
at org.gjt.sp.jedit.BeanShell.runScript(BeanShell.java:210)
at org.gjt.sp.jedit.Macros$BeanShellHandler.runMacro(Macros.java:990)
at org.gjt.sp.jedit.Macros$Macro.invoke(Macros.java:417)
at org.gjt.sp.jedit.gui.InputHandler.invokeAction(InputHandler.java:229)
at org.gjt.sp.jedit.jEdit$3.invokeAction(jEdit.java:2910)
at org.gjt.sp.jedit.EditAction$Wrapper.actionPerformed(EditAction.java:216)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MenuDragMouseHandler.menuDragMouseReleased(Unknown Source)
at javax.swing.JMenuItem.fireMenuDragMouseReleased(Unknown Source)
at javax.swing.JMenuItem.processMenuDragMouseEvent(Unknown Source)
at javax.swing.JMenuItem.processMouseEvent(Unknown Source)
at javax.swing.MenuSelectionManager.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicMenuUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
__________________________________________________________
I write this macro:
// Delete 3 chars at start of line for all except first line
// delete lines longer then 930 characters
textArea.goToBufferStart(false);
textArea.goToNextLine(false);
int textAreagetLineCount=textArea.getLineCount();
java.lang.String pos ="";
for(int j = 0; j < textAreagetLineCount; ++j)
{
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.deleteToStartOfLine();
textArea.goToStartOfLine(false);
if(textArea.getLineLength(j) >= 930)
{
textArea.deleteLine();
}
textArea.goToNextLine(false);
textArea.goToStartOfLine(false);
}
buffer.save(view,null,true);
jEdit.closeBuffer(view,buffer);
__________________________________________________________
and example of file:
----Begin of file---
title
g line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line
g line long line long line long line
---End of file---
__________________________________________________________
produce this error:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
at org.gjt.sp.jedit.Buffer.getLineEndOffset(Buffer.java:935)
at org.gjt.sp.jedit.Buffer.getLineLength(Buffer.java:958)
at org.gjt.sp.jedit.textarea.JEditTextArea.getLineLength(JEditTextArea.java:1280)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at bsh.Reflect.invokeOnMethod(Reflect.java:149)
at bsh.Reflect.invokeObjectMethod(Reflect.java:81)
at bsh.Name.invokeMethod(Name.java:856)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:72)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.BSHBinaryExpression.eval(BSHBinaryExpression.java:52)
at bsh.BSHIfStatement.evaluateCondition(BSHIfStatement.java:63)
at bsh.BSHIfStatement.eval(BSHIfStatement.java:46)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BSHBlock.eval(BSHBlock.java:46)
at bsh.BSHForStatement.eval(BSHForStatement.java:111)
at bsh.Interpreter.eval(Interpreter.java:641)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:355)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:284)
at org.gjt.sp.jedit.BeanShell.runScript(BeanShell.java:210)
at org.gjt.sp.jedit.Macros$BeanShellHandler.runMacro(Macros.java:990)
at org.gjt.sp.jedit.Macros$Macro.invoke(Macros.java:417)
at org.gjt.sp.jedit.gui.InputHandler.invokeAction(InputHandler.java:229)
at org.gjt.sp.jedit.jEdit$3.invokeAction(jEdit.java:2910)
at org.gjt.sp.jedit.EditAction$Wrapper.actionPerformed(EditAction.java:216)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MenuDragMouseHandler.menuDragMouseReleased(Unknown Source)
at javax.swing.JMenuItem.fireMenuDragMouseReleased(Unknown Source)
at javax.swing.JMenuItem.processMenuDragMouseEvent(Unknown Source)
at javax.swing.JMenuItem.processMouseEvent(Unknown Source)
at javax.swing.MenuSelectionManager.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicMenuUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)