Search in sources :

Example 26 with Location

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

the class NamedTemplates method checkUniqueness.

/**
 * Checks the uniqueness of the named templates.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle
 */
public void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (lastUniquenessCheck != null && !lastUniquenessCheck.isLess(timestamp)) {
        return;
    }
    Identifier identifier;
    String name;
    if (lastUniquenessCheck == null) {
        namedTemplateMap = new HashMap<String, NamedTemplate>(named_templates.size());
        duplicatedNames = new ArrayList<NamedTemplate>();
        for (NamedTemplate template : named_templates) {
            identifier = template.getName();
            name = identifier.getName();
            if (namedTemplateMap.containsKey(name)) {
                if (duplicatedNames == null) {
                    duplicatedNames = new ArrayList<NamedTemplate>();
                }
                duplicatedNames.add(template);
            } else {
                namedTemplateMap.put(name, template);
            }
        }
        if (duplicatedNames != null) {
            for (NamedTemplate template : duplicatedNames) {
                named_templates.remove(template);
            }
        }
    }
    if (duplicatedNames != null) {
        for (NamedTemplate template : duplicatedNames) {
            identifier = template.getName();
            name = identifier.getName();
            final Location namedLocation = namedTemplateMap.get(name).getName().getLocation();
            namedLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEFIRST, identifier.getDisplayName()));
            template.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEREPEATED, identifier.getDisplayName()));
        }
    }
    lastUniquenessCheck = timestamp;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Location(org.eclipse.titan.designer.AST.Location)

Example 27 with Location

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

