mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code streamlining.
This commit is contained in:
parent
cc7de08d92
commit
f744f34410
1 changed files with 15 additions and 24 deletions
|
@ -62,13 +62,10 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
|
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
|
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
|
||||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
|
||||||
import org.eclipse.cdt.internal.formatter.CCodeFormatter;
|
import org.eclipse.cdt.internal.formatter.CCodeFormatter;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.Assert;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.Document;
|
import org.eclipse.jface.text.Document;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
@ -558,35 +555,29 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAppends(IASTTranslationUnit tu) {
|
private void handleAppends(IASTTranslationUnit tu) {
|
||||||
|
List<ASTModification> modifications = getModifications(tu, ModificationKind.APPEND_CHILD);
|
||||||
|
if (modifications.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
ASTWriter synthWriter = new ASTWriter();
|
ASTWriter synthWriter = new ASTWriter();
|
||||||
synthWriter.setModificationStore(modificationStore);
|
synthWriter.setModificationStore(modificationStore);
|
||||||
|
|
||||||
for (ASTModification modification : getModifications(tu, ModificationKind.APPEND_CHILD)) {
|
IASTFileLocation targetLocation = tu.getFileLocation();
|
||||||
IASTNode targetNode = modification.getTargetNode();
|
IFile file = FileHelper.getFileFromNode(tu);
|
||||||
IASTFileLocation targetLocation = targetNode.getFileLocation();
|
MultiTextEdit parentEdit = getEdit(tu, file);
|
||||||
String currentFile = targetLocation.getFileName();
|
|
||||||
IPath implPath = new Path(currentFile);
|
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||||
IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null);
|
|
||||||
if (relevantFile == null || !relevantFile.exists()) { // If not in workspace or local file system
|
for (ASTModification modification : modifications) {
|
||||||
throw new UnhandledASTModificationException(modification);
|
|
||||||
}
|
|
||||||
MultiTextEdit edit;
|
|
||||||
if (changes.containsKey(relevantFile)) {
|
|
||||||
edit = changes.get(relevantFile);
|
|
||||||
} else {
|
|
||||||
edit = new MultiTextEdit();
|
|
||||||
changes.put(relevantFile, edit);
|
|
||||||
}
|
|
||||||
String code = synthWriter.write(modification.getNewNode(), commentMap);
|
String code = synthWriter.write(modification.getNewNode(), commentMap);
|
||||||
|
|
||||||
if (targetNode instanceof IASTTranslationUnit &&
|
if (declarations.length > 0) {
|
||||||
((IASTTranslationUnit) targetNode).getDeclarations().length > 0) {
|
IASTDeclaration lastDecl = declarations[declarations.length - 1];
|
||||||
IASTTranslationUnit targetTu = (IASTTranslationUnit) targetNode;
|
|
||||||
IASTDeclaration lastDecl = targetTu.getDeclarations()[targetTu.getDeclarations().length - 1];
|
|
||||||
targetLocation = lastDecl.getFileLocation();
|
targetLocation = lastDecl.getFileLocation();
|
||||||
}
|
}
|
||||||
String lineDelimiter = FileHelper.determineLineDelimiter(tu.getRawSignature());
|
String lineDelimiter = FileHelper.determineLineDelimiter(tu.getRawSignature());
|
||||||
edit.addChild(new InsertEdit(endOffset(targetLocation), lineDelimiter + lineDelimiter + code));
|
parentEdit.addChild(new InsertEdit(endOffset(targetLocation),
|
||||||
|
lineDelimiter + lineDelimiter + code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue