X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaIndenter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaIndenter.java index fa4715c..d3fb1b8 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaIndenter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaIndenter.java @@ -19,6 +19,8 @@ import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.TextUtilities; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; /** @@ -168,7 +170,8 @@ public class JavaIndenter { return null; // add additional indent - indent.append(createIndent(fIndent)); + //indent.append(createIndent(fIndent)); + indent.insert(0, createIndent(fIndent)); if (fIndent < 0) unindent(indent); @@ -407,6 +410,15 @@ public class JavaIndenter { prevPos + 1 - lineOffset).trim().length() == 0; int prevToken = fScanner.previousToken(prevPos, JavaHeuristicScanner.UNBOUND); + if (prevToken == Symbols.TokenEOF && nextToken == Symbols.TokenEOF) { + ITypedRegion partition = TextUtilities.getPartition(fDocument, IPHPPartitions.PHP_PARTITIONING, offset, true); + if (partition.getType().equals(IPHPPartitions.PHP_SINGLELINE_COMMENT)) { + fAlign = fScanner.getPosition(); + } else { + fAlign = JavaHeuristicScanner.NOT_FOUND; + } + return JavaHeuristicScanner.NOT_FOUND; + } boolean bracelessBlockStart = fScanner.isBracelessBlockStart( prevPos, JavaHeuristicScanner.UNBOUND); @@ -505,31 +517,34 @@ public class JavaIndenter { // align braces, but handle the case where we align with the method // declaration start instead of // the opening brace. - // if (matchBrace) { - // if (skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE)) { - // try { - // // align with the opening brace that is on a line by its own - // int lineOffset= fDocument.getLineOffset(fLine); - // if (lineOffset <= fPosition && fDocument.get(lineOffset, fPosition - - // lineOffset).trim().length() == 0) - // return fPosition; - // } catch (BadLocationException e) { - // // concurrent modification - walk default path - // } - // // if the opening brace is not on the start of the line, skip to the - // start - // int pos= skipToStatementStart(true, true); - // fIndent= 0; // indent is aligned with reference position - // return pos; - // } else { - // // if we can't find the matching brace, the heuristic is to unindent - // // by one against the normal position - // int pos= findReferencePosition(offset, danglingElse, false, - // matchParen, matchCase); - // fIndent--; - // return pos; - // } - // } + if (matchBrace) { + if (skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE)) { + try { + // align with the opening brace that is on a line by its own + int lineOffset = fDocument.getLineOffset(fLine); + if (lineOffset <= fPosition + && fDocument + .get(lineOffset, fPosition - lineOffset) + .trim().length() == 0) + return fPosition; + } catch (BadLocationException e) { + // concurrent modification - walk default path + } + // if the opening brace is not on the start of the line, skip to + // the start + int pos = skipToStatementStart(true, true); + fIndent = 0; // indent is aligned with reference position + return pos; + } else { + // if we can't find the matching brace, the heuristic is to + // unindent + // by one against the normal position + int pos = findReferencePosition(offset, danglingElse, false, + matchParen, matchCase); + fIndent--; + return pos; + } + } // align parenthesis' if (matchParen) { @@ -549,9 +564,9 @@ public class JavaIndenter { // the only reliable way to get case labels aligned (due to many // different styles of using braces in a block) // is to go for another case statement, or the scope opening brace - // if (matchCase) { - // return matchCaseAlignment(); - // } + if (matchCase) { + return matchCaseAlignment(); + } nextToken(); switch (fToken) { @@ -787,41 +802,40 @@ public class JavaIndenter { * * @return the reference offset for a switch label */ - // private int matchCaseAlignment() { - // while (true) { - // nextToken(); - // switch (fToken) { - // // invalid cases: another case label or an LBRACE must come before a case - // // -> bail out with the current position - // case Symbols.TokenLPAREN: - // case Symbols.TokenLBRACKET: - // case Symbols.TokenEOF: - // return fPosition; - // case Symbols.TokenLBRACE: - // // opening brace of switch statement - // fIndent= prefCaseIndent(); - // return fPosition; - // case Symbols.TokenCASE: - // case Symbols.TokenDEFAULT: - // // align with previous label - // fIndent= 0; - // return fPosition; - // - // // scopes: skip them - // case Symbols.TokenRPAREN: - // case Symbols.TokenRBRACKET: - // case Symbols.TokenRBRACE: - // skipScope(); - // break; - // - // default: - // // keep searching - // continue; - // - // } - // } - // } - /** + private int matchCaseAlignment() { + while (true) { + nextToken(); + switch (fToken) { + // invalid cases: another case label or an LBRACE must come before a + // case + // -> bail out with the current position + case Symbols.TokenLPAREN: + case Symbols.TokenLBRACKET: + case Symbols.TokenEOF: + return fPosition; + case Symbols.TokenLBRACE: + // opening brace of switch statement + fIndent = 1; //prefCaseIndent() is for Java + return fPosition; + case Symbols.TokenCASE: + case Symbols.TokenDEFAULT: + // align with previous label + fIndent = 0; + return fPosition; + // scopes: skip them + case Symbols.TokenRPAREN: + case Symbols.TokenRBRACKET: + case Symbols.TokenRBRACE: + skipScope(); + break; + default: + // keep searching + continue; + } + } + } + + /** * Returns the reference position for a list element. The algorithm tries to * match any previous indentation on the same list. If there is none, the * reference position returned is determined depending on the type of list: @@ -873,14 +887,17 @@ public class JavaIndenter { case Symbols.TokenQUESTIONMARK: if (prefTernaryDeepAlign()) { setFirstElementAlignment(fPosition - 1, fPosition + 1); - return fPosition; } else { fIndent = prefTernaryIndent(); - return fPosition; } + return fPosition; case Symbols.TokenEOF: return 0; + case Symbols.TokenEQUAL: + // indent assignments + fIndent= prefAssignmentIndent(); + return fPosition; } } }