Search in sources :

Example 56 with Module

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

the class MinimizeScopeActionFromEditor method findSelection.

private Definition findSelection() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    TTCN3Editor targetEditor;
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return null;
    } else {
        targetEditor = (TTCN3Editor) editor;
    }
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final TextSelection textSelection = extractSelection(selectionService.getSelection());
    // iterating through part of the module
    final IResource selectedRes = extractResource(targetEditor);
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("SelectionFinder.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return null;
    }
    final IFile selectedFile = (IFile) selectedRes;
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(selectedFile.getProject());
    final Module selectedModule = projectSourceParser.containedModule(selectedFile);
    // getting current selection nodes
    final int selectionOffset = textSelection.getOffset() + textSelection.getLength();
    final SelectionFinderVisitor selVisitor = new SelectionFinderVisitor(selectionOffset);
    selectedModule.accept(selVisitor);
    final Definition selectedDef = selVisitor.getSelection();
    if (selectedDef == null) {
        ErrorReporter.logWarning("SelectionFinder.findSelection(): Visitor did not find a definition in the selection.");
        statusLineManager.setErrorMessage(ERR_MSG_NO_SELECTION);
        return null;
    }
    return selectedDef;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) Module(org.eclipse.titan.designer.AST.Module) IResource(org.eclipse.core.resources.IResource) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 57 with Module

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

the class DependencyCollector method filterImportDefinitions.

/**
 * Returns the <code>importDefs</code> list, with the {@link ImportModule}s removed which refer to
 * modules that are not contained in the <code>allFiles</code> set.
 */
private static void filterImportDefinitions(final Set<IResource> allFiles, final List<ImportModule> importDefs, final ProjectSourceParser projParser) {
    final List<Identifier> allFileIds = new ArrayList<Identifier>(allFiles.size());
    for (IResource r : allFiles) {
        if (!(r instanceof IFile)) {
            continue;
        }
        final IFile f = (IFile) r;
        final Module m = projParser.containedModule(f);
        allFileIds.add(m.getIdentifier());
    }
    final ListIterator<ImportModule> importIt = importDefs.listIterator();
    while (importIt.hasNext()) {
        final ImportModule im = importIt.next();
        final Identifier id = im.getIdentifier();
        if (!allFileIds.contains(id)) {
            importIt.remove();
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) IResource(org.eclipse.core.resources.IResource) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)

Example 58 with Module

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

the class DependencyCollector method filterFriendDefinitions.

/**
 * Returns the <code>friendDefs</code> list, with the {@link FriendModule}s removed which refer to
 * modules that are not contained in the <code>allFiles</code> set.
 */
private static void filterFriendDefinitions(final Set<IResource> allFiles, final List<FriendModule> friendDefs, final ProjectSourceParser projParser) {
    final List<Identifier> allFileIds = new ArrayList<Identifier>(allFiles.size());
    for (IResource r : allFiles) {
        if (!(r instanceof IFile)) {
            continue;
        }
        final IFile f = (IFile) r;
        final Module m = projParser.containedModule(f);
        allFileIds.add(m.getIdentifier());
    }
    final ListIterator<FriendModule> importIt = friendDefs.listIterator();
    while (importIt.hasNext()) {
        final FriendModule fm = importIt.next();
        final Identifier id = fm.getIdentifier();
        if (!allFileIds.contains(id)) {
            importIt.remove();
        }
    }
}
Also used : FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Identifier(org.eclipse.titan.designer.AST.Identifier) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) IResource(org.eclipse.core.resources.IResource)

Example 59 with Module

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

the class Expectation method runTest.

public void runTest() {
    Map<String, List<Integer>> actualMarkers = new HashMap<String, List<Integer>>();
    // analyze the modules, and collect the related markers
    IProject project = WorkspaceHandlingLibrary.getWorkspace().getRoot().getProject(CustomConfigurable.PROJECT_TO_USE);
    ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    for (String modName : expectedMarkers.keySet()) {
        Module mod = parser.getModuleByName(modName);
        IResource file = mod.getLocation().getFile();
        MarkerHandler mh = Analyzer.builder().addProblem(type).build().analyzeModule(new NullProgressMonitor(), mod);
        List<Integer> lines = new ArrayList<Integer>();
        for (Marker m : mh.get(file)) {
            if (m.getProblemType() == type && m.getLine() != -1) {
                lines.add(m.getLine());
            }
        }
        // save the line number of markers that were from our problem type
        actualMarkers.put(modName, lines);
    }
    // check whether the reality complies our expectations
    for (String modName : expectedMarkers.keySet()) {
        for (Integer ln : expectedMarkers.get(modName)) {
            if (!actualMarkers.get(modName).remove(ln)) {
                fail("We expected a marker in " + modName + " at line " + ln + ", but have not found it");
            }
        }
    }
    // Check whether we managed to consume all markers that showed up during the analysis
    for (String modName : actualMarkers.keySet()) {
        for (Integer ln : actualMarkers.get(modName)) {
            fail("Unexpected marker in " + modName + " at line " + ln);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Marker(org.eclipse.titanium.markers.handler.Marker) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) IResource(org.eclipse.core.resources.IResource)

Example 60 with Module

use of org.eclipse.titan.designer.AST.Module 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)

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