Search in sources :

Example 1 with ProjectSourceParser

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

the class InternalMakefileGenerator method addTTCN3Module.

/**
 * Adds a file to the list of TTCN-3 files.
 * <p/>
 * The directory of the file must always point to a working directory,
 * or a central storage directory.
 *
 * @param file      the file to be added.
 * @param directory in which this file can be found (null if the working
 *                  directory of the actual project)
 */
public void addTTCN3Module(final IFile file, final String directory) {
    ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
    String moduleName = parser.containedModuleName(file);
    if (moduleName == null) {
        if (file.isSynchronized(IResource.DEPTH_ZERO)) {
            ErrorReporter.logWarning("file " + file.getFullPath().toOSString() + " is out-of sync with the file system");
        } else {
            ErrorReporter.logWarning("file " + file.getFullPath().toOSString() + " even tough it has ttcn extension is added as on other file since the on-the-fly analyzer was not able to find a valid module inside");
        }
        addOtherFiles(file, directory);
        return;
    }
    final Identifier identifier = new Identifier(Identifier_type.ID_NAME, moduleName);
    ModuleStruct module;
    final IPath fileLocation = file.getLocation();
    if (fileLocation == null) {
        final String originalLocation = directory + File.separatorChar + file.getName();
        module = new ModuleStruct(directory, originalLocation, file.getName(), identifier.getTtcnName());
    } else {
        final String originalLocation = fileLocation.toOSString();
        module = new ModuleStruct(directory, originalLocation, fileLocation.lastSegment(), identifier.getTtcnName());
    }
    module.setRegular(fileLocation != null && "ttcn".equals(file.getFileExtension()) && file.getName().equals(moduleName + ".ttcn"));
    ttcn3Modules.add(module);
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IPath(org.eclipse.core.runtime.IPath) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 2 with ProjectSourceParser

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

the class OpenDeclarationHelper method findVisibleDeclarations.

public static DeclarationCollector findVisibleDeclarations(final IEditorPart targetEditor, final IReferenceParser referenceParser, final IDocument document, final int offset, final boolean reportErrors) {
    final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEFILE);
        }
        return null;
    }
    Reference reference = null;
    referenceParser.setErrorReporting(reportErrors);
    reference = referenceParser.findReferenceForOpening(file, offset, document);
    if (reference == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
        }
        return null;
    }
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (ResourceExclusionHelper.isExcluded(file)) {
        ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return null;
    }
    final Module tempModule = projectSourceParser.containedModule(file);
    if (tempModule == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(NOTFOUNDMODULE, file.getFullPath()));
        }
        return null;
    }
    final Scope scope = tempModule.getSmallestEnclosingScope(offset);
    if (scope == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLESCOPE);
        }
        return null;
    }
    reference.setMyScope(scope);
    reference.detectModid();
    if (reference.getId() == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
        }
        return null;
    }
    final DeclarationCollector declarationCollector = new DeclarationCollector(reference);
    scope.addDeclaration(declarationCollector);
    return declarationCollector;
}
Also used : IFile(org.eclipse.core.resources.IFile) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 3 with ProjectSourceParser

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

the class FriendModule method check.

/**
 * Does the semantic checking of this friend ship.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle
 */
public void check(final CompilationTimeStamp timestamp) {
    if (lastCheckTimeStamp != null && !lastCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    if (parser == null || identifier == null) {
        lastCheckTimeStamp = timestamp;
        return;
    }
    final Module referredModule = parser.getModuleByName(identifier.getName());
    if (referredModule == null) {
        identifier.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTMISSINGFRIENDMODULE, GeneralConstants.WARNING, null), MessageFormat.format(MISSINGMODULE, identifier.getDisplayName()));
    } else if (!module_type.TTCN3_MODULE.equals(referredModule.getModuletype())) {
        identifier.getLocation().reportSemanticError(MessageFormat.format("The friend module `{0}'' must be a TTCN-3 module", identifier.getDisplayName()));
    }
    lastCheckTimeStamp = timestamp;
}
Also used : Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 4 with ProjectSourceParser

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

the class Imports method checkImports.

