Search in sources :

Example 16 with Status

use of org.eclipse.core.runtime.Status in project che by eclipse.

the class InferTypeArgumentsRefactoring method checkFinalConditions.

/*
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    HashMap<IJavaProject, ArrayList<IJavaElement>> projectsToElements = getJavaElementsPerProject(fElements);
    //$NON-NLS-1$
    pm.beginTask("", projectsToElements.size() + 2);
    final RefactoringStatus result = new RefactoringStatus();
    try {
        fTCModel = new InferTypeArgumentsTCModel();
        final InferTypeArgumentsConstraintCreator unitCollector = new InferTypeArgumentsConstraintCreator(fTCModel, fAssumeCloneReturnsSameType);
        for (Iterator<Entry<IJavaProject, ArrayList<IJavaElement>>> iter = projectsToElements.entrySet().iterator(); iter.hasNext(); ) {
            Entry<IJavaProject, ArrayList<IJavaElement>> entry = iter.next();
            IJavaProject project = entry.getKey();
            ArrayList<IJavaElement> javaElementsList = entry.getValue();
            IJavaElement[] javaElements = javaElementsList.toArray(new IJavaElement[javaElementsList.size()]);
            List<ICompilationUnit> cus = Arrays.asList(JavaModelUtil.getAllCompilationUnits(javaElements));
            int batchSize = 150;
            int batches = ((cus.size() - 1) / batchSize) + 1;
            SubProgressMonitor projectMonitor = new SubProgressMonitor(pm, 1);
            //$NON-NLS-1$
            projectMonitor.beginTask("", batches);
            projectMonitor.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_building);
            for (int i = 0; i < batches; i++) {
                List<ICompilationUnit> batch = cus.subList(i * batchSize, Math.min(cus.size(), (i + 1) * batchSize));
                ICompilationUnit[] batchCus = batch.toArray(new ICompilationUnit[batch.size()]);
                final SubProgressMonitor batchMonitor = new SubProgressMonitor(projectMonitor, 1);
                batchMonitor.subTask(RefactoringCoreMessages.InferTypeArgumentsRefactoring_calculating_dependencies);
                ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
                parser.setProject(project);
                parser.setCompilerOptions(RefactoringASTParser.getCompilerOptions(project));
                parser.setResolveBindings(true);
                parser.createASTs(batchCus, new String[0], new ASTRequestor() {

                    @Override
                    public void acceptAST(final ICompilationUnit source, final CompilationUnit ast) {
                        batchMonitor.subTask(BasicElementLabels.getFileName(source));
                        SafeRunner.run(new ISafeRunnable() {

                            public void run() throws Exception {
                                IProblem[] problems = ast.getProblems();
                                for (int p = 0; p < problems.length; p++) {
                                    if (problems[p].isError()) {
                                        String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
                                        String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_in_cu_skipped, new Object[] { cuName });
                                        result.addError(msg, JavaStatusContext.create(source, SourceRangeFactory.create(problems[p])));
                                        return;
                                    }
                                }
                                ast.accept(unitCollector);
                            }

                            public void handleException(Throwable exception) {
                                String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
                                String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_internal_error, new Object[] { cuName });
                                JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null));
                                String msg2 = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_skipped, new Object[] { cuName });
                                result.addError(msg2, JavaStatusContext.create(source));
                            }
                        });
                        fTCModel.newCu();
                    }

                    @Override
                    public void acceptBinding(String bindingKey, IBinding binding) {
                    //do nothing
                    }
                }, batchMonitor);
            }
            projectMonitor.done();
            fTCModel.newCu();
        }
        //			Display.getDefault().syncExec(new Runnable() {
        //				public void run() {
        //					MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Debugging...", "after constraint gen");
        //				}
        //			});
        pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_solving);
        InferTypeArgumentsConstraintsSolver solver = new InferTypeArgumentsConstraintsSolver(fTCModel);
        InferTypeArgumentsUpdate updates = solver.solveConstraints(new SubProgressMonitor(pm, 1));
        //free caches
        solver = null;
        fChangeManager = new TextChangeManager();
        rewriteDeclarations(updates, new SubProgressMonitor(pm, 1));
        IFile[] filesToModify = ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits());
        result.merge(Checks.validateModifiesFiles(filesToModify, getValidationContext()));
        return result;
    } finally {
        pm.done();
        clearGlobalState();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IBinding(org.eclipse.jdt.core.dom.IBinding) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Entry(java.util.Map.Entry) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) ASTParser(org.eclipse.jdt.core.dom.ASTParser) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IProblem(org.eclipse.jdt.core.compiler.IProblem) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager)

Example 17 with Status

use of org.eclipse.core.runtime.Status in project che by eclipse.

the class CompilationUnitRewriteOperationsFix method createChange.

//	/**
//	 * {@inheritDoc}
//	 */
//	@Override
//	public LinkedProposalModel getLinkedPositions() {
//		if (!fLinkedProposalModel.hasLinkedPositions())
//			return null;
//
//		return fLinkedProposalModel;
//	}
/**
	 * {@inheritDoc}
	 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
    CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite((ICompilationUnit) fCompilationUnit.getJavaElement(), fCompilationUnit);
    fLinkedProposalModel.clear();
    for (int i = 0; i < fOperations.length; i++) {
        CompilationUnitRewriteOperation operation = fOperations[i];
        operation.rewriteAST(cuRewrite, fLinkedProposalModel);
    }
    CompilationUnitChange result = cuRewrite.createChange(getDisplayString(), true, null);
    if (result == null)
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.ID_PLUGIN, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
    return result;
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 18 with Status

use of org.eclipse.core.runtime.Status in project che by eclipse.

the class ContributionContextTypeRegistry method createResolver.

private static TemplateVariableResolver createResolver(IConfigurationElement element) throws CoreException {
    try {
        String type = element.getAttribute(TYPE);
        if (type != null) {
            TemplateVariableResolver resolver = (TemplateVariableResolver) element.createExecutableExtension(CLASS);
            resolver.setType(type);
            String desc = element.getAttribute(DESCRIPTION);
            //$NON-NLS-1$
            resolver.setDescription(desc == null ? "" : desc);
            return resolver;
        }
    } catch (ClassCastException e) {
        //$NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.editors", IStatus.OK, "extension does not implement " + TemplateVariableResolver.class.getName(), e));
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 19 with Status

use of org.eclipse.core.runtime.Status in project che by eclipse.

the class MultiStateTextFileChange method isValid.

/*
	 * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
	 */
public final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    //$NON-NLS-1$
    monitor.beginTask("", 1);
    try {
        if (fValidationState == null)
            //$NON-NLS-1$
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateTextFileChange has not been initialialized"));
        final ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        fDirty = buffer != null && buffer.isDirty();
        final RefactoringStatus status = fValidationState.isValid(needsSaving());
        if (needsSaving()) {
            status.merge(Changes.validateModifiesFiles(new IFile[] { fFile }));
        } else {
            // we are reading the file. So it should be at least in sync
            status.merge(Changes.checkInSync(new IFile[] { fFile }));
        }
        return status;
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 20 with Status

use of org.eclipse.core.runtime.Status in project che by eclipse.

the class ChePreferences method save.

protected void save(String location) throws BackingStoreException {
    if (location == null) {
        //                PrefsMessages.message("Unable to determine location of preference file for node: " + absolutePath()); //$NON-NLS-1$
        return;
    }
    //        if (DEBUG_PREFERENCE_GENERAL)
    //            PrefsMessages.message("Saving preferences to file: " + location); //$NON-NLS-1$
    Properties table = convertToProperties(new SortedProperties(), EMPTY_STRING);
    if (table.isEmpty()) {
        File file = new File(location);
        // nothing to save. delete existing file if one exists.
        if (file.exists() && !file.delete()) {
            //                String message = NLS.bind(PrefsMessages.preferences_failedDelete, location);
            ResourcesPlugin.log(new Status(IStatus.WARNING, PrefsMessages.OWNER_NAME, IStatus.WARNING, "preferences save failed, file was delete", null));
        }
        return;
    }
    table.put(VERSION_KEY, VERSION_VALUE);
    write(table, location);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Properties(java.util.Properties) File(java.io.File)

Aggregations

Status (org.eclipse.core.runtime.Status)305 IStatus (org.eclipse.core.runtime.IStatus)282 CoreException (org.eclipse.core.runtime.CoreException)132 IOException (java.io.IOException)66 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)64 InvocationTargetException (java.lang.reflect.InvocationTargetException)40 File (java.io.File)38 ArrayList (java.util.ArrayList)37 IFile (org.eclipse.core.resources.IFile)37 MultiStatus (org.eclipse.core.runtime.MultiStatus)30 IResource (org.eclipse.core.resources.IResource)27 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)26 IProject (org.eclipse.core.resources.IProject)24 IPath (org.eclipse.core.runtime.IPath)24 ITask (com.cubrid.common.core.task.ITask)23 PartInitException (org.eclipse.ui.PartInitException)23 InputStream (java.io.InputStream)18 GridData (org.eclipse.swt.layout.GridData)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)16