Search in sources :

Example 6 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCN3Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
            CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
            if (timestamp == null) {
                TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
            } else {
                TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
            }
        }
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
    return;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 7 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class SpecialASN1Module method createSpecAsss.

/**
 * Creates the special assignments by parsing the strings as if they
 * were coming from an internal file and creating a module around them.
 *
 * @return the module of the special assignments created.
 */
private static ASN1Module createSpecAsss() {
    if (null != specialAssignmentsModule) {
        return specialAssignmentsModule;
    }
    final ASN1Assignments parsedAssignments = new ASN1Assignments();
    ASN1Assignment actualAssignment;
    for (String[] assignment : INTERNAL_ASSIGNMENTS) {
        actualAssignment = SpecialASN1Module.parseSpecialInternalAssignment(assignment[1], new Identifier(Identifier_type.ID_ASN, assignment[0]));
        parsedAssignments.addAssignment(actualAssignment);
    }
    // null as a project might not be a good idea
    specialAssignmentsModule = new ASN1Module(new Identifier(Identifier_type.ID_ASN, INTERNAL_MODULE), null, Tag_types.AUTOMATIC_TAGS, false);
    specialAssignmentsModule.setExports(new Exports(true));
    specialAssignmentsModule.setImports(new Imports());
    specialAssignmentsModule.setAssignments(parsedAssignments);
    specialAssignmentsModule.setLocation(NULL_Location.INSTANCE);
    specialAssignmentsModule.setScopeName(INTERNAL_MODULE);
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
    specialAssignmentsModule.checkImports(timestamp, referenceChain, new ArrayList<Module>());
    specialAssignmentsModule.check(timestamp);
    return specialAssignmentsModule;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ASN1Assignments(org.eclipse.titan.designer.AST.ASN1.ASN1Assignments) ModuleImportationChain(org.eclipse.titan.designer.AST.ModuleImportationChain) Module(org.eclipse.titan.designer.AST.Module) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)

Example 8 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class Def_Type_Visit_Handler method handleDefTypeNodes.

public void handleDefTypeNodes(IVisitableNode node) {
    Def_Type typeNode = (Def_Type) node;
    CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter();
    myASTVisitor.currentFileName = typeNode.getIdentifier().toString();
    Type type = typeNode.getType(compilationCounter);
    if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
        // record
        Def_Type_Record_Writer recordNode = new Def_Type_Record_Writer(typeNode);
        // add component fields
        recordNode.add(compFieldTypes, compFieldNames);
        String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(recordNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
        // set
        Def_Type_Set_Writer setNode = new Def_Type_Set_Writer(typeNode);
        // add component fields
        setNode.add(compFieldTypes, compFieldNames);
        String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(setNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
        // union
        Def_Type_Union_Writer union_writer = new Def_Type_Union_Writer(typeNode);
        // add component fields
        union_writer.add(compFieldTypes, compFieldNames);
        String[] typeArray = compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(union_writer.getJavaSource());
    } else if (type instanceof Integer_Type) {
        Def_Type_Integer_Writer integerNode = Def_Type_Integer_Writer.getInstance(typeNode);
        integerNode.clearLists();
        myASTVisitor.visualizeNodeToJava(integerNode.getJavaSource());
    } else if (type instanceof CharString_Type) {
        Def_Type_Charstring_Writer charstringNode = Def_Type_Charstring_Writer.getInstance(typeNode);
        charstringNode.clearLists();
        charstringNode.addCharStringValue(charstringValue);
        charstringValue = null;
        myASTVisitor.visualizeNodeToJava(charstringNode.getJavaSource());
    } else if (type instanceof TTCN3_Enumerated_Type) {
        Def_Type_Enum_Writer enumTypeNode = Def_Type_Enum_Writer.getInstance(typeNode);
        enumTypeNode.clearLists();
        enumTypeNode.enumItems.addAll(enumItems);
        enumTypeNode.enumItemValues.addAll(enumItemValues);
        enumItemValues.clear();
        enumItems.clear();
        myASTVisitor.visualizeNodeToJava(enumTypeNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_SET_OF)) {
        Def_Type_Set_Of_Writer setOfNode = new Def_Type_Set_Of_Writer(typeNode);
        setOfNode.setFieldType(setOfFieldType);
        setOfFieldType = null;
        myASTVisitor.visualizeNodeToJava(setOfNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
        Def_Type_Record_Of_Writer writer = new Def_Type_Record_Of_Writer(typeNode);
        writer.setFieldType(recordOfFieldType);
        myASTVisitor.visualizeNodeToJava(writer.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_PORT)) {
        Def_Type_Port_Writer portNode = Def_Type_Port_Writer.getInstance(typeNode);
        portNode.clearLists();
        portNode.inMessageName.addAll(inMessageName);
        portNode.outMessageName.addAll(outMessageName);
        portNode.inOutMessageName.addAll(inOutMessageName);
        portNode.setPortTypeAReferencedType(isPortTypeAReferencedType);
        waitingForPortAttriburtes = false;
        isPortTypeAReferencedType = false;
        inMessageName.clear();
        outMessageName.clear();
        inOutMessageName.clear();
        myASTVisitor.visualizeNodeToJava(portNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_COMPONENT)) {
        Def_Type_Component_Writer compNode = Def_Type_Component_Writer.getInstance(typeNode);
        compNode.clearLists();
        // add component fields
        compNode.compFieldPortTypes.addAll(componentPortTypes);
        compNode.compFieldPortNames.addAll(componentPortNames);
        compNode.compFieldVarTypes.addAll(componentVarTypes);
        compNode.compFieldVarNames.addAll(componentVarNames);
        componentPortTypes.clear();
        componentPortNames.clear();
        componentVarTypes.clear();
        componentVarNames.clear();
        waitForCompReference = false;
        myASTVisitor.visualizeNodeToJava(compNode.getJavaSource());
    }
    parentName = null;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp)

Example 9 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class RunsOnScopeReduction method process.

@Override
protected void process(IVisitableNode node, Problems problems) {
    final Set<Identifier> definitions = new HashSet<Identifier>();
    final Identifier componentIdentifier;
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final Identifier identifier;
    boolean isTestCase = false;
    if (node instanceof Def_Function) {
        final Def_Function variable = (Def_Function) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else if (node instanceof Def_Altstep) {
        final Def_Altstep variable = (Def_Altstep) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else {
        final Def_Testcase variable = (Def_Testcase) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
        isTestCase = true;
    }
    final ReferenceCheck chek = new ReferenceCheck();
    node.accept(chek);
    definitions.addAll(chek.getIdentifiers());
    if (definitions.isEmpty()) {
        if (isTestCase) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
        } else {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
        }
    } else if (!definitions.contains(componentIdentifier)) {
        ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
        if (definitions.size() == 1) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
        } else {
            // FIXME: implement other cases
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ArrayList(java.util.ArrayList) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) HashSet(java.util.HashSet)

Example 10 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class UnusedStartedFuncRetVal method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Start_Component_Statement) {
        final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
        final Start_Component_Statement s = (Start_Component_Statement) node;
        final Component_Type compType = Port_Utility.checkComponentReference(timestamp, s, s.getComponent(), false, false);
        final Assignment assignment = s.getFunctionInstanceReference().getRefdAssignment(timestamp, false);
        if (assignment == null) {
            return;
        }
        switch(assignment.getAssignmentType()) {
            case A_FUNCTION:
            case A_FUNCTION_RTEMP:
            case A_FUNCTION_RVAL:
                break;
            default:
                return;
        }
        final Def_Function function = (Def_Function) assignment;
        final IType runsOnType = function.getRunsOnType(timestamp);
        if (compType == null || runsOnType == null || !function.isStartable()) {
            return;
        }
        switch(function.getAssignmentType()) {
            case A_FUNCTION_RTEMP:
                break;
            case A_FUNCTION_RVAL:
                IType type = function.getType(timestamp);
                boolean returnTypeCorrect = false;
                while (!returnTypeCorrect) {
                    if (type.hasDoneAttribute()) {
                        returnTypeCorrect = true;
                        break;
                    }
                    if (type instanceof IReferencingType) {
                        final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        final IType refd = ((IReferencingType) type).getTypeRefd(timestamp, refChain);
                        refChain.release();
                        if (type != refd) {
                            type = refd;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (!returnTypeCorrect) {
                    final String msg = MessageFormat.format(PROBLEM, function.getDescription(), function.getType(timestamp).getTypename());
                    problems.report(s.getFunctionInstanceReference().getLocation(), msg);
                }
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Start_Component_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Start_Component_Statement) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)13 IType (org.eclipse.titan.designer.AST.IType)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 Module (org.eclipse.titan.designer.AST.Module)3 Type (org.eclipse.titan.designer.AST.Type)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Location (org.eclipse.titan.designer.AST.Location)2 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)2 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)2 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)2 Value (org.eclipse.titan.designer.AST.Value)2 HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1