the class StatementBlock method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (!isDamaged) {
        // handle the simple case quickly
        for (int i = 0, size = statements.size(); i < size; i++) {
            final Statement statement = statements.get(i);
            statement.updateSyntax(reparser, false);
            reparser.updateLocation(statement.getLocation());
        }
        return;
    }
    returnStatus = null;
    lastTimeChecked = null;
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = location.getOffset();
    int rightBoundary = location.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    for (int i = 0, size = statements.size(); i < size && !enveloped; i++) {
        final Statement statement = statements.get(i);
        final Location temporalLocation = statement.getLocation();
        Location cumulativeLocation;
        if (statement instanceof Definition_Statement) {
            cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
        } else {
            cumulativeLocation = temporalLocation;
        }
        if (temporalLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
            enveloped = true;
            leftBoundary = cumulativeLocation.getOffset();
            rightBoundary = cumulativeLocation.getEndOffset();
        } else if (reparser.isDamaged(cumulativeLocation)) {
            nofDamaged++;
            if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
                lastAppendableBeforeChange = statement;
            } else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
                lastPrependableBeforeChange = statement;
            }
        } else {
            if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
                leftBoundary = cumulativeLocation.getEndOffset();
                lastAppendableBeforeChange = statement;
            }
            if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
                rightBoundary = cumulativeLocation.getOffset();
                lastPrependableBeforeChange = statement;
            }
        }
    }
    // was not enveloped
    if (!enveloped) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
    }
    // extension might be correct
    if (lastAppendableBeforeChange != null) {
        final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
        if (isBeingExtended) {
            leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
            nofDamaged++;
            enveloped = false;
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
    }
    if (lastPrependableBeforeChange != null) {
        final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
        if (temp != null && reparser.endsWithToken(temp)) {
            rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
            nofDamaged++;
            enveloped = false;
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
    }
    if (nofDamaged != 0) {
        removeStuffInRange(reparser);
    }
    for (final Iterator<Statement> iterator = statements.iterator(); iterator.hasNext(); ) {
        final Statement statement = iterator.next();
        final Location temporalLocation = statement.getLocation();
        Location cumulativeLocation;
        if (statement instanceof Definition_Statement) {
            cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
        } else {
            cumulativeLocation = temporalLocation;
        }
        if (reparser.isAffectedAppended(cumulativeLocation)) {
            try {
                statement.updateSyntax(reparser, enveloped && reparser.envelopsDamage(cumulativeLocation));
                reparser.updateLocation(statement.getLocation());
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    iterator.remove();
                    reparser.extendDamagedRegion(cumulativeLocation);
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (!enveloped) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        final int result = reparse(reparser);
        if (result > 1) {
            throw new ReParseException(result - 1);
        }
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 28 with Location

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

the class StatementBlock method removeStuffInRange.

private void removeStuffInRange(final TTCN3ReparseUpdater reparser) {
    for (int i = statements.size() - 1; i >= 0; i--) {
        final Statement statement = statements.get(i);
        Location cumulativeLocation;
        if (statement instanceof Definition_Statement) {
            cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
        } else {
            cumulativeLocation = statement.getLocation();
        }
        if (reparser.isDamaged(cumulativeLocation)) {
            reparser.extendDamagedRegion(cumulativeLocation);
            statements.remove(i);
        }
    }
}
Also used : NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 29 with Location

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

the class CompField method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        boolean enveloped = false;
        if (name != null) {
            final Location tempIdentifier = name.getLocation();
            if (reparser.envelopsDamage(tempIdentifier) || reparser.isExtending(tempIdentifier)) {
                reparser.extendDamagedRegion(tempIdentifier);
                final IIdentifierReparser r = new IdentifierReparser(reparser);
                final int result = r.parse();
                name = r.getIdentifier();
                // damage handled
                if (result == 0) {
                    enveloped = true;
                } else {
                    throw new ReParseException(result);
                }
            }
        }
        if (type != null) {
            if (enveloped) {
                type.updateSyntax(reparser, false);
                reparser.updateLocation(type.getLocation());
            } else if (reparser.envelopsDamage(type.getLocation())) {
                type.updateSyntax(reparser, true);
                enveloped = true;
                reparser.updateLocation(type.getLocation());
            }
        }
        if (defaultValue != null) {
            if (enveloped) {
                defaultValue.updateSyntax(reparser, false);
                reparser.updateLocation(defaultValue.getLocation());
            } else if (reparser.envelopsDamage(defaultValue.getLocation())) {
                defaultValue.updateSyntax(reparser, true);
                enveloped = true;
                reparser.updateLocation(defaultValue.getLocation());
            }
        }
        if (enveloped) {
            return;
        }
        throw new ReParseException();
    }
    reparser.updateLocation(name.getLocation());
    if (type != null) {
        type.updateSyntax(reparser, false);
        reparser.updateLocation(type.getLocation());
    }
    if (defaultValue != null) {
        defaultValue.updateSyntax(reparser, false);
        reparser.updateLocation(defaultValue.getLocation());
    }
}
Also used : IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) IdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser) IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 30 with Location

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

the class CompFieldMap method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        lastCompilationTimeStamp = null;
        if (doubleComponents != null) {
            fields.addAll(doubleComponents);
            doubleComponents = null;
            lastUniquenessCheck = null;
        }
        boolean enveloped = false;
        int nofDamaged = 0;
        int leftBoundary = location.getOffset();
        int rightBoundary = location.getEndOffset();
        final int damageOffset = reparser.getDamageStart();
        IAppendableSyntax lastAppendableBeforeChange = null;
        IAppendableSyntax lastPrependableBeforeChange = null;
        for (int i = 0, size = fields.size(); i < size && !enveloped; i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            // move offset to commentLocation
            if (field.getCommentLocation() != null) {
                tempLocation.setOffset(field.getCommentLocation().getOffset());
            }
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
                if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                    lastAppendableBeforeChange = field;
                } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                    lastPrependableBeforeChange = field;
                }
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = field;
                }
                if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = field;
                }
            }
        }
        // extend the reparser to the calculated values if the damage was not enveloped
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
        // correct
        if (lastAppendableBeforeChange != null) {
            final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
            if (isBeingExtended) {
                leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (lastPrependableBeforeChange != null) {
            final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
            if (temp != null && reparser.endsWithToken(temp)) {
                rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (nofDamaged != 0) {
            removeStuffInRange(reparser);
        }
        for (int i = 0; i < fields.size(); i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            if (reparser.isAffectedAppended(tempLocation)) {
                try {
                    field.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    reparser.updateLocation(field.getLocation());
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        fields.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                    } else {
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            int result = reparse(reparser);
            if (result == 0) {
                return;
            }
            throw new ReParseException(Math.max(--result, 0));
        }
        return;
    }
    for (int i = 0, size = fields.size(); i < size; i++) {
        final CompField field = fields.get(i);
        field.updateSyntax(reparser, false);
        reparser.updateLocation(field.getLocation());
    }
    if (doubleComponents != null) {
        for (int i = 0, size = doubleComponents.size(); i < size; i++) {
            final CompField field = doubleComponents.get(i);
            field.updateSyntax(reparser, false);
            reparser.updateLocation(field.getLocation());
        }
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7