Search in sources :

Example 1 with Def_ModulePar_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Template method getTemplateReferenced.

/**
 * Calculates the referenced template, and while doing so checks the
 * reference too.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param referenceChain
 *                the reference chain used to detect cyclic references.
 *
 * @return the template referenced
 */
private ITTCN3Template getTemplateReferenced(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (reference == null) {
        setIsErroneous(true);
        return null;
    }
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        setIsErroneous(true);
        return this;
    }
    ITTCN3Template template = null;
    switch(ass.getAssignmentType()) {
        case A_TEMPLATE:
            template = ((Def_Template) ass).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            ((Def_Var_Template) ass).check(timestamp);
            template = ((Def_Var_Template) ass).getInitialValue();
            break;
        case A_MODULEPAR_TEMPLATE:
            template = ((Def_ModulePar_Template) ass).getDefaultTemplate();
            break;
        default:
            setIsErroneous(true);
            return this;
    }
    if (template != null) {
        template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
    }
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (template != null) {
        return template;
    } else if (subreferences != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
    // some array indices could not be evaluated
    } else if (reference.getUsedInIsbound()) {
        return this;
    } else {
        setIsErroneous(true);
    }
    return this;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 2 with Def_ModulePar_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template in project titan.EclipsePlug-ins by eclipse.

the class All_From_Template method getNofTemplatesNotAnyornone.

/**
 * Calculates the number of list members which are not the any or none
 * symbol.
 *
 * @return the number calculated.
 */
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
    int result = 0;
    if (allFrom == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    if (!((SpecificValue_Template) allFrom).isReference()) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    // isReference branch:
    final Reference reference = ((SpecificValue_Template) allFrom).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        allFrom.getLocation().reportSemanticError("Assignment not found");
        allFrom.setIsErroneous(true);
        return result;
    }
    ITTCN3Template body = null;
    switch(assignment.getAssignmentType()) {
        case A_TEMPLATE:
            body = ((Def_Template) assignment).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            body = ((Def_Var_Template) assignment).getInitialValue();
            break;
        case A_CONST:
            final IValue value = ((Def_Const) assignment).getValue();
            return getNofValues(value, timestamp);
        case A_MODULEPAR:
            final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
            return getNofValues(mvalue, timestamp);
        case A_MODULEPAR_TEMPLATE:
            body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
            break;
        default:
            return result;
    }
    if (body == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
        allFrom.setIsErroneous(true);
        return result;
    }
    result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)

Example 3 with Def_ModulePar_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template 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;
    }
    // find all locations in the module that should be edited
    final DefinitionVisitor vis = new DefinitionVisitor();
    module.accept(vis);
    final NavigableSet<Definition> nodes = vis.getLocations();
    if (nodes.isEmpty()) {
        return null;
    }
    // calculate edit locations
    final List<Definition> locations = new ArrayList<Definition>();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("UngroupModuleparRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
        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);
    int precedeOffset = -1;
    final String fileContents = loadFileContent(toVisit);
    for (Definition node : locations) {
        final Location l = node.getCumulativeDefinitionLocation();
        final Location typeLocation = node.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
        final Location identifierLocation = node.getIdentifier().getLocation();
        if (precedeOffset != l.getOffset()) {
            precedeOffset = l.getOffset();
            final int len = l.getEndOffset() - l.getOffset();
            rootEdit.addChild(new DeleteEdit(l.getOffset(), len + 1));
        }
        String typeText = fileContents.substring(typeLocation.getOffset(), typeLocation.getEndOffset()).trim();
        String name = fileContents.substring(identifierLocation.getOffset(), identifierLocation.getEndOffset()).trim();
        String newModulePar = "";
        if (node instanceof Def_ModulePar) {
            Def_ModulePar modulePar = (Def_ModulePar) node;
            if (modulePar.getDefaultValue() != null) {
                final Location valueLocation = modulePar.getDefaultValue().getLocation();
                String valueText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
                newModulePar = "modulepar " + typeText + " " + name + " := " + valueText + ";\n";
            } else {
                newModulePar = "modulepar " + typeText + " " + name + ";\n";
            }
        } else if (node instanceof Def_ModulePar_Template) {
            Def_ModulePar_Template modulePar = (Def_ModulePar_Template) node;
            if (modulePar.getDefaultTemplate() != null) {
                final Location valueLocation = modulePar.getDefaultTemplate().getLocation();
                String temlateText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
                newModulePar = "modulepar template " + typeText + " " + name + " := " + temlateText + ";\n";
            } else {
                newModulePar = "modulepar template " + typeText + " " + name + ";\n";
            }
        }
        rootEdit.addChild(new InsertEdit(l.getOffset(), newModulePar));
    }
    return tfc;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) Def_ModulePar_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DeleteEdit(org.eclipse.text.edits.DeleteEdit) 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)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)2 ArrayList (java.util.ArrayList)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)1 DeleteEdit (org.eclipse.text.edits.DeleteEdit)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 IValue (org.eclipse.titan.designer.AST.IValue)1 Location (org.eclipse.titan.designer.AST.Location)1 Module (org.eclipse.titan.designer.AST.Module)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)1 Def_ModulePar_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template)1 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)1 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1