Search in sources :

Example 1 with IAppendableSyntax

use of org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax 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 2 with IAppendableSyntax

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

Example 3 with IAppendableSyntax

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

the class Definitions method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param importedModules
 *                the list of module importations found in the same
 *                module.
 * @param friendModules
 *                the list of friend module declaration in the same
 *                module.
 * @param controlpart
 *                the control part found in the same module.
 * @throws ReParseException
 *                 if there was an error while refreshing the location
 *                 information and it could not be solved internally.
 */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> importedModules, final List<FriendModule> friendModules, final ControlPart controlpart) throws ReParseException {
    // calculate damaged region
    int result = 0;
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = location.getOffset();
    int rightBoundary = location.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    final int damageEndOffset = reparser.getDamageEnd();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    boolean isControlPossible = controlpart == null;
    if (controlpart != null) {
        final Location tempLocation = controlpart.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
        } else if (!reparser.isDamaged(tempLocation)) {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = controlpart;
            }
            if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = controlpart;
            }
        }
    }
    for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
        final Group tempGroup = groups.get(i);
        final Location tempLocation = tempGroup.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = tempGroup;
            }
            if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = tempGroup;
            }
        }
    }
    if (!groups.isEmpty()) {
        isControlPossible &= groups.get(groups.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
        final ImportModule tempImport = importedModules.get(i);
        if (tempImport.getParentGroup() == null) {
            final Location tempLocation = tempImport.getLocation();
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = tempImport;
                }
                if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = tempImport;
                }
            }
        }
    }
    if (!importedModules.isEmpty()) {
        isControlPossible &= importedModules.get(importedModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
        final FriendModule tempFriend = friendModules.get(i);
        if (tempFriend.getParentGroup() == null) {
            final Location tempLocation = tempFriend.getLocation();
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = tempFriend;
                }
                if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = tempFriend;
                }
            }
        }
    }
    if (!friendModules.isEmpty()) {
        isControlPossible &= friendModules.get(friendModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (tempLocation.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 = temp;
                } else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
                    lastPrependableBeforeChange = temp;
                }
            } else {
                if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = cumulativeLocation.getEndOffset();
                    lastAppendableBeforeChange = temp;
                }
                if (cumulativeLocation.getOffset() > damageEndOffset && cumulativeLocation.getOffset() < rightBoundary) {
                    rightBoundary = cumulativeLocation.getOffset();
                    lastPrependableBeforeChange = temp;
                }
            }
            final Location tempCommentLocation = temp.getCommentLocation();
            if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
                nofDamaged++;
                rightBoundary = tempLocation.getEndOffset();
            }
        }
    }
    if (!definitions.isEmpty()) {
        isControlPossible &= definitions.get(definitions.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    // was not enveloped
    if (!enveloped && reparser.isDamaged(location)) {
        // the 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) {
            // remove damaged stuff
            removeStuffInRange(reparser, importedModules, friendModules);
            if (doubleDefinitions != null) {
                doubleDefinitions.clear();
            }
            lastUniquenessCheckTimeStamp = null;
            lastCompilationTimeStamp = null;
        }
        // extend damaged region till the neighbor definitions just here to avoid calculating something damaged or extended:
        // Perhaps it should be moved even farther:
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
    }
    // update what is left
    for (int i = 0; i < groups.size(); i++) {
        final Group temp = groups.get(i);
        final Location tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, importedModules, definitions, friendModules);
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    groups.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    if (doubleDefinitions != null) {
                        doubleDefinitions.clear();
                    }
                    lastUniquenessCheckTimeStamp = null;
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < importedModules.size(); i++) {
        final ImportModule temp = importedModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    if (isDamaged) {
                        ((TTCN3Module) parentScope).checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        importedModules.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    for (int i = 0; i < friendModules.size(); i++) {
        final FriendModule temp = friendModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    if (isDamaged) {
                        ((TTCN3Module) parentScope).checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        friendModules.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(cumulativeLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, isDamaged);
                    if (reparser.getNameChanged()) {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        // to recheck the whole module
                        lastCompilationTimeStamp = null;
                        reparser.setNameChanged(false);
                    // This could also spread
                    }
                    if (isDamaged) {
                        // TODO lets move this into the definitions
                        temp.checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        definitions.remove(temp);
                        reparser.extendDamagedRegion(cumulativeLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser, importedModules, friendModules);
        if (doubleDefinitions != null) {
            doubleDefinitions.clear();
        }
        lastUniquenessCheckTimeStamp = null;
        lastCompilationTimeStamp = null;
    }
    for (int i = 0, size = groups.size(); i < size; i++) {
        final Group temp = groups.get(i);
        final Location tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = importedModules.size(); i < size; i++) {
        final ImportModule temp = importedModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                reparser.updateLocation(tempLocation);
            }
        }
    }
    for (int i = 0, size = friendModules.size(); i < size; i++) {
        final FriendModule temp = friendModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                reparser.updateLocation(tempLocation);
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(tempLocation)) {
                if (tempLocation != cumulativeLocation) {
                    reparser.updateLocation(cumulativeLocation);
                }
                reparser.updateLocation(tempLocation);
            }
        }
    }
    final boolean tempIsControlPossible = isControlPossible;
    if (!enveloped) {
        if (reparser.envelopsDamage(location)) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            result = reparse(reparser, tempIsControlPossible);
            result = Math.max(result - 1, 0);
            lastCompilationTimeStamp = null;
        } else {
            result = Math.max(result, 1);
        }
    }
    if (result == 0) {
        lastUniquenessCheckTimeStamp = null;
    } else {
        if (doubleDefinitions != null) {
            doubleDefinitions.clear();
        }
        lastUniquenessCheckTimeStamp = null;
        throw new ReParseException(result);
    }
}
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 4 with IAppendableSyntax

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

the class For_Loop_Definitions method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param isDamaged
 *                true if the location contains the damaged area, false
 *                if only its' location needs to be updated.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (!isDamaged) {
        // handle the simple case quickly
        for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
            final Definition temp = iterator.next();
            final Location temporalLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(temporalLocation)) {
                if (!temporalLocation.equals(cumulativeLocation)) {
                    reparser.updateLocation(cumulativeLocation);
                }
                reparser.updateLocation(temporalLocation);
            }
        }
        return;
    }
    // calculate damaged region
    int result = 0;
    lastCompilationTimeStamp = 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 (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        final Location tempLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (tempLocation.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 = temp;
            } else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
                lastPrependableBeforeChange = temp;
            }
        } else {
            if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
                leftBoundary = cumulativeLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
                rightBoundary = cumulativeLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    // was not enveloped
    if (!enveloped && isDamaged) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        // the 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) {
            // remove damaged stuff
            removeStuffInRange(reparser);
            lastUniquenessCheckTimeStamp = null;
        }
    }
    // update what is left
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        final Location temporalLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (reparser.isAffected(cumulativeLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(temporalLocation));
                if (reparser.getNameChanged()) {
                    lastUniquenessCheckTimeStamp = null;
                    reparser.setNameChanged(false);
                }
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    definitions.remove(temp);
                    reparser.extendDamagedRegion(cumulativeLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser);
        lastUniquenessCheckTimeStamp = null;
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        final Location temporalLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (reparser.isAffected(temporalLocation)) {
            if (!temporalLocation.equals(cumulativeLocation)) {
                reparser.updateLocation(cumulativeLocation);
            }
            reparser.updateLocation(temporalLocation);
        }
    }
    if (!enveloped && reparser.envelopsDamage(location)) {
        // whole definition region has to be re-parsed
        throw new ReParseException();
    }
    if (result != 0) {
        lastUniquenessCheckTimeStamp = null;
        throw new ReParseException(result);
    }
}
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 5 with IAppendableSyntax

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

the class Group method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param allImportedModules
 *                the list of module importations found in the same
 *                module.
 * @param allDefinitions
 *                the list of definitions found in the same module.
 * @param allFriends
 *                the list of friend module declarations found in the
 *                same module.
 * @return in case of processing error the minimum amount of semantic
 *         levels that must be destroyed to handle the syntactic
 *         changes, otherwise 0.
 */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> allImportedModules, final List<Definition> allDefinitions, final List<FriendModule> allFriends) throws ReParseException {
    int result = 0;
    Location tempLocation = identifier.getLocation();
    if (reparser.isDamaged(tempLocation)) {
        if (reparser.envelopsDamage(tempLocation) || reparser.isExtending(tempLocation)) {
            reparser.extendDamagedRegion(tempLocation);
            result = reparseIdentifier(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
        } else {
            throw new ReParseException();
        }
    } else {
        reparser.updateLocation(tempLocation);
    }
    if (reparser.isDamaged(innerLocation) && !reparser.envelopsDamage(innerLocation)) {
        throw new ReParseException();
    }
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = innerLocation.getOffset();
    int rightBoundary = innerLocation.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
            if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                lastAppendableBeforeChange = temp;
            } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                lastPrependableBeforeChange = temp;
            }
        // reparser.extendDamagedRegion(temp_location);
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
        final Location tempCommentLocation = temp.getCommentLocation();
        if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
            rightBoundary = tempCommentLocation.getOffset();
            lastPrependableBeforeChange = temp;
        }
    }
    // was not enveloped
    if (!enveloped && reparser.envelopsDamage(location)) {
        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) {
        // remove damaged stuff
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    // update what is left
    for (int i = 0; i < groups.size(); i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, allImportedModules, allDefinitions, friendModules);
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    groups.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < importedModules.size(); i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    importedModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < friendModules.size(); i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    friendModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                temp.updateSyntax(reparser, isDamaged);
                if (reparser.getNameChanged()) {
                    lastUniquenessCheckTimeStamp = null;
                    reparser.setNameChanged(false);
                }
                if (isDamaged) {
                    temp.checkRoot();
                }
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    definitions.remove(temp);
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    for (int i = 0, size = groups.size(); i < size; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = importedModules.size(); i < size; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = friendModules.size(); i < size; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    if (withAttributesPath != null && reparser.isAffected(withAttributesPath.getLocation())) {
        if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
            reparser.extendDamagedRegion(withAttributesPath.getLocation());
            result = reparseOptionalWithStatement(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
            return;
        }
        withAttributesPath.updateSyntax(reparser, reparser.envelopsDamage(withAttributesPath.getLocation()));
        reparser.updateLocation(withAttributesPath.getLocation());
    }
    if (!enveloped && reparser.envelopsDamage(innerLocation)) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        result = reparseModuleDefinitionsList(reparser);
    }
    reparser.updateLocation(innerLocation);
    if (result > 1) {
        throw new ReParseException(result - 1);
    }
    return;
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)5 IAppendableSyntax (org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax)5 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)5 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)4