Search in sources :

Example 41 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    if (selection instanceof Def_Type) {
        final Def_Type df = (Def_Type) selection;
        type = df.getType(CompilationTimeStamp.getBaseTimestamp());
    }
    final DefinitionVisitor vis = new DefinitionVisitor(type);
    module.accept(vis);
    final NavigableSet<ILocateableNode> nodes = vis.getLocations();
    if (nodes.isEmpty()) {
        return null;
    }
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (!rootEdit.hasChildren()) {
        return null;
    }
    tfc.setEdit(rootEdit);
    return tfc;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CoreException(org.eclipse.core.runtime.CoreException) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Module(org.eclipse.titan.designer.AST.Module) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 42 with Module

use of org.eclipse.titan.designer.AST.Module 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)

Example 43 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ExtractToFunctionWizardFuncNamePage method checkNewNameValidity.

private boolean checkNewNameValidity() {
    final String newName = newFuncName.getText();
    if (newName.length() == 0) {
        setErrorMessage(null);
        setPageComplete(false);
        return false;
    }
    final Module mod = ((ExtractToFunctionRefactoring) getRefactoring()).getSelectedModule();
    switch(mod.getModuletype()) {
        case TTCN3_MODULE:
            if (!Identifier.isValidInTtcn(newName)) {
                setErrorMessage("Not a valid TTCN-3 identifier!");
                setPageComplete(false);
                return false;
            }
            break;
        case ASN_MODULE:
            if (!Identifier.isValidInAsn(newName)) {
                setErrorMessage("Not a valid ASN.1 identifier!");
                setPageComplete(false);
                return false;
            }
            break;
        default:
            ErrorReporter.INTERNAL_ERROR();
    }
    final Assignments assignments = mod.getAssignments();
    for (int i = 0; i < assignments.getNofAssignments(); i++) {
        final Assignment asg = assignments.getAssignmentByIndex(i);
        if (asg.getIdentifier().getDisplayName().equals(newName)) {
            setErrorMessage("A function with the provided name already exists!");
            setPageComplete(false);
            return false;
        }
    }
    setErrorMessage(null);
    setPageComplete(true);
    return true;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module)

Example 44 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    final DefinitionVisitor vis = new DefinitionVisitor();
    module.accept(vis);
    final List<FormalParameter> nodes = vis.getLocations();
    // Calculate edit locations
    final List<Location> locations = new ArrayList<Location>();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("LazyficationRefactoring: " + "CoreException while calculating edit locations in " + toVisit.getName() + ".");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (locations.isEmpty()) {
        return null;
    }
    // Create a change for each edit location
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    for (Location l : locations) {
        rootEdit.addChild(new InsertEdit(l.getOffset(), "@lazy "));
    }
    return tfc;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) InsertEdit(org.eclipse.text.edits.InsertEdit) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) CoreException(org.eclipse.core.runtime.CoreException) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Location(org.eclipse.titan.designer.AST.Location)

Example 45 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class DCListener method doubleClick.

@Override
public void doubleClick(final DoubleClickEvent event) {
    if (event.getSelection() instanceof IStructuredSelection) {
        final Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
        Location loc = null;
        if (o instanceof Module) {
            loc = ((Module) o).getLocation();
            LocationHighlighter.jumpToLocation(loc);
        }
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Module (org.eclipse.titan.designer.AST.Module)130 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)51 ArrayList (java.util.ArrayList)37 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)36 IFile (org.eclipse.core.resources.IFile)32 Assignment (org.eclipse.titan.designer.AST.Assignment)22 Identifier (org.eclipse.titan.designer.AST.Identifier)21 Location (org.eclipse.titan.designer.AST.Location)16 Reference (org.eclipse.titan.designer.AST.Reference)16 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)16 HashMap (java.util.HashMap)14 List (java.util.List)13 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)11 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Assignments (org.eclipse.titan.designer.AST.Assignments)9 Scope (org.eclipse.titan.designer.AST.Scope)9 TextSelection (org.eclipse.jface.text.TextSelection)8