Search in sources :

Example 31 with FieldSubReference

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

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

the class ImportModule method checkImports.

@Override
public /**
 * {@inheritDoc}
 */
void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
    if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    symbols.checkUniqueness(timestamp);
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    if (null == parser || null == identifier) {
        lastImportCheckTimeStamp = timestamp;
        // FIXME: is it correct? lastImportCheckTimeStamp will be set in extreme case only - very early running
        referredModule = null;
        return;
    }
    final Module temp = referredModule;
    referredModule = parser.getModuleByName(identifier.getName());
    if (temp != referredModule) {
        setUnhandledChange(true);
    }
    if (referredModule == null) {
        identifier.getLocation().reportSemanticError(MessageFormat.format(MISSINGMODULE, identifier.getDisplayName()));
    } else {
        if (!(referredModule instanceof ASN1Module)) {
            identifier.getLocation().reportSemanticError(MessageFormat.format(NOTASN1MODULE, identifier.getDisplayName()));
            lastImportCheckTimeStamp = timestamp;
            referredModule = null;
            return;
        }
        moduleStack.add(referredModule);
        if (!referenceChain.add(this)) {
            moduleStack.remove(moduleStack.size() - 1);
            lastImportCheckTimeStamp = timestamp;
            return;
        }
        referredModule.checkImports(timestamp, referenceChain, moduleStack);
        for (int i = 0; i < symbols.size(); i++) {
            final Identifier id = symbols.getNthElement(i);
            final List<ISubReference> list = new ArrayList<ISubReference>();
            list.add(new FieldSubReference(id));
            final Defined_Reference reference = new Defined_Reference(null, list);
            reference.setLocation(identifier.getLocation());
            if (null != referredModule.getAssBySRef(timestamp, reference)) {
                if (!((ASN1Module) referredModule).exportsSymbol(timestamp, id)) {
                    identifier.getLocation().reportSemanticError(MessageFormat.format(SYMBOLNOTEXPORTED, id.getDisplayName(), referredModule.getIdentifier().getDisplayName()));
                }
            }
        }
        moduleStack.remove(moduleStack.size() - 1);
    }
    lastImportCheckTimeStamp = timestamp;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 33 with FieldSubReference

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

the class ASN1_Choice_Type method generateCodeIsPresentBoundChosen.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, String field) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return;
    }
    if (subReferenceIndex >= subreferences.size()) {
        return;
    }
    final StringBuilder closingBrackets = new StringBuilder();
    if (isTemplate) {
        boolean anyvalueReturnValue = true;
        if (optype == Operation_type.ISPRESENT_OPERATION) {
            anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
        } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
            anyvalueReturnValue = false;
        }
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
        expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
        expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
        expression.expression.append("break;\n");
        expression.expression.append("case ANY_VALUE:\n");
        expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
        expression.expression.append("break;\n");
        expression.expression.append("case SPECIFIC_VALUE:{\n");
        closingBrackets.append("break;}\n");
        closingBrackets.append("default:\n");
        closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
        closingBrackets.append("break;\n");
        closingBrackets.append("}\n");
        closingBrackets.append("}\n");
    }
    final ISubReference subReference = subreferences.get(subReferenceIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2}.union_selection_type.ALT_{3});\n", globalId, externalId, getGenNameValue(aData, expression.expression, myScope), FieldSubReference.getJavaGetterName(fieldId.getName())));
    expression.expression.append("}\n");
    final CompField compField = getComponentByName(fieldId);
    final Type nextType = compField.getType();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    closingBrackets.insert(0, "}\n");
    final String temporalId = aData.getTemporaryVariableName();
    final String temporalId2 = aData.getTemporaryVariableName();
    expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
    expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
    if (optype == Operation_type.ISBOUND_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
    } else if (optype == Operation_type.ISPRESENT_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
    } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
            expression.expression.append("}\n");
        }
    }
    nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
    expression.expression.append(closingBrackets);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Example 34 with FieldSubReference

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

the class ASN1Module method getAssBySRef.

@Override
public /**
 * {@inheritDoc}
 */
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
    Identifier moduleId = reference.getModuleIdentifier();
    final Identifier id = reference.getId();
    if (null == id) {
        return null;
    }
    Module module = null;
    if (null == moduleId || moduleId.getName().equals(identifier.getName())) {
        if (assignments.hasLocalAssignmentWithID(timestamp, id)) {
            return assignments.getLocalAssignmentByID(timestamp, id);
        }
        if (null != moduleId) {
            id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENT, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        }
        if (imports.singularImportedSymbols_map.containsKey(id.getName())) {
            module = imports.singularImportedSymbols_map.get(id.getName());
            moduleId = module.getIdentifier();
            imports.getImportedModuleById(moduleId).setUsedForImportation();
        } else if (imports.pluralImportedSymbols.contains(id.getName())) {
            id.getLocation().reportSemanticError(MessageFormat.format(MORESYMBOLS, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        } else {
            id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENTORSYMBOL, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        }
    }
    if (null == module) {
        if (!imports.hasImportedModuleWithId(moduleId)) {
            moduleId.getLocation().reportSemanticError(MessageFormat.format(NOIMPORTEDMODULE, moduleId.getDisplayName()));
            return null;
        }
        if (!imports.getImportedModuleById(moduleId).hasSymbol(id)) {
            id.getLocation().reportSemanticError(MessageFormat.format(NOSYMBOLSIMPORTED, id.getDisplayName(), moduleId.getDisplayName()));
            return null;
        }
        imports.getImportedModuleById(moduleId).setUsedForImportation();
        final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
        if (null == parser) {
            return null;
        }
        module = parser.getModuleByName(moduleId.getName());
    }
    if (this == module || null == module) {
        return null;
    }
    final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
    newSubreferences.add(new FieldSubReference(id));
    final Defined_Reference finalReference = new Defined_Reference(null, newSubreferences);
    // FIXME add semantic check guard on project level.
    return module.getAssBySRef(timestamp, finalReference);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 35 with FieldSubReference

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

the class StatementBlock method registerDefinition.

/**
 * Registers a definition (for example new variable) into the list of
 * definitions available in this statement block.
 *
 * Please note, that this is done while the semantic check is happening,
 * as it must not be allowed to reach definitions not yet defined.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param definition
 *                the definition to register.
 */
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
    if (definition == null) {
        return;
    }
    final Identifier identifier = definition.getIdentifier();
    if (identifier == null) {
        return;
    }
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(3);
    }
    final String definitionName = identifier.getName();
    if (definitionMap.containsKey(definitionName)) {
        if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
            final Location otherLocation = definitionMap.get(definitionName).getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        }
    } else {
        definitionMap.put(definitionName, definition);
        if (parentScope != null && definition.getLocation() != null) {
            if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                definition.getLocation().reportSemanticError(MessageFormat.format(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(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                }
            } else if (parentScope.isValidModuleId(identifier)) {
                definition.getLocation().reportSemanticWarning(MessageFormat.format(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) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)45 ISubReference (org.eclipse.titan.designer.AST.ISubReference)42 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IType (org.eclipse.titan.designer.AST.IType)24 Reference (org.eclipse.titan.designer.AST.Reference)16 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)14 ArrayList (java.util.ArrayList)13 IValue (org.eclipse.titan.designer.AST.IValue)12 Assignment (org.eclipse.titan.designer.AST.Assignment)10 Value (org.eclipse.titan.designer.AST.Value)8 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)7 Type (org.eclipse.titan.designer.AST.Type)6 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)5 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)5 Location (org.eclipse.titan.designer.AST.Location)5 Defined_Reference (org.eclipse.titan.designer.AST.ASN1.Defined_Reference)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 Module (org.eclipse.titan.designer.AST.Module)4 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)4