Search in sources :

Example 21 with Module

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

the class Port_Utility method checkToClause.

/**
 * Checks a to clause reference to see if it really references valid
 * component type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the source statement of this check.
 * @param portType
 *                the type of the port used in the statement. Used to
 *                find the address type in effect.
 * @param toClause
 *                the to clause to check
 */
public static void checkToClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final IValue toClause) {
    if (toClause == null) {
        return;
    }
    IType addressType = null;
    if (portType != null) {
        addressType = portType.getPortBody().getAddressType(timestamp);
    } else if (source != null) {
        final Module module = source.getMyStatementBlock().getModuleScope();
        if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
            addressType = ((TTCN3Module) module).getAddressType(timestamp);
        }
    }
    if (addressType == null) {
        checkComponentReference(timestamp, source, toClause, true, true);
    } else {
        // detect possible enumerated values (address may be an
        // enumerated type)
        final IValue temp = addressType.checkThisValueRef(timestamp, toClause);
        // try to figure out whether the argument is a component
        // reference or an SUT address
        boolean isAddress;
        final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (governor == null) {
            isAddress = !Type_type.TYPE_COMPONENT.equals(temp.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE));
        } else {
            isAddress = addressType.isCompatible(timestamp, governor, null, null, null);
        }
        if (isAddress) {
            addressType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
        } else {
            checkComponentReference(timestamp, source, temp, true, true);
        }
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IType(org.eclipse.titan.designer.AST.IType)

Example 22 with Module

use of org.eclipse.titan.designer.AST.Module 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);
    ASN1ReferenceParser refParser = new ASN1ReferenceParser();
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    if (tempModule != null) {
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    TemplateContextType contextType = new TemplateContextType(ASN1CodeSkeletons.CONTEXT_IDENTIFIER, ASN1CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_ASN, ASN1CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    if (scope != null) {
        scope.addProposal(propCollector);
        propCollector.sortTillMarked();
        propCollector.markPosition();
    }
    if (ref.getSubreferences().size() != 1) {
        return propCollector.getCompletitions();
    }
    if (scope == null) {
        propCollector.addProposal(CodeScanner.TAGS, null, KEYWORD);
    } else {
        ASN1CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    propCollector.addProposal(CodeScanner.VERBS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.COMPARE_TYPES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STATUS_TYPE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STORAGE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.MODIFIER, null, KEYWORD);
    propCollector.addProposal(CodeScanner.ACCESS_TYPE, null, KEYWORD);
    propCollector.sortTillMarked();
    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) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 23 with Module

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

the class AbstractOfType method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (myScope != null) {
        final Module module = myScope.getModuleScope();
        if (module != null && module.getSkippedFromSemanticChecking()) {
            lastTimeChecked = timestamp;
            return;
        }
    }
    componentInternal = false;
    isErroneous = false;
    parseAttributes(timestamp);
    if (ofType == null) {
        setIsErroneous(true);
    } else {
        ofType.setGenName(getGenNameOwn(), "0");
        ofType.setParentType(this);
        ofType.check(timestamp);
        if (!isAsn()) {
            ofType.checkEmbedded(timestamp, ofType.getLocation(), true, "embedded into another type");
        }
        componentInternal = ofType.isComponentInternal(timestamp);
    }
    if (constraints != null) {
        constraints.check(timestamp);
    }
    checkSubtypeRestrictions(timestamp);
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : Module(org.eclipse.titan.designer.AST.Module)

Example 24 with Module

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

the class EnumItem method getDeclaration.

@Override
public /**
 * {@inheritDoc}
 */
Declaration getDeclaration() {
    if (getMyScope() == null) {
        return null;
    }
    final Module module = getMyScope().getModuleScope();
    final Assignment assignment = module.getEnclosingAssignment(getLocation().getOffset());
    final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
    if (type instanceof ITypeWithComponents) {
        final Identifier id = ((ITypeWithComponents) type).getComponentIdentifierByName(getId());
        return Declaration.createInstance(assignment, id);
    }
    return null;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) ITypeWithComponents(org.eclipse.titan.designer.AST.ITypeWithComponents) Module(org.eclipse.titan.designer.AST.Module) IType(org.eclipse.titan.designer.AST.IType)

Example 25 with Module

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

the class UnusedGlobalDefinition method process.

@Override
protected void process(IProject project, Problems problems) {
    TITANDebugConsole.println("Unused global definition");
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    final List<Module> modules = new ArrayList<Module>();
    final Set<Assignment> unused = new HashSet<Assignment>();
    for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
        Module module = projectSourceParser.getModuleByName(moduleName);
        modules.add(module);
        final GlobalDefinitionCheck chek = new GlobalDefinitionCheck();
        module.accept(chek);
        unused.addAll(chek.getDefinitions());
    }
    for (Module module : modules) {
        final GlobalUsedDefinitionCheck chekUsed = new GlobalUsedDefinitionCheck();
        module.accept(chekUsed);
        unused.removeAll(chekUsed.getDefinitions());
    }
    for (Assignment ass : unused) {
        final String name = ass.getIdentifier().getDisplayName();
        final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used globally", ass.getAssignmentName(), name);
        problems.report(ass.getIdentifier().getLocation(), msg);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) HashSet(java.util.HashSet)

Aggregations

Module (org.eclipse.titan.designer.AST.Module)130 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)51 ArrayList (java.util.ArrayList)37 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)36 IFile (org.eclipse.core.resources.IFile)32 Assignment (org.eclipse.titan.designer.AST.Assignment)22 Identifier (org.eclipse.titan.designer.AST.Identifier)21 Location (org.eclipse.titan.designer.AST.Location)16 Reference (org.eclipse.titan.designer.AST.Reference)16 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)16 HashMap (java.util.HashMap)14 List (java.util.List)13 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)11 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Assignments (org.eclipse.titan.designer.AST.Assignments)9 Scope (org.eclipse.titan.designer.AST.Scope)9 TextSelection (org.eclipse.jface.text.TextSelection)8