1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 07:15:39 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2010-08-21 20:26:23 +00:00
parent f7e376cfc7
commit 5faa4da90e

View file

@ -65,11 +65,11 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
*/ */
public void customizeDocumentCommand(IDocument doc, DocumentCommand cmd) { public void customizeDocumentCommand(IDocument doc, DocumentCommand cmd) {
fgDefaultLineDelim = TextUtilities.getDefaultLineDelimiter(doc); fgDefaultLineDelim = TextUtilities.getDefaultLineDelimiter(doc);
if(doc instanceof IDocumentExtension4) { if (doc instanceof IDocumentExtension4) {
boolean forNewLine= cmd.length == 0 && cmd.text != null && endsWithDelimiter(doc, cmd.text); boolean forNewLine= cmd.length == 0 && cmd.text != null && endsWithDelimiter(doc, cmd.text);
boolean forCommentEnd= "/".equals(cmd.text); //$NON-NLS-1$ boolean forCommentEnd= "/".equals(cmd.text); //$NON-NLS-1$
if(forNewLine || forCommentEnd) { if (forNewLine || forCommentEnd) {
IDocumentExtension4 ext4= (IDocumentExtension4) doc; IDocumentExtension4 ext4= (IDocumentExtension4) doc;
DocumentRewriteSession drs= ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL); DocumentRewriteSession drs= ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
try { try {
@ -140,7 +140,7 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
c.shiftsCaret= false; c.shiftsCaret= false;
c.caretOffset= c.offset + buf.length(); c.caretOffset= c.offset + buf.length();
if(commentAtStart && shouldCloseMultiline(doc, c.offset)) { if (commentAtStart && shouldCloseMultiline(doc, c.offset)) {
try { try {
doc.replace(c.offset, 0, indentation+" "+MULTILINE_END); // close the comment in order to parse //$NON-NLS-1$ doc.replace(c.offset, 0, indentation+" "+MULTILINE_END); // close the comment in order to parse //$NON-NLS-1$
buf.append(lineDelim); buf.append(lineDelim);
@ -149,18 +149,18 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
IASTDeclaration dec= null; IASTDeclaration dec= null;
IASTTranslationUnit ast= getAST(); IASTTranslationUnit ast= getAST();
if(ast != null) { if (ast != null) {
dec= findFollowingDeclaration(ast, offset); dec= findFollowingDeclaration(ast, offset);
if(dec == null) { if (dec == null) {
IASTNodeSelector ans= ast.getNodeSelector(ast.getFilePath()); IASTNodeSelector ans= ast.getNodeSelector(ast.getFilePath());
IASTNode node= ans.findEnclosingNode(offset, 0); IASTNode node= ans.findEnclosingNode(offset, 0);
if(node instanceof IASTDeclaration) { if (node instanceof IASTDeclaration) {
dec= (IASTDeclaration) node; dec= (IASTDeclaration) node;
} }
} }
} }
if(dec!=null) { if (dec != null) {
ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false); ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false);
StringBuilder content= customizeAfterNewLineForDeclaration(doc, dec, partition); StringBuilder content= customizeAfterNewLineForDeclaration(doc, dec, partition);
buf.append(indent(content, indentation + MULTILINE_MID, lineDelim)); buf.append(indent(content, indentation + MULTILINE_MID, lineDelim));
@ -209,17 +209,17 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
@Override @Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
IASTNodeLocation loc= declaration.getFileLocation(); IASTNodeLocation loc= declaration.getFileLocation();
if(loc != null) { if (loc != null) {
int candidateOffset= loc.getNodeOffset(); int candidateOffset= loc.getNodeOffset();
int candidateEndOffset= candidateOffset+loc.getNodeLength(); int candidateEndOffset= candidateOffset+loc.getNodeLength();
if(offset <= candidateOffset) { if (offset <= candidateOffset) {
dec[0]= declaration; dec[0]= declaration;
return PROCESS_ABORT; return PROCESS_ABORT;
} }
boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset); boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset);
if(candidateEnclosesOffset) { if (candidateEnclosesOffset) {
stopWhenLeaving= declaration; stopWhenLeaving= declaration;
} }
} }
@ -227,33 +227,33 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
} }
@Override @Override
public int leave(IASTDeclaration declaration) { public int leave(IASTDeclaration declaration) {
if(declaration==stopWhenLeaving) if (declaration == stopWhenLeaving)
return PROCESS_ABORT; return PROCESS_ABORT;
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
}; };
if(unit!=null) { if (unit != null) {
unit.accept(av); unit.accept(av);
} }
return dec[0]; return dec[0];
} }
/** /**
* @return the AST unit for the active editor, or null if there is no active editor, or * @return the AST unit for the active editor, or <code>null</code> if there is no active editor, or
* the AST could not be obtained. * the AST could not be obtained.
*/ */
public IASTTranslationUnit getAST() { public IASTTranslationUnit getAST() {
final ITranslationUnit unit= getTranslationUnit(); final ITranslationUnit unit= getTranslationUnit();
try { try {
if(unit!=null) { if (unit != null) {
IASTTranslationUnit ast= unit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS); IASTTranslationUnit ast= unit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
return ast; return ast;
} }
} catch(CModelException ce) { } catch (CModelException e) {
CUIPlugin.log(ce); CUIPlugin.log(e);
} catch(CoreException ce) { } catch (CoreException e) {
CUIPlugin.log(ce); CUIPlugin.log(e);
} }
return null; return null;
} }
@ -333,7 +333,7 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
StringBuilder result= new StringBuilder(); StringBuilder result= new StringBuilder();
BufferedReader br= new BufferedReader(new StringReader(buffer.toString())); BufferedReader br= new BufferedReader(new StringReader(buffer.toString()));
try { try {
for(String line= br.readLine(); line!=null; line= br.readLine()) { for(String line= br.readLine(); line != null; line= br.readLine()) {
result.append(indent).append(line).append(lineDelim); result.append(indent).append(line).append(lineDelim);
} }
} catch(IOException ioe) { } catch(IOException ioe) {