use of org.eclipse.xtend.core.javaconverter.JavaConverter.ConversionResult in project xtext-xtend by eclipse.
the class ConversionProblemsDialog method handleMemberSelect.
protected void handleMemberSelect(Widget item) {
Object data = null;
if (item != null)
data = item.getData();
if (data instanceof ICompilationUnit) {
this.currentCU = (ICompilationUnit) data;
problemsPane.setImage(CompareUI.getImage(this.currentCU.getResource()));
String pattern = "Problems in file {0}";
String title = MessageFormat.format(pattern, new Object[] { this.currentCU.getResource().getName() });
problemsPane.setText(title);
if (problemsTable != null) {
problemsTable.setRedraw(false);
problemsTable.removeAll();
ConversionResult conversionResult = input.get(currentCU);
for (String problem : conversionResult.getProblems()) {
addProblemItem(problem);
}
problemsTable.setRedraw(true);
}
} else
this.currentCU = null;
}
use of org.eclipse.xtend.core.javaconverter.JavaConverter.ConversionResult in project xtext-xtend by eclipse.
the class ConvertJavaCode method doConvert.
private void doConvert(final Set<ICompilationUnit> compilationUnits, IProgressMonitor monitor, Map<ICompilationUnit, ConversionResult> conversionResults) throws ExecutionException, InterruptedException {
for (ICompilationUnit iCompilationUnit : compilationUnits) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
JavaConverter converter = converterProvider.get();
ConversionResult conversionResult = converter.toXtend(iCompilationUnit);
monitor.subTask("Working with " + iCompilationUnit.getElementName());
if (!conversionResult.getProblems().iterator().hasNext()) {
IFile file = xtendFileToCreate(iCompilationUnit);
Resource resource = createResource(file, conversionResult.getXtendCode());
if (!validateResource(resource)) {
monitor.subTask("Conversion was not successfull. Re-trying with another strategy.");
conversionResult = converter.useRobustSyntax().toXtend(iCompilationUnit);
}
}
conversionResults.put(iCompilationUnit, conversionResult);
monitor.worked(1);
}
}
use of org.eclipse.xtend.core.javaconverter.JavaConverter.ConversionResult in project xtext-xtend by eclipse.
the class ConvertJavaCode method runJavaConverter.
public void runJavaConverter(final Set<ICompilationUnit> compilationUnits, Shell activeShell) throws ExecutionException {
Map<ICompilationUnit, ConversionResult> conversionResults = newHashMap();
boolean canceled = convertAllWithProgress(activeShell, compilationUnits, conversionResults);
if (canceled) {
return;
}
boolean hasConversionFailures = any(conversionResults.values(), new Predicate<ConversionResult>() {
@Override
public boolean apply(ConversionResult input) {
return input.getProblems().iterator().hasNext();
}
});
if (hasConversionFailures) {
ConversionProblemsDialog problemsDialog = new ConversionProblemsDialog(activeShell, conversionResults);
problemsDialog.open();
if (problemsDialog.getReturnCode() == Window.CANCEL) {
return;
}
}
final String storedValue = dialogs.getUserDecision(DELETE_JAVA_FILES_AFTER_CONVERSION);
boolean deleteJavaFiles = false;
if (MessageDialogWithToggle.PROMPT.equals(storedValue)) {
int userAnswer = dialogs.askUser("Delete Java source files?", "Xtend converter", DELETE_JAVA_FILES_AFTER_CONVERSION, activeShell);
if (userAnswer == IDialogConstants.CANCEL_ID) {
// cancel
return;
} else if (userAnswer == IDialogConstants.YES_ID) {
deleteJavaFiles = true;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(storedValue)) {
deleteJavaFiles = true;
}
for (final Entry<ICompilationUnit, ConversionResult> result : conversionResults.entrySet()) {
ICompilationUnit compilationUnit = result.getKey();
ConversionResult conversionResult = result.getValue();
String xtendCode = conversionResult.getXtendCode();
IFile xtendFileToCreate = xtendFileToCreate(compilationUnit);
if (!conversionResult.getProblems().iterator().hasNext()) {
String formattedCode = formatXtendCode(xtendFileToCreate, xtendCode);
if (formattedCode != null) {
xtendCode = formattedCode;
}
}
writeToFile(xtendFileToCreate, xtendCode);
if (deleteJavaFiles) {
try {
compilationUnit.delete(true, null);
} catch (JavaModelException e) {
handleException("Unable to delete Java file.", e, compilationUnit.getResource());
}
}
}
}
use of org.eclipse.xtend.core.javaconverter.JavaConverter.ConversionResult in project xtext-xtend by eclipse.
the class ConversionProblemsDialog method create.
@Override
public void create() {
super.create();
if (javaFilesTable != null && !javaFilesTable.isDisposed()) {
for (Entry<ICompilationUnit, ConversionResult> entry : input.entrySet()) {
if (entry.getValue().getProblems().iterator().hasNext()) {
ICompilationUnit cu = entry.getKey();
IResource resource = cu.getResource();
TableItem ti = new TableItem(javaFilesTable, SWT.NONE);
ti.setImage(CompareUI.getImage(resource));
ti.setText(resource.getName());
ti.setData(cu);
ti.setChecked(true);
}
}
if (javaFilesTable.getItems().length > 0) {
javaFilesTable.select(0);
handleMemberSelect(javaFilesTable.getItems()[0]);
}
}
}
Aggregations