Search in sources :

Example 36 with ReParseException

use of org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException in project titan.EclipsePlug-ins by eclipse.

the class ObjectIdentifierComponent method updateSyntax.

/**
 *  Handles the incremental parsing of this objid component.
 *
 *  @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.
 *   @return in case of processing error the minimum amount of semantic levels
 *    that must be destroyed to handle the syntactic changes, otherwise 0.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (name != null) {
        reparser.updateLocation(name.getLocation());
    }
    if (number instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) number).updateSyntax(reparser, false);
        reparser.updateLocation(number.getLocation());
    } else if (number != null) {
        throw new ReParseException();
    }
    if (definedValue instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) definedValue).updateSyntax(reparser, false);
        reparser.updateLocation(definedValue.getLocation());
    } else if (definedValue != null) {
        throw new ReParseException();
    }
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 37 with ReParseException

use of org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException in project titan.EclipsePlug-ins by eclipse.

the class SelectUnionCase method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (items != null) {
        for (Identifier item : items) {
            if (item instanceof Identifier) {
                final Identifier identifier = item;
                reparser.updateLocation(identifier.getLocation());
            } else {
                // program error, this should not happen
                ErrorReporter.INTERNAL_ERROR("Invalid type in select union case");
            }
        }
    }
    if (statementBlock != null) {
        statementBlock.updateSyntax(reparser, false);
        reparser.updateLocation(statementBlock.getLocation());
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 38 with ReParseException

use of org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException in project titan.EclipsePlug-ins by eclipse.

the class CompositeTemplate method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (lengthRestriction != null) {
        lengthRestriction.updateSyntax(reparser, false);
        reparser.updateLocation(lengthRestriction.getLocation());
    }
    if (baseTemplate instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
        reparser.updateLocation(baseTemplate.getLocation());
    } else if (baseTemplate != null) {
        throw new ReParseException();
    }
    templates.updateSyntax(reparser, false);
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 39 with ReParseException

use of org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException in project titan.EclipsePlug-ins by eclipse.

the class Start_Timer_Statement method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (timerReference != null) {
        timerReference.updateSyntax(reparser, false);
        reparser.updateLocation(timerReference.getLocation());
    }
    if (timerValue instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) timerValue).updateSyntax(reparser, false);
        reparser.updateLocation(timerValue.getLocation());
    } else if (timerValue != null) {
        throw new ReParseException();
    }
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 40 with ReParseException

use of org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException 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)

Aggregations

ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)52 Location (org.eclipse.titan.designer.AST.Location)24 IIncrementallyUpdateable (org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)6 IAppendableSyntax (org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax)5 IType (org.eclipse.titan.designer.AST.IType)2 FileNotFoundException (java.io.FileNotFoundException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IValue (org.eclipse.titan.designer.AST.IValue)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Module (org.eclipse.titan.designer.AST.Module)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1 ObjectIdentifierComponent (org.eclipse.titan.designer.AST.TTCN3.values.ObjectIdentifierComponent)1 Type (org.eclipse.titan.designer.AST.Type)1 ITtcn3FileReparser (org.eclipse.titan.designer.parsers.ttcn3parser.ITtcn3FileReparser)1 Ttcn3FileReparser (org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3FileReparser)1