/**
 * Checks the import hierarchies of this importation (and the ones in
 * the imported module recursively).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param referenceChain
 *                a chain of references used to find circularly imported
 *                modules.
 * @param moduleStack
 *                the stack of modules visited so far, from the starting
 *                point.
 */
public void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
    if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    lastImportCheckTimeStamp = timestamp;
    if (null == project) {
        return;
    }
    importedModules_map.clear();
    singularImportedSymbols_map.clear();
    pluralImportedSymbols.clear();
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    if (null == parser) {
        return;
    }
    for (ImportModule importModule : importedModules_v) {
        final Identifier identifier = importModule.getIdentifier();
        if (null == identifier || null == identifier.getLocation()) {
            continue;
        }
        final Module referredModule = parser.getModuleByName(identifier.getName());
        if (null == referredModule) {
            identifier.getLocation().reportSemanticError(MessageFormat.format(ImportModule.MISSINGMODULE, identifier.getDisplayName()));
            continue;
        } else if (!(referredModule instanceof ASN1Module)) {
            identifier.getLocation().reportSemanticError(TTCN3IMPORT);
            continue;
        } else if (referredModule == module) {
            identifier.getLocation().reportSemanticError(SELFIMPORT);
            continue;
        }
        String name = identifier.getName();
        if (importedModules_map.containsKey(name)) {
            final Location importedLocation = importedModules_map.get(name).getIdentifier().getLocation();
            importedLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEIMPORTFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEIMPORTREPEATED, identifier.getDisplayName()));
        } else {
            importedModules_map.put(name, importModule);
        }
        final Symbols symbols = importModule.getSymbols();
        if (null == symbols) {
            continue;
        }
        for (int i = 0; i < symbols.size(); i++) {
            name = symbols.getNthElement(i).getName();
            if (singularImportedSymbols_map.containsKey(name)) {
                if (!referredModule.equals(singularImportedSymbols_map.get(name))) {
                    singularImportedSymbols_map.remove(name);
                    pluralImportedSymbols.add(name);
                }
            } else if (!pluralImportedSymbols.contains(name)) {
                singularImportedSymbols_map.put(name, referredModule);
            }
        }
        importModule.setUnhandledChange(false);
        LoadBalancingUtilities.astNodeChecked();
    }
    for (ImportModule importModule : importedModules_v) {
        // check the imports recursively
        referenceChain.markState();
        importModule.checkImports(timestamp, referenceChain, moduleStack);
        referenceChain.previousState();
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 5 with ProjectSourceParser

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

the class Export_Debug_AST_Action method run.

@Override
public void run(IAction action) {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    IStructuredSelection structSelection = (IStructuredSelection) selection;
    List<IProject> projects = new ArrayList<IProject>();
    for (Object selected : structSelection.toList()) {
        if (!(selected instanceof IProject)) {
            continue;
        }
        projects.add((IProject) selected);
    }
    for (IProject project : projects) {
        Shell shell = Display.getCurrent().getActiveShell();
        FileDialog d = new FileDialog(shell, SWT.SAVE);
        d.setText("Export debug information of the AST");
        d.setFilterExtensions(new String[] { "*.zip" });
        d.setFilterPath(project.getLocation().toOSString());
        d.setFileName("Debug_AST.zip");
        String zipFilename = d.open();
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename));
            ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
            Set<String> names = parser.getKnownModuleNames();
            for (String name : names) {
                Module module = parser.getModuleByName(name);
                exportDebugAST(out, module);
            }
            out.close();
        } catch (Exception e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Shell(org.eclipse.swt.widgets.Shell) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) Module(org.eclipse.titan.designer.AST.Module) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)72 Module (org.eclipse.titan.designer.AST.Module)51 IFile (org.eclipse.core.resources.IFile)34 ArrayList (java.util.ArrayList)23 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)23 IProject (org.eclipse.core.resources.IProject)19 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)14 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 Identifier (org.eclipse.titan.designer.AST.Identifier)11 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Location (org.eclipse.titan.designer.AST.Location)10 List (java.util.List)9 Reference (org.eclipse.titan.designer.AST.Reference)9 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)9 CoreException (org.eclipse.core.runtime.CoreException)8 TextSelection (org.eclipse.jface.text.TextSelection)8 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7