From c5947d1de0b7ecd962d9ad44510b970377d5ef8a Mon Sep 17 00:00:00 2001 From: batxo Date: Mon, 27 Dec 2010 01:16:11 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B8=E3=83=A3=E3=83=B3=E3=83=97=E6=A9=9F?= =?utf8?q?=E8=83=BD=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- plugin.xml | 20 +++- src/coboled/editors/command/JumpHandler.java | 142 +++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 src/coboled/editors/command/JumpHandler.java diff --git a/plugin.xml b/plugin.xml index d119feb..ffc51df 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,14 +21,24 @@ + id="coboled.editors.command.quickoutline"> + + + + @@ -44,9 +54,13 @@ + + = 0) { + c = doc.getChar(pos); + if (!Character.isJavaIdentifierPart(c)) + break; + --pos; + } + + startPos = pos; + + pos = caretPos; + int length = doc.getLength(); + + while (pos < length) { + c = doc.getChar(pos); + if (!Character.isJavaIdentifierPart(c)) + break; + ++pos; + } + + endPos = pos; + int offset = startPos + 1; + int wordLength = endPos - offset; + return doc.get(offset, wordLength); + + } catch (BadLocationException e) { + } + return ""; + } + + private IDocument getDocument(CobolEditor editor) { + IDocumentProvider provider = editor.getDocumentProvider(); + IDocument doc = provider.getDocument(editor.getEditorInput()); + return doc; + } + + private int getCaretPos(CobolEditor editor) { + ISelectionProvider selectionProvider = editor.getSelectionProvider(); + ITextSelection selection = (ITextSelection) selectionProvider.getSelection(); + int caretPos = selection.getOffset(); + return caretPos; + } + + private int findDefinition(String source, String selection) { + int offset = findSectionDefinition(source, selection); + if(offset == -1) { + offset = findDataDefinition(source, selection); + } + return offset; + } + + private int findSectionDefinition(String source, String selection) { + StringBuilder patternString = new StringBuilder(); + patternString.append("^.{6} ( {0,3})"); + patternString.append("("); + patternString.append(selection); + patternString.append(")"); + patternString.append("( +?SECTION)"); + return find(source, patternString.toString(), 2); + } + + private int findDataDefinition(String source, String selection) { + StringBuilder patternString = new StringBuilder(); + patternString.append("^.{6} ( *?)([0-9][0-9])( +?)"); + patternString.append("("); + patternString.append(selection); + patternString.append(")"); + return find(source, patternString.toString(), 4); + } + + /** + * オフセットを返却する。検索結果が0の場合は-1を返却する。 + * + * @param source + * @param patternString + * @return offset + */ + private int find(String source, String patternString, int group) { + Pattern pattern = Pattern.compile(patternString, Pattern.MULTILINE); + Matcher matcher = pattern.matcher(source); + if(matcher.find()) { + return matcher.start(group); + } + return -1; + } +} -- 2.11.0