Search in sources :

Example 81 with Location

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

the class Definitions method reportDoubleDefinitions.

// reports the found double definitions. It is supposed doubleDefinition to be created already
private void reportDoubleDefinitions() {
    if (doubleDefinitions != null && !doubleDefinitions.isEmpty()) {
        String definitionName;
        Definition definition;
        Identifier identifier;
        for (int i = 0, size = doubleDefinitions.size(); i < size; i++) {
            definition = doubleDefinitions.get(i);
            identifier = definition.getIdentifier();
            definitionName = identifier.getName();
            try {
                final Location otherLocation = definitionMap.get(definitionName).getIdentifier().getLocation();
                otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
                identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
            } catch (NullPointerException e) {
                ErrorReporter.logError("Nullpointer was detected when reporting duplication error for definition: " + definitionName);
                throw e;
            }
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 82 with Location

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

the class Definitions method check.

/**
 * Refresh all markers on groups, definitions
 */
@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastCompilationTimeStamp != null && !lastCompilationTimeStamp.isLess(timestamp)) {
        return;
    }
    lastCompilationTimeStamp = timestamp;
    final Module module = getModuleScope();
    if (module != null) {
        if (module.getSkippedFromSemanticChecking()) {
            return;
        }
    }
    // markers on imports cannot be removed, they are already refreshed
    // These offsets will be used to remove last comments within Definitions
    int maxEndOffset = getLocation().getOffset();
    int lastEndOffset = 0;
    for (final Definition definition : definitions) {
        if (definition.getLastTimeChecked() == null || definition.getLastTimeChecked().isLess(timestamp)) {
            MarkerHandler.markAllSemanticMarkersForRemoval(definition.getCommentLocation());
            // doubleDefinition report will be deleted!
            MarkerHandler.markAllSemanticMarkersForRemoval(definition);
        }
        lastEndOffset = definition.getLocation().getEndOffset();
        if (lastEndOffset > maxEndOffset) {
            maxEndOffset = lastEndOffset;
        }
    }
    for (final Group group : groups) {
        group.markMarkersForRemoval(timestamp);
    }
    // remove markers on the final commented lines (for incremental parsing)
    final int defsEndOffset = getLocation().getEndOffset();
    if (maxEndOffset < defsEndOffset) {
        final Location loc = new Location(getLocation().getFile(), 0, maxEndOffset, defsEndOffset);
        MarkerHandler.markAllSemanticMarkersForRemoval(loc);
    }
    checkUniqueness(timestamp);
    checkGroups(timestamp);
    for (final Definition definition : definitions) {
        // it calls definition.checkUniqueness!
        definition.check(timestamp);
    }
    // perhaps checkUniqueness() was executed earlier and their markers have been removed
    reportDoubleDefinitions();
}
Also used : Module(org.eclipse.titan.designer.AST.Module) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 83 with Location

use of org.eclipse.titan.designer.AST.Location 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 84 with Location

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

the class For_Loop_Definitions method checkUniqueness.

/**
 * Checks the uniqueness of the definitions, and also builds a hashmap
 * of them to speed up further searches.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (lastUniquenessCheckTimeStamp != null && !lastUniquenessCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    lastUniquenessCheckTimeStamp = timestamp;
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(definitions.size());
    }
    definitionMap.clear();
    String definitionName;
    Definition definition;
    for (int i = 0, size = definitions.size(); i < size; i++) {
        definition = definitions.get(i);
        final Identifier identifier = definition.getIdentifier();
        definitionName = identifier.getName();
        if (definitionMap.containsKey(definitionName)) {
            final Location otherLocation = definitionMap.get(definitionName).getIdentifier().getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            definitionMap.put(definitionName, definition);
            if (parentScope != null && definition.getLocation() != null) {
                if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                    definition.getLocation().reportSemanticError(MessageFormat.format(StatementBlock.HIDINGSCOPEELEMENT, identifier.getDisplayName()));
                    final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                    subReferences.add(new FieldSubReference(identifier));
                    final Reference reference = new Reference(null, subReferences);
                    final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                    if (assignment != null && assignment.getLocation() != null) {
                        assignment.getLocation().reportSingularSemanticError(MessageFormat.format(StatementBlock.HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                    }
                } else if (parentScope.isValidModuleId(identifier)) {
                    definition.getLocation().reportSemanticWarning(MessageFormat.format(StatementBlock.HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 85 with Location

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

the class FormalParameterList method checkUniqueness.

/**
 * Checks the uniqueness of the parameters, and also builds a hashmap of
 * them to speed up further searches.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
private void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (lastTimeUniquenessChecked != null && !lastTimeUniquenessChecked.isLess(timestamp)) {
        return;
    }
    if (parameterMap != null) {
        parameterMap.clear();
    }
    for (int i = 0, size = parameters.size(); i < size; i++) {
        final FormalParameter parameter = parameters.get(i);
        if (parameter != null) {
            final String parameterName = parameter.getIdentifier().getName();
            if (parameterMap == null) {
                parameterMap = new HashMap<String, FormalParameter>(parameters.size());
            }
            if (parameterMap.containsKey(parameterName)) {
                final Location otherLocation = parameterMap.get(parameterName).getIdentifier().getLocation();
                otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEPARAMETERFIRST, parameter.getIdentifier().getDisplayName()));
                final Location paramLocation = parameter.getIdentifier().getLocation();
                paramLocation.reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERREPEATED, parameter.getIdentifier().getDisplayName()));
            } else {
                parameterMap.put(parameterName, parameter);
            }
        }
    }
    lastTimeUniquenessChecked = timestamp;
}
Also used : 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