Search in sources :

Example 1 with ReturnCertainty

use of org.eclipse.titanium.refactoring.function.ReturnVisitor.ReturnCertainty in project titan.EclipsePlug-ins by eclipse.

the class ExtractToFunctionRefactoring method createFunction.

public WorkspaceJob createFunction() {
    final WorkspaceJob job = new WorkspaceJob("ExtractToFunction: creating new function text") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            final StatementList selectedStatements = selectionFinder.getSelectedStatements();
            final Module selectedModule = getSelectedModule();
            final IFile selectedFile = getSelectedFile();
            final Reference runsOnRef = selectionFinder.getRunsOnRef();
            final Type returnType = selectionFinder.getReturnType();
            final ReturnCertainty retCertainty = selectionFinder.getReturnCertainty();
            parentFunc = selectionFinder.getParentFunc();
            if (parentFunc == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not find the enclosing function of the selection! ");
                return Status.CANCEL_STATUS;
            }
            if (selectionFinder.getInsertLoc() < 0) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not calculate the insert location! ");
                return Status.CANCEL_STATUS;
            }
            if (selectedStatements == null || selectedStatements.isEmpty() || selectedModule == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): No or invalid selection! ");
                return Status.CANCEL_STATUS;
            }
            // collect params and find runs on clause
            paramCollector = new ParamCollector(project, selectedStatements, selectedModule);
            paramCollector.perform();
            List<Param> params = paramCollector.getParams();
            // 
            if (params == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to collect params! ");
                return Status.CANCEL_STATUS;
            }
            // create new function text
            functionCreator = new FunctionCreator(selectedStatements, selectedFile, newFuncName, params, runsOnRef, returnType, retCertainty);
            functionCreator.perform();
            functionText = functionCreator.getFunctionText();
            if (functionText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function text! ");
                return Status.CANCEL_STATUS;
            }
            functionCallText = functionCreator.getFunctionCallText();
            if (functionCallText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function call text! ");
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.titan.designer.AST.Type) IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ReturnCertainty(org.eclipse.titanium.refactoring.function.ReturnVisitor.ReturnCertainty) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Module (org.eclipse.titan.designer.AST.Module)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Type (org.eclipse.titan.designer.AST.Type)1 ReturnCertainty (org.eclipse.titanium.refactoring.function.ReturnVisitor.ReturnCertainty)1