use of org.eclipse.ltk.core.refactoring.RefactoringStatusEntry in project che by eclipse.
the class ChangeSignatureProcessor method checkCompilationofDeclaringCu.
private RefactoringStatus checkCompilationofDeclaringCu() throws CoreException {
ICompilationUnit cu = getCu();
TextChange change = fChangeManager.get(cu);
String newCuSource = change.getPreviewContent(new NullProgressMonitor());
CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, cu, true, false, null);
IProblem[] problems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fBaseCuRewrite.getRoot());
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < problems.length; i++) {
IProblem problem = problems[i];
if (shouldReport(problem, newCUNode))
result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusEntry in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method refreshName.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.IUIRefresher#refreshName()
*/
@Override
public void refreshName() {
ICompilationUnit unit = (ICompilationUnit) this.getInputJavaElement();
String newName = item.getProperty().getLabel();
try {
boolean noError = true;
// String newName2 = newName + SuffixConstants.SUFFIX_STRING_java;
//$NON-NLS-1$
String newName2 = newName + ".java";
if (item instanceof RoutineItem && !unit.getElementName().equals(newName2)) {
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
processor.setNewElementName(newName2);
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus != null && conditionStatus.hasError()) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String errorMessage = "Rename " + unit.getElementName() + " to " + newName + " has errors!";
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
//$NON-NLS-1$
MessageDialog.openError(this.getSite().getShell(), "Warning", errorMessage);
noError = false;
}
}
if (noError) {
doSave(null);
}
setName();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusEntry in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusEntry in project che by eclipse.
the class RenameAnalyzeUtil method analyzeCompileErrors.
private static RefactoringStatus analyzeCompileErrors(String newCuSource, CompilationUnit newCUNode, CompilationUnit oldCUNode) {
RefactoringStatus result = new RefactoringStatus();
IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, oldCUNode);
for (int i = 0; i < newProblems.length; i++) {
IProblem problem = newProblems[i];
if (problem.isError())
result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusEntry in project che by eclipse.
the class ExtractTempRefactoring method checkNewSource.
private void checkNewSource(SubProgressMonitor monitor, RefactoringStatus result) throws CoreException {
String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, fCu, true, true, monitor);
IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCompilationUnitNode);
for (int i = 0; i < newProblems.length; i++) {
IProblem problem = newProblems[i];
if (problem.isError())
result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
}
}
Aggregations