From: batxo Date: Sun, 26 Dec 2010 16:16:11 +0000 (+0900) Subject: ジャンプ機能を実装 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=HEAD;p=coboled%2FCobolEditor.git ジャンプ機能を実装 --- 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; + } +}