Search in sources :

Example 11 with Assignments

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

the class ImportModule method addDeclaration.

/**
 * Adds the imported module or definitions contained in it, to the list
 * declaration proposals.
 *
 * @param declarationCollector
 *                the declaration collector.
 * @param targetModuleId
 *                the identifier of the module where the declaration
 *                should be inserted into.
 */
@Override
public /**
 * {@inheritDoc}
 */
void addDeclaration(final DeclarationCollector declarationCollector, final Identifier targetModuleId) {
    final Module savedReferredModule = referredModule;
    if (savedReferredModule != null) {
        final Assignments assignments = savedReferredModule.getAssignments();
        for (int i = 0; i < assignments.getNofAssignments(); i++) {
            final Assignment temporalAssignment = assignments.getAssignmentByIndex(i);
            if (savedReferredModule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, temporalAssignment)) {
                temporalAssignment.addDeclaration(declarationCollector, 0);
            }
        }
        final Identifier moduleId = declarationCollector.getReference().getModuleIdentifier();
        final List<ISubReference> subrefs = declarationCollector.getReference().getSubreferences();
        if (moduleId == null && subrefs.size() == 1 && identifier.getName().equals(subrefs.get(0).getId().getName())) {
            declarationCollector.addDeclaration(savedReferredModule.getIdentifier().getDisplayName(), savedReferredModule.getIdentifier().getLocation(), (Scope) null);
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module)

Example 12 with Assignments

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

the class ASN1Assignments method checkUniqueness.

/**
 * Checks the uniqueness of the definitions, and also builds a hashmap
 * of them to speed up further searches.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
public void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (null != lastUniqueNessCheckTimeStamp && !lastUniqueNessCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    if (null == assignmentMap) {
        assignmentMap = new HashMap<String, ASN1Assignment>(assignments.size());
    }
    lastUniqueNessCheckTimeStamp = timestamp;
    dynamic_assignments.clear();
    assignmentMap.clear();
    final Assignments specialAssignments = SpecialASN1Module.getSpecialModule().getAssignments();
    for (ASN1Assignment assignment : assignments) {
        final Identifier identifier = assignment.getIdentifier();
        final String assignmentName = identifier.getName();
        if (specialAssignments.hasAssignmentWithId(timestamp, identifier)) {
            final Location selfLocation = assignment.getIdentifier().getLocation();
            selfLocation.reportSemanticError(MessageFormat.format(RESERVEDIDENTIFIER, identifier.getDisplayName()));
        } else if (assignmentMap.containsKey(assignmentName)) {
            final Location otherLocation = assignmentMap.get(assignmentName).getIdentifier().getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            final Location selfLocation = assignment.getIdentifier().getLocation();
            selfLocation.reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            assignmentMap.put(assignmentName, assignment);
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Assignments(org.eclipse.titan.designer.AST.Assignments) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 13 with Assignments

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

the class ASN1Assignments method addDynamicAssignment.

/**
 * Adds a dynamic assignment to the list of assignments.
 * <p>
 * Only assignments which were created dynamically during the semantic
 * check shall be added with this function. The scope of the newly added
 * assignment is set to this scope scope here.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param assignment
 *                the assignment to be added
 */
public void addDynamicAssignment(final CompilationTimeStamp timestamp, final ASN1Assignment assignment) {
    if (null == assignment || null == assignment.getIdentifier()) {
        return;
    }
    if (null == lastUniqueNessCheckTimeStamp) {
        checkUniqueness(timestamp);
    }
    dynamic_assignments.add(assignment);
    assignment.setMyScope(this);
    final Identifier identifier = assignment.getIdentifier();
    final String assignmentName = identifier.getName();
    final Assignments specialAssignments = SpecialASN1Module.getSpecialModule().getAssignments();
    if (specialAssignments.hasAssignmentWithId(timestamp, identifier)) {
        final Location tempLocation = assignment.getIdentifier().getLocation();
        tempLocation.reportSemanticError(MessageFormat.format(RESERVEDIDENTIFIER, identifier.getDisplayName()));
    } else if (assignmentMap.containsKey(assignmentName)) {
        final Location otherLocation = assignmentMap.get(assignmentName).getIdentifier().getLocation();
        otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
        final Location selfLocation = assignment.getIdentifier().getLocation();
        selfLocation.reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
    } else {
        assignmentMap.put(assignmentName, assignment);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Assignments(org.eclipse.titan.designer.AST.Assignments) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 14 with Assignments

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

the class BrokenPartsViaReferences method getAssignmentsFrom.

public List<AssignmentHandler> getAssignmentsFrom(final Module module) {
    final List<AssignmentHandler> assignmentHandlers = new ArrayList<AssignmentHandler>();
    final Assignments assignments = module.getAssignments();
    for (int d = 0; d < assignments.getNofAssignments(); ++d) {
        final Assignment assignment = assignments.getAssignmentByIndex(d);
        final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(assignment);
        if (assignment instanceof Undefined_Assignment) {
            final ASN1Assignment realAssignment = ((Undefined_Assignment) assignment).getRealAssignment(CompilationTimeStamp.getBaseTimestamp());
            if (realAssignment != null) {
                realAssignment.accept(assignmentHandler);
            } else {
                // TODO: re-fine this branch
                assignment.accept(assignmentHandler);
            }
        } else {
            assignment.accept(assignmentHandler);
        }
        assignmentHandlers.add(assignmentHandler);
    }
    return assignmentHandlers;
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)

Example 15 with Assignments

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

the class BrokenPartsViaReferences method processStartModules.

public void processStartModules(final List<Module> startModules, final Map<Module, List<AssignmentHandler>> moduleAndBrokenAssignments) {
    for (Module startModule : startModules) {
        if (isTooSlow()) {
            return;
        }
        if (startModule instanceof TTCN3Module && startModule.getLastCompilationTimeStamp() != null && !startModule.isCheckRoot()) {
            // definition name has not changed but module semantically has not been checked:
            final Assignments startAssignments = startModule.getAssignments();
            final List<AssignmentHandler> brokens = new ArrayList<AssignmentHandler>();
            final List<AssignmentHandler> notBrokens = new ArrayList<AssignmentHandler>();
            for (Assignment assignment : startAssignments) {
                MarkerHandler.markAllSemanticMarkersForRemoval(assignment);
            }
            for (int d = 0; d < startAssignments.getNofAssignments(); ++d) {
                final Assignment startAssignment = startAssignments.getAssignmentByIndex(d);
                final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(startAssignment);
                startAssignment.check(timestamp);
                startAssignment.accept(assignmentHandler);
                if (startAssignment.isCheckRoot()) {
                    assignmentHandler.setIsInfected(true);
                    startAssignment.notCheckRoot();
                    assignmentHandler.addReason("Definition's infected, because of incremental parsing.");
                    brokens.add(assignmentHandler);
                } else if (assignmentHandler.getIsInfected()) {
                    assignmentHandler.addReason("Definition contains an infected reference.");
                    brokens.add(assignmentHandler);
                } else {
                    notBrokens.add(assignmentHandler);
                }
            }
            if (!brokens.isEmpty()) {
                checkLocalAssignments(brokens, notBrokens);
                if (moduleAndBrokenAssignments.containsKey(startModule)) {
                    moduleAndBrokenAssignments.get(startModule).addAll(brokens);
                } else {
                    moduleAndBrokenAssignments.put(startModule, brokens);
                }
            }
        } else {
            if (startModule.getLastCompilationTimeStamp() == null) {
                // The markers have been marked for removal only for ASN1 modules
                startModule.check(timestamp);
            }
            // puts additional markers!
            final List<AssignmentHandler> startAssignments = getAssignmentsFrom(startModule);
            for (AssignmentHandler assignmentHandler : startAssignments) {
                assignmentHandler.initStartParts();
                assignmentHandler.assignment.notCheckRoot();
                assignmentHandler.addReason("Parent module's CompilationTimeStamp is null.");
            }
            if (moduleAndBrokenAssignments.containsKey(startModule)) {
                moduleAndBrokenAssignments.get(startModule).addAll(startAssignments);
            } else {
                moduleAndBrokenAssignments.put(startModule, startAssignments);
            }
        }
        startModule.notCheckRoot();
    }
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Assignments(org.eclipse.titan.designer.AST.Assignments) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Aggregations

Assignments (org.eclipse.titan.designer.AST.Assignments)17 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Module (org.eclipse.titan.designer.AST.Module)9 Identifier (org.eclipse.titan.designer.AST.Identifier)7 ArrayList (java.util.ArrayList)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)3 Undefined_Assignment (org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment)3 Location (org.eclipse.titan.designer.AST.Location)3 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)3 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 IFile (org.eclipse.core.resources.IFile)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 RewriteSessionEditProcessor (org.eclipse.jface.text.RewriteSessionEditProcessor)1 TextSelection (org.eclipse.jface.text.TextSelection)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 CfgLocation (org.eclipse.titan.common.parsers.cfg.CfgLocation)1