Search in sources :

Example 46 with Location

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

the class ASN1_Integer_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == namedNumbers) {
        parseBlockInt();
    }
    if (isErroneous || null == namedNumbers) {
        return;
    }
    /* check named numbers */
    final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final Identifier identifier = namedValue.getName();
        if (nameMap.containsKey(identifier.getName())) {
            final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            nameMap.put(identifier.getName(), identifier);
        }
    }
    final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final IValue value = namedValue.getValue();
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = value.getValueRefdLast(timestamp, referenceChain);
        referenceChain.release();
        if (last.getIsErroneous(timestamp)) {
            continue;
        }
        switch(last.getValuetype()) {
            case INTEGER_VALUE:
                {
                    final Integer_Value integerValue = (Integer_Value) last;
                    if (integerValue.isNative()) {
                        final Integer intValue = Integer.valueOf(integerValue.intValue());
                        if (valueMap.containsKey(intValue)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Duplicate number {0} for name `{1}''", intValue, namedValue.getName().getDisplayName()));
                            final NamedValue temp = valueMap.get(intValue);
                            temp.getLocation().reportSemanticError(MessageFormat.format("Number {0} is already assigned to name `{1}''", intValue, temp.getName().getDisplayName()));
                        } else {
                            valueMap.put(intValue, namedValue);
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("Integer value `{0}'' is too big to be used as a named number", integerValue.getValueValue()));
                        value.setIsErroneous(true);
                    }
                    break;
                }
            default:
                namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named number `{0}''", namedValue.getName().getDisplayName()));
                value.setIsErroneous(true);
                break;
        }
    }
    nameMap.clear();
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Example 47 with Location

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

the class SubType method getParsedLocation.

/**
 * get the location of the subtype constraints parsed for this type, or
 * return the owner type location if none were parsed
 */
public Location getParsedLocation() {
    if ((parsedRestrictions == null) || parsedRestrictions.isEmpty()) {
        return myOwner.getLocation();
    }
    if (parsedRestrictions.size() == 1) {
        final Location loc = parsedRestrictions.get(0).getLocation();
        return (loc == null) ? myOwner.getLocation() : loc;
    }
    final Location startLoc = parsedRestrictions.get(0).getLocation();
    final Location endLoc = parsedRestrictions.get(parsedRestrictions.size() - 1).getLocation();
    if ((startLoc == null) || (endLoc == null)) {
        return myOwner.getLocation();
    }
    return Location.interval(startLoc, endLoc);
}
Also used : Location(org.eclipse.titan.designer.AST.Location)

Example 48 with Location

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

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    int ofs = findWordStart(offset, doc);
    String incompleteString = "";
    try {
        if (doc != null && offset >= ofs) {
            incompleteString = doc.get(ofs, offset - ofs);
        }
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    String[] reference = incompleteString.trim().split(REFERENCE_SPLITTER, -1);
    Reference ref = new Reference(null);
    ref.setLocation(new Location(file, 0, 0, offset - ofs));
    FieldSubReference subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[0]));
    subref.setLocation(new Location(file, 0, 0, reference[0].length()));
    ref.addSubReference(subref);
    if (reference.length > 1) {
        subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[1]));
        subref.setLocation(new Location(file, 0, reference[0].length() + 1, offset - ofs));
        ref.addSubReference(subref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, ofs);
    TTCN3CodeSkeletons.addSkeletonProposals(doc, offset, propCollector);
    TTCN3Keywords.addKeywordProposals(propCollector);
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Example 49 with Location

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

the class Symbols method checkUniqueness.

/**
 * Checks the uniqueness of the symbols, and also builds a hashmap of
 * them to speed up further searches.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
public void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    symbols_map.clear();
    symbols_v.trimToSize();
    for (Identifier id : symbols_v) {
        final String name = id.getName();
        if (symbols_map.containsKey(name)) {
            final Location location = symbols_map.get(name).getLocation();
            location.reportSingularSemanticError(MessageFormat.format(DUPLICATESYMBOLFIRST, id.getDisplayName()));
            id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATESYMBOLREPEATED, id.getDisplayName()));
        } else {
            symbols_map.put(name, id);
        }
    }
    lastTimeChecked = timestamp;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Location(org.eclipse.titan.designer.AST.Location)

Example 50 with Location

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

the class ASN1_BitString_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == namedValues) {
        parseBlockBitstring();
    }
    if (isErroneous || null == namedValues) {
        return;
    }
    /* check named bits */
    final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
    for (int i = 0, size = namedValues.getSize(); i < size; i++) {
        final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
        final Identifier identifier = namedValue.getName();
        if (nameMap.containsKey(identifier.getName())) {
            final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            nameMap.put(identifier.getName(), identifier);
        }
    }
    final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
    for (int i = 0, size = namedValues.getSize(); i < size; i++) {
        final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
        final IValue value = namedValue.getValue();
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = value.getValueRefdLast(timestamp, referenceChain);
        referenceChain.release();
        if (last.getIsErroneous(timestamp)) {
            continue;
        }
        switch(last.getValuetype()) {
            case INTEGER_VALUE:
                {
                    final Integer_Value integerValue = (Integer_Value) last;
                    if (integerValue.isNative()) {
                        final int intValue = integerValue.intValue();
                        final Integer intValueObject = Integer.valueOf(intValue);
                        if (intValue < 0) {
                            value.getLocation().reportSemanticError(MessageFormat.format("A non-negative INTEGER value was expected for named bit `{0}'' instead of {1}", namedValue.getName().getDisplayName(), intValueObject));
                            value.setIsErroneous(true);
                            continue;
                        }
                        if (valueMap.containsKey(intValueObject)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Duplicate value {0} for named bit `{1}''", intValueObject, namedValue.getName().getDisplayName()));
                            value.setIsErroneous(true);
                            final NamedValue temp = valueMap.get(intValueObject);
                            temp.getLocation().reportSemanticError(MessageFormat.format("Bit {0} is already assigned to name `{1}''", intValueObject, temp.getName().getDisplayName()));
                        } else {
                            valueMap.put(intValueObject, namedValue);
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value `{0}'' is too big to be used as a named bit", integerValue.getValueValue()));
                        value.setIsErroneous(true);
                    }
                    break;
                }
            default:
                namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named bit `{0}''", namedValue.getName().getDisplayName()));
                break;
        }
    }
    nameMap.clear();
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) 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