本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.reconcile方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.reconcile方法的具体用法?Java ICompilationUnit.reconcile怎么用?Java ICompilationUnit.reconcile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.reconcile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatUnitSourceCode
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* Format a Unit Source Code
*
* @param testInterface
* @param monitor
* @throws CoreException
*/
@SuppressWarnings("unchecked")
public static void formatUnitSourceCode(IFile file, IProgressMonitor monitor) throws CoreException {
@SuppressWarnings("rawtypes")
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
subMonitor.split(50);
ICompilationUnit workingCopy = unit.getWorkingCopy(monitor);
Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
DefaultCodeFormatterConstants.createAlignmentValue(true,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
ISourceRange range = unit.getSourceRange();
TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(),
range.getOffset(), range.getLength(), 0, null);
subMonitor.split(30);
if (formatEdit != null /* && formatEdit.hasChildren()*/) {
workingCopy.applyTextEdit(formatEdit, monitor);
workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
workingCopy.commitWorkingCopy(true, null);
workingCopy.discardWorkingCopy();
}
file.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
subMonitor.split(20);
}
示例2: updatePathGenerator
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static void updatePathGenerator (IFile ifile, String oldPathGenerator,String newPathGenerator) throws CoreException {
ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
ICompilationUnit workingCopy = cu.getWorkingCopy(new NullProgressMonitor());
IBuffer buffer = ((IOpenable)workingCopy).getBuffer();
String source = buffer.getContents();
int start = source.indexOf(oldPathGenerator);
buffer.replace(start, oldPathGenerator.length(), newPathGenerator);
workingCopy.reconcile(ICompilationUnit.NO_AST, false, workingCopy.getOwner(), new NullProgressMonitor());
workingCopy.commitWorkingCopy(true, null);
workingCopy.discardWorkingCopy();
ifile.touch(new NullProgressMonitor ());
}
示例3: performValidation
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private IStatus performValidation(IProgressMonitor monitor) throws JavaModelException {
long start = System.currentTimeMillis();
List<ICompilationUnit> cusToReconcile = new ArrayList<>();
synchronized (toReconcile) {
cusToReconcile.addAll(toReconcile);
toReconcile.clear();
}
if (cusToReconcile.isEmpty()) {
return Status.OK_STATUS;
}
// first reconcile all units with content changes
SubMonitor progress = SubMonitor.convert(monitor, cusToReconcile.size() + 1);
for (ICompilationUnit cu : cusToReconcile) {
cu.reconcile(ICompilationUnit.NO_AST, true, null, progress.newChild(1));
}
this.sharedASTProvider.invalidateAll();
List<ICompilationUnit> toValidate = Arrays.asList(JavaCore.getWorkingCopies(null));
List<CompilationUnit> astRoots = this.sharedASTProvider.getASTs(toValidate, monitor);
for (CompilationUnit astRoot : astRoots) {
// report errors, even if there are no problems in the file: The client need to know that they got fixed.
ICompilationUnit unit = (ICompilationUnit) astRoot.getTypeRoot();
DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit);
handler.beginReporting();
for (IProblem problem : astRoot.getProblems()) {
handler.acceptProblem(problem);
}
handler.endReporting();
}
JavaLanguageServerPlugin.logInfo("Reconciled " + toReconcile.size() + ", validated: " + toValidate.size() + ". Took " + (System.currentTimeMillis() - start) + " ms");
return Status.OK_STATUS;
}
示例4: addGeneratedAnnotation
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* @param file
* @param info
* @param monitor
* @throws MalformedTreeException
* @throws BadLocationException
* @throws CoreException
*/
@SuppressWarnings("deprecation")
public static void addGeneratedAnnotation(IFile file, IFile graphFile, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException, CoreException {
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
try {
String source = compilationUnit.getSource();
Document document = new Document(source);
compilationUnit.becomeWorkingCopy(new SubProgressMonitor(monitor, 1));
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(compilationUnit);
parser.setResolveBindings(true);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1));
astRoot.recordModifications();
final ImportRewrite importRewrite = ImportRewrite.create(astRoot, true);
importRewrite.addImport("javax.annotation.Generated");
astRoot.accept(new ASTVisitor() {
@SuppressWarnings("unchecked")
@Override
public boolean visit(TypeDeclaration node) {
ASTNode copiedNode = null;
// Add Generated annotation
ClassExtension ce;
try {
ce = new ClassExtension(false, false, false, false, false, false, "", "", null, false, false,
"", "", "", graphFile);
NormalAnnotation annotation = ce.getGeneratedClassAnnotation();
if (annotation != null) {
copiedNode = ASTNode.copySubtree(node.getAST(), annotation);
node.modifiers().add(0, copiedNode);
}
} catch (JavaModelException e) {
ResourceManager.logException(e);
}
return super.visit(node);
}
});
TextEdit rewrite = astRoot.rewrite(document, compilationUnit.getJavaProject().getOptions(true));
rewrite.apply(document);
TextEdit rewriteImports = importRewrite.rewriteImports(new SubProgressMonitor(monitor, 1));
rewriteImports.apply(document);
String newSource = document.get();
compilationUnit.getBuffer().setContents(newSource);
compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, new SubProgressMonitor(monitor, 1));
compilationUnit.commitWorkingCopy(false, new SubProgressMonitor(monitor, 1));
} finally {
compilationUnit.discardWorkingCopy();
monitor.done();
}
// WorkbenchFacade.JDTManager.reorganizeImport(compilationUnit);
}