Permalink
Browse files

- tabs fixed

  • Loading branch information...
maqdev committed Jul 16, 2011
1 parent 5843c43 commit a0040255398c96938896180453f4c2ffbddd3edf
@@ -25,7 +25,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*
*/
-
package org.carbonfx.valaproject;
import java.io.IOException;
@@ -25,7 +25,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*
*/
-
package org.carbonfx.valaproject;
import java.io.IOException;
@@ -25,7 +25,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*
*/
-
package org.carbonfx.valaproject.editor;
import org.carbonfx.valaproject.options.CodeStyle;
@@ -41,7 +40,7 @@
private Context context;
private CodeStyle codeStyle;
- public ValaIndentTask(Context context){
+ public ValaIndentTask(Context context) {
this.context = context;
this.codeStyle = CodeStyle.getCodeStyle(context.document());
@@ -51,17 +50,16 @@ public ValaIndentTask(Context context){
public void reindent() throws BadLocationException {
int caretOffset = context.caretOffset();
- int lineOffset = context.lineStartOffset(caretOffset);
+ int lineOffset = context.lineStartOffset(caretOffset);
- final BaseDocument doc = (BaseDocument)context.document();
+ final BaseDocument doc = (BaseDocument) context.document();
int lastNonWhite = Utilities.getFirstNonWhiteBwd(doc, lineOffset);
IndentMode mode = getMode(lineOffset, lastNonWhite, doc);
int currentIndent = getCurrentIndent(lastNonWhite, doc);
- switch (mode)
- {
+ switch (mode) {
case NEW_BLOCK:
indentNewBlock(lineOffset, currentIndent);
break;
@@ -79,15 +77,11 @@ public ExtraLock indentLock() {
private IndentMode getMode(int lineOffset, int lastNonWhite, BaseDocument doc) throws BadLocationException {
IndentMode mode = IndentMode.UNKNOWN;
- if (lastNonWhite >= 0 && lastNonWhite < lineOffset)
- {
- String s = doc.getText(lastNonWhite,1);
- if (s != null && s.equals("{"))
- {
+ if (lastNonWhite >= 0 && lastNonWhite < lineOffset) {
+ String s = doc.getText(lastNonWhite, 1);
+ if (s != null && s.equals("{")) {
mode = IndentMode.NEW_BLOCK;
- }
- else
- {
+ } else {
mode = IndentMode.SAME_LEVEL;
}
}
@@ -97,19 +91,16 @@ private IndentMode getMode(int lineOffset, int lastNonWhite, BaseDocument doc) t
private int getCurrentIndent(int lastNonWhite, BaseDocument doc) throws BadLocationException {
int prevLineStart = Utilities.getRowStart(doc, lastNonWhite);
int currentIndent = 0;
- if (prevLineStart >= 0)
- {
+ if (prevLineStart >= 0) {
int p = Utilities.getFirstNonWhiteFwd(doc, prevLineStart);
- if (p >= 0 && p >= prevLineStart && p <= lastNonWhite)
- {
+ if (p >= 0 && p >= prevLineStart && p <= lastNonWhite) {
String s = doc.getText(prevLineStart, p - prevLineStart);
-
+
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == '\t') {
currentIndent += codeStyle.getTabSize();
- }
- else {
- currentIndent ++;
+ } else {
+ currentIndent++;
}
}
}
@@ -118,7 +109,7 @@ private int getCurrentIndent(int lastNonWhite, BaseDocument doc) throws BadLocat
}
private void indentNewBlock(int lineOffset, int indent) throws BadLocationException {
- final BaseDocument doc = (BaseDocument)context.document();
+ final BaseDocument doc = (BaseDocument) context.document();
int countLCurl = getCurlCount(false, lineOffset, doc);
int countRCurl = getCurlCount(true, lineOffset, doc);
@@ -138,7 +129,7 @@ private void indentNewBlock(int lineOffset, int indent) throws BadLocationExcept
}
private void indentSameLevel(int lineOffset, int indent) throws BadLocationException {
- final BaseDocument doc = (BaseDocument)context.document();
+ final BaseDocument doc = (BaseDocument) context.document();
String s = getIndentString(indent);
int newCaretPos = lineOffset + s.length();
doc.insertString(lineOffset, s, null);
@@ -157,8 +148,7 @@ private int getCurlCount(boolean forward, int offset, BaseDocument doc) throws B
from = offset;
to = doc.getLength();
incval = 1;
- }
- else {
+ } else {
fwchar = '{';
bwchar = '}';
from = offset;
@@ -186,17 +176,15 @@ private int getCurlCount(boolean forward, int offset, BaseDocument doc) throws B
if (c == '"') {
if (mode == 0) {
mode = 2;
- }
- else if (mode == 2) {
+ } else if (mode == 2) {
mode = 0;
}
}
if (c == '\'') {
if (mode == 0) {
mode = 1;
- }
- else if (mode == 1) {
+ } else if (mode == 1) {
mode = 0;
}
}
@@ -205,17 +193,16 @@ else if (mode == 1) {
}
private String getIndentString(int indent) {
-
- StringBuilder sb = new StringBuilder(indent+2);
+
+ StringBuilder sb = new StringBuilder(indent + 2);
if (codeStyle.getExpandTabToSpaces()) {
for (int i = 0; i < indent; ++i) {
sb.append(' ');
}
- }
- else {
+ } else {
int tabCount = indent / codeStyle.getTabSize();
int spaceCount = indent % codeStyle.getTabSize();
@@ -232,8 +219,8 @@ private String getIndentString(int indent) {
return sb.toString();
}
- private enum IndentMode
- {
+ private enum IndentMode {
+
UNKNOWN,
NEW_BLOCK,
SAME_LEVEL
@@ -25,18 +25,15 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*
*/
-
package org.carbonfx.valaproject.editor;
import org.netbeans.modules.editor.indent.spi.Context;
import org.netbeans.modules.editor.indent.spi.IndentTask;
-public class ValaIndentTaskFactory implements IndentTask.Factory
-{
+public class ValaIndentTaskFactory implements IndentTask.Factory {
@Override
public IndentTask createTask(Context cntxt) {
return new ValaIndentTask(cntxt);
}
-
}
Oops, something went wrong.

0 comments on commit a004025

Please sign in to comment.