Search in sources :

Example 41 with Reference

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

the class EffCouplingDetector method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof Reference) {
        final Reference reference = (Reference) node;
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment != null) {
            final Module referencedModule = assignment.getMyScope().getModuleScope();
            if (!ownModule.equals(referencedModule)) {
                efferentCoupling.get(ownModule).add(assignment);
            }
        }
    }
    return V_CONTINUE;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Reference(org.eclipse.titan.designer.AST.Reference) Module(org.eclipse.titan.designer.AST.Module)

Example 42 with Reference

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

the class RenameRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    // search
    idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
    // add the referred identifier to the map of found identifiers
    Identifier refdIdentifier = rf.getReferredIdentifier();
    Module refdModule = rf.assignment.getMyScope().getModuleScope();
    if (idsMap.containsKey(refdModule)) {
        idsMap.get(refdModule).add(new Hit(refdIdentifier));
    } else {
        ArrayList<Hit> identifierList = new ArrayList<Hit>();
        identifierList.add(new Hit(refdIdentifier));
        idsMap.put(refdModule, identifierList);
    }
    // scopes
    if (rf.fieldId == null) {
        // check that in all affected scopes there is no
        // definition with the new name
        Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
        if (rf.scope.getModuleScope() instanceof ASN1Module) {
            idType = Identifier_type.ID_ASN;
        }
        Identifier newId = new Identifier(idType, newIdentifierName);
        // check for assignment with given id in all sub-scopes
        // of the assignment's scope
        // TODO: this does not detect runs on <-> component
        // member conflicts because the RunsOnScope is not a
        // sub-scope of the ComponentTypeBody scope,
        // also it does not go into other modules
        Scope rootScope = rf.assignment.getMyScope();
        if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
            rootScope = rootScope.getParentScope();
        }
        SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
        module.accept(subScopeVisitor);
        List<Scope> subScopes = subScopeVisitor.getSubScopes();
        subScopes.add(rootScope);
        for (Scope ss : subScopes) {
            if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
                List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(newId));
                Reference reference = new Reference(null, subReferences);
                Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
                if (assignment != null && assignment.getLocation() != null) {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
                } else {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
                }
                // to avoid spam and multiple messages for the same conflict
                return result;
            }
        }
    } else {
        boolean alreadyExists = false;
        // name
        if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
            alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
        } else if (rf.type instanceof TTCN3_Enumerated_Type) {
            alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Choice_Type) {
            alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Enumerated_Type) {
            alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Sequence_Type) {
            alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Set_Type) {
            alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        }
        if (alreadyExists) {
            result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
        }
    }
    return result;
}
Also used : Identifier_type(org.eclipse.titan.designer.AST.Identifier.Identifier_type) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) SubScopeVisitor(org.eclipse.titan.designer.AST.SubScopeVisitor) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) ASN1_Enumerated_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)

Example 43 with Reference

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

the class OpenDeclaration method handleModuleParameters.

/**
 * Selects and reveals the selected module parameter.
 *
 * @param file
 *                The current file.
 * @param offset
 *                The position of the cursor.
 * @param document
 *                The document opened in the configuration file editor.
 * @return True
 */
public boolean handleModuleParameters(final IFile file, final int offset, final IDocument document) {
    ConfigReferenceParser refParser = new ConfigReferenceParser(false);
    Reference reference = refParser.findReferenceForOpening(file, offset, document);
    if (refParser.isModuleParameter()) {
        if (reference == null) {
            return false;
        }
        ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        String exactModuleName = refParser.getExactModuleName();
        ArrayList<Assignment> foundAssignments = new ArrayList<Assignment>();
        if (exactModuleName != null) {
            Module module = projectSourceParser.getModuleByName(exactModuleName);
            if (module != null) {
                Assignments assignments = module.getAssignments();
                for (int i = 0; i < assignments.getNofAssignments(); i++) {
                    Assignment assignment = assignments.getAssignmentByIndex(i);
                    if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                        foundAssignments.add(assignment);
                    }
                }
            }
        } else {
            for (String moduleName : projectSourceParser.getKnownModuleNames()) {
                Module module = projectSourceParser.getModuleByName(moduleName);
                if (module != null) {
                    Assignments assignments = module.getAssignments();
                    for (int i = 0; i < assignments.getNofAssignments(); i++) {
                        Assignment assignment = assignments.getAssignmentByIndex(i);
                        if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                            foundAssignments.add(assignment);
                        }
                    }
                }
            }
        }
        if (foundAssignments.isEmpty()) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTMODULEPARDECLARATION);
            return false;
        }
        // List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
        // DeclarationCollectionHelper declaration = null;
        Assignment assignment = null;
        if (foundAssignments.size() == 1) {
            assignment = foundAssignments.get(0);
        } else {
            Assignment result = openCollectionListDialog(foundAssignments);
            if (result != null) {
                assignment = result;
            }
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            for (Assignment tempAssignment : foundAssignments) {
                Location location = tempAssignment.getLocation();
                TITANDebugConsole.println("Module parameter: " + location.getFile() + ":" + location.getOffset() + "-" + location.getEndOffset());
            }
        }
        if (assignment != null) {
            Location location = assignment.getLocation();
            selectAndRevealRegion((IFile) location.getFile(), location.getOffset(), location.getEndOffset(), true);
        }
        return true;
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

Example 44 with Reference

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

the class ConfigReferenceParser method findReferenceForOpening.

@Override
public Reference findReferenceForOpening(final IFile file, final int offset, final IDocument document) {
    Reference reference = null;
    int ofs = offset - 1;
    int endoffset = offset;
    if (-1 == offset) {
        return reference;
    }
    try {
        int tempOfs = referenceStartOffset(ofs, document);
        if (-1 == tempOfs) {
            return reference;
        }
        ofs = tempOfs + 1;
        char currentChar = document.getChar(endoffset);
        while (endoffset < document.getLength()) {
            if (!Character.isLetterOrDigit(currentChar) && currentChar != '*' && currentChar != '_' && currentChar != '.') {
                break;
            }
            currentChar = document.getChar(++endoffset);
        }
        if (!moduleParameter) {
            defineName = document.get(ofs, endoffset - ofs);
            return null;
        }
        String selected = document.get(ofs, endoffset - ofs);
        String parameter = selected;
        int dotIndex = selected.indexOf('.');
        if (dotIndex > 0) {
            String moduleName = selected.substring(0, dotIndex);
            if (!"*".equals(moduleName)) {
                exactModuleName = moduleName;
                IPreferencesService prefs = Platform.getPreferencesService();
                if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
                    TITANDebugConsole.println("Module: " + exactModuleName);
                }
            }
            parameter = selected.substring(dotIndex + 1);
        }
        TTCN3ReferenceAnalyzer refAnalyzer = new TTCN3ReferenceAnalyzer();
        reference = refAnalyzer.parse(file, parameter, reportErrors, document.getLineOfOffset(ofs) + 1, ofs);
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    return reference;
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) TTCN3ReferenceAnalyzer(org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReferenceAnalyzer) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 45 with Reference

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

the class ExtractToFunctionRefactoring method createFunction.

public WorkspaceJob createFunction() {
    final WorkspaceJob job = new WorkspaceJob("ExtractToFunction: creating new function text") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            final StatementList selectedStatements = selectionFinder.getSelectedStatements();
            final Module selectedModule = getSelectedModule();
            final IFile selectedFile = getSelectedFile();
            final Reference runsOnRef = selectionFinder.getRunsOnRef();
            final Type returnType = selectionFinder.getReturnType();
            final ReturnCertainty retCertainty = selectionFinder.getReturnCertainty();
            parentFunc = selectionFinder.getParentFunc();
            if (parentFunc == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not find the enclosing function of the selection! ");
                return Status.CANCEL_STATUS;
            }
            if (selectionFinder.getInsertLoc() < 0) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not calculate the insert location! ");
                return Status.CANCEL_STATUS;
            }
            if (selectedStatements == null || selectedStatements.isEmpty() || selectedModule == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): No or invalid selection! ");
                return Status.CANCEL_STATUS;
            }
            // collect params and find runs on clause
            paramCollector = new ParamCollector(project, selectedStatements, selectedModule);
            paramCollector.perform();
            List<Param> params = paramCollector.getParams();
            // 
            if (params == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to collect params! ");
                return Status.CANCEL_STATUS;
            }
            // create new function text
            functionCreator = new FunctionCreator(selectedStatements, selectedFile, newFuncName, params, runsOnRef, returnType, retCertainty);
            functionCreator.perform();
            functionText = functionCreator.getFunctionText();
            if (functionText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function text! ");
                return Status.CANCEL_STATUS;
            }
            functionCallText = functionCreator.getFunctionCallText();
            if (functionCallText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function call text! ");
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.titan.designer.AST.Type) IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ReturnCertainty(org.eclipse.titanium.refactoring.function.ReturnVisitor.ReturnCertainty) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7