Search in sources :

Example 6 with FriendModule

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

FriendModule (org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule)4 Location (org.eclipse.titan.designer.AST.Location)3 Module (org.eclipse.titan.designer.AST.Module)3 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)3 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 IAppendableSyntax (org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)1