Search in sources :

Example 6 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.

the class RenameRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    // search
    idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
    // add the referred identifier to the map of found identifiers
    Identifier refdIdentifier = rf.getReferredIdentifier();
    Module refdModule = rf.assignment.getMyScope().getModuleScope();
    if (idsMap.containsKey(refdModule)) {
        idsMap.get(refdModule).add(new Hit(refdIdentifier));
    } else {
        ArrayList<Hit> identifierList = new ArrayList<Hit>();
        identifierList.add(new Hit(refdIdentifier));
        idsMap.put(refdModule, identifierList);
    }
    // scopes
    if (rf.fieldId == null) {
        // check that in all affected scopes there is no
        // definition with the new name
        Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
        if (rf.scope.getModuleScope() instanceof ASN1Module) {
            idType = Identifier_type.ID_ASN;
        }
        Identifier newId = new Identifier(idType, newIdentifierName);
        // check for assignment with given id in all sub-scopes
        // of the assignment's scope
        // TODO: this does not detect runs on <-> component
        // member conflicts because the RunsOnScope is not a
        // sub-scope of the ComponentTypeBody scope,
        // also it does not go into other modules
        Scope rootScope = rf.assignment.getMyScope();
        if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
            rootScope = rootScope.getParentScope();
        }
        SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
        module.accept(subScopeVisitor);
        List<Scope> subScopes = subScopeVisitor.getSubScopes();
        subScopes.add(rootScope);
        for (Scope ss : subScopes) {
            if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
                List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(newId));
                Reference reference = new Reference(null, subReferences);
                Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
                if (assignment != null && assignment.getLocation() != null) {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
                } else {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
                }
                // to avoid spam and multiple messages for the same conflict
                return result;
            }
        }
    } else {
        boolean alreadyExists = false;
        // name
        if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
            alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
        } else if (rf.type instanceof TTCN3_Enumerated_Type) {
            alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Choice_Type) {
            alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Enumerated_Type) {
            alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Sequence_Type) {
            alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Set_Type) {
            alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        }
        if (alreadyExists) {
            result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
        }
    }
    return result;
}
Also used : Identifier_type(org.eclipse.titan.designer.AST.Identifier.Identifier_type) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) SubScopeVisitor(org.eclipse.titan.designer.AST.SubScopeVisitor) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) ASN1_Enumerated_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)

Example 7 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.

the class ReferenceFinder method detectSmallestScope.

/**
 * Detect the smallest scope where the references should be searched
 *
 * @param assignment
 *                The assignment
 * @return The detected scope
 */
private Scope detectSmallestScope(final Assignment assignment) {
    Scope localScope = assignment.getMyScope();
    final Module module = localScope.getModuleScope();
    if (localScope instanceof StatementBlock) {
        final StatementBlock statementBlock = (StatementBlock) localScope;
        if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
            localScope = localScope.getParentScope();
        }
        if (statementBlock.hasEnclosingLoopOrAltguard()) {
            localScope = localScope.getParentScope();
        }
    }
    if (localScope instanceof NamedBridgeScope) {
        localScope = localScope.getParentScope();
    }
    // control,function,testcase,altstep then it is global
    if (localScope instanceof Assignments && localScope.getParentScope() == module) {
        localScope = module;
    } else // treat it as global definition
    if (localScope instanceof ComponentTypeBody) {
        // FIXME this still does not make them global, that is something completely different.
        localScope = module;
    } else // search for actual named parameters everywhere
    if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
        localScope = module;
    } else // For_Statement that must be searched
    if (localScope instanceof For_Loop_Definitions) {
        localScope = localScope.getParentScope();
    }
    return localScope;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) For_Loop_Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.For_Loop_Definitions) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 8 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.

the class Export_Debug_AST method run.

@Override
public void run(IAction action) {
    if (targetEditor == null)
        return;
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
    Module module = parser.containedModule(file);
    if (module == null) {
        TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
    }
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    module.accept(new ASTVisitor() {

        private int padding = 0;

        @Override
        public int visit(IVisitableNode node) {
            if (node instanceof Assignment) {
                Assignment assignment = (Assignment) node;
                printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
            } else if (node instanceof Identifier) {
                printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
            } else if (node instanceof Statement) {
                Statement statement = (Statement) node;
                printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
            } else if (node instanceof Reference) {
                Reference ref = (Reference) node;
                printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
                Assignment old = ref.getAssOld();
                if (old != null) {
                    printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
                }
            } else if (node instanceof ComponentTypeBody) {
                ComponentTypeBody body = (ComponentTypeBody) node;
                Map<String, Definition> map = body.getDefinitionMap();
                printInfoln(padding + 1, " contains definitions:");
                for (Map.Entry<String, Definition> entry : map.entrySet()) {
                    printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
                }
            }
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding++;
            }
            return super.visit(node);
        }

        @Override
        public int leave(IVisitableNode node) {
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding--;
            }
            return super.leave(node);
        }
    });
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IFile(org.eclipse.core.resources.IFile) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ASTVisitor(org.eclipse.titan.designer.AST.ASTVisitor) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) Module(org.eclipse.titan.designer.AST.Module) Map(java.util.Map) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 9 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.

the class AssignmentHandlerComponent method collectDataFrom.

public void collectDataFrom(final ComponentTypeBody componentTypeBody) {
    for (final Definition tempDefinition : componentTypeBody.getDefinitions()) {
        final ReferenceCollector referenceCollector = new ReferenceCollector();
        tempDefinition.accept(referenceCollector);
        final Set<String> references = computeReferences(referenceCollector.getReferences());
        if (containsErroneousReference(referenceCollector.getReferences())) {
            setIsInfected(true);
        }
        componentDefinitions.put(tempDefinition, references);
    }
    processComponentTypeReferenceList(componentTypeBody.getAttributeExtensions());
    processComponentTypeReferenceList(componentTypeBody.getExtensions());
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 10 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.

the class Def_Timer method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    if (getMyScope() instanceof ComponentTypeBody) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_COMPONENT_TIMER, identifier, this);
    } else if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TIMER, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TIMER, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (dimensions != null) {
        dimensions.check(timestamp);
    }
    if (defaultDuration != null) {
        if (dimensions == null) {
            defaultDuration.setLoweridToReference(timestamp);
            final Type_type tempType = defaultDuration.getExpressionReturntype(timestamp, isLocal() ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : Expected_Value_type.EXPECTED_STATIC_VALUE);
            switch(tempType) {
                case TYPE_REAL:
                    final IValue last = defaultDuration.getValueRefdLast(timestamp, null);
                    if (!last.isUnfoldable(timestamp)) {
                        final Real_Value real = (Real_Value) last;
                        final double value = real.getValue();
                        if (value < 0.0f) {
                            defaultDuration.getLocation().reportSemanticError(MessageFormat.format(NEGATIVDURATIONERROR, value));
                        } else if (real.isPositiveInfinity()) {
                            final String message = MessageFormat.format(INFINITYDURATIONERROR, real.createStringRepresentation());
                            defaultDuration.getLocation().reportSemanticError(message);
                        }
                    }
                    return;
                default:
                    defaultDuration.getLocation().reportSemanticError(OPERANDERROR);
            }
        } else {
            checkArrayDuration(timestamp, defaultDuration, 0);
        }
        defaultDuration.setCodeSection(CodeSectionType.CS_POST_INIT);
    }
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)8 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7 Assignment (org.eclipse.titan.designer.AST.Assignment)6 IValue (org.eclipse.titan.designer.AST.IValue)6 IType (org.eclipse.titan.designer.AST.IType)5 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Reference (org.eclipse.titan.designer.AST.Reference)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Scope (org.eclipse.titan.designer.AST.Scope)3 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ASTVisitor (org.eclipse.titan.designer.AST.ASTVisitor)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)2 Module (org.eclipse.titan.designer.AST.Module)2