Search in sources :

Example 76 with Module

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

the class TITANJavaBuilder method build.

@Override
protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor) throws CoreException {
    IProject project = getProject();
    if (!TITANInstallationValidator.check(true)) {
        return project.getReferencedProjects();
    }
    if (!LicenseValidator.check()) {
        return project.getReferencedProjects();
    }
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    final boolean reportDebugInformation = store.getBoolean(PreferenceConstants.DISPLAYDEBUGINFORMATION);
    final SubMonitor progress = SubMonitor.convert(monitor);
    progress.beginTask("Build", 2);
    ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    // TODO: this is temporary code!
    sourceParser.makefileCreatingAnalyzeAll();
    progress.worked(1);
    BuildTimestamp timestamp = BuildTimestamp.getNewBuildCounter();
    IProgressMonitor codeGeneratorMonitor = progress.newChild(1);
    codeGeneratorMonitor.beginTask("Checking prerequisites", sourceParser.getModules().size() + 1);
    for (Module module : sourceParser.getModules()) {
        TITANDebugConsole.println("Generating code for module `" + module.getIdentifier().getDisplayName() + "'");
        try {
            ProjectSourceCompiler.compile(timestamp, module, reportDebugInformation);
        } catch (Exception e) {
            ErrorReporter.logExceptionStackTrace("While generating Java code for module " + module.getIdentifier().getDisplayName(), e);
        }
        codeGeneratorMonitor.worked(1);
    }
    TITANDebugConsole.println("Generating code for single main");
    try {
        ProjectSourceCompiler.generateSingleMain(project, sourceParser.getModules(), reportDebugInformation);
        ProjectSourceCompiler.generateParallelMain(project, sourceParser.getModules(), reportDebugInformation);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("While generating Java code for main module ", e);
    }
    codeGeneratorMonitor.worked(1);
    codeGeneratorMonitor.done();
    return new IProject[0];
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) BuildTimestamp(org.eclipse.titan.designer.compiler.BuildTimestamp) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Module(org.eclipse.titan.designer.AST.Module) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) CoreException(org.eclipse.core.runtime.CoreException)

Example 77 with Module

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

the class ProjectSourceCompiler method generateSingleMain.

// FIXME comment
public static void generateSingleMain(final IProject project, final Collection<Module> modules, final boolean aDebug) throws CoreException {
    IFolder folder = project.getFolder(DIR_GENERATED_ROOT);
    IFile file = folder.getFile("Single_main.java");
    createDir(folder);
    StringBuilder contentBuilder = new StringBuilder();
    contentBuilder.append("// This Java file was generated by the TITAN Designer eclipse plug-in\n");
    contentBuilder.append("// of the TTCN-3 Test Executor version ").append(GeneralConstants.VERSION_STRING).append('\n');
    contentBuilder.append("// for (").append(System.getProperty("user.name")).append('@');
    try {
        contentBuilder.append(InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
        contentBuilder.append("unknown");
    }
    // TODO date will need to be simplified to have optimize build time
    // aSb.append(") on ").append(new Date()).append('\n');
    contentBuilder.append(")\n");
    contentBuilder.append('\n');
    contentBuilder.append("// ").append(GeneralConstants.COPYRIGHT_STRING).append('\n');
    contentBuilder.append('\n');
    contentBuilder.append("// Do not edit this file unless you know what you are doing.\n");
    contentBuilder.append('\n');
    contentBuilder.append("package ");
    contentBuilder.append(PACKAGE_GENERATED_ROOT);
    contentBuilder.append(";\n\n");
    contentBuilder.append(MessageFormat.format("import {0}.Module_List;\n", PACKAGE_RUNTIME_ROOT));
    contentBuilder.append(MessageFormat.format("import {0}.Runtime_Single_main;\n", PACKAGE_RUNTIME_ROOT));
    for (Module module : modules) {
        contentBuilder.append(MessageFormat.format("import {0}.{1};\n", PACKAGE_GENERATED_ROOT, module.getIdentifier().getName()));
    }
    contentBuilder.append("public class Single_main {\n\n");
    contentBuilder.append("public static void main( String[] args ) {\n");
    contentBuilder.append("long absoluteStart = System.nanoTime();\n");
    for (Module module : modules) {
        contentBuilder.append(MessageFormat.format("Module_List.add_module(new {0}());\n", module.getIdentifier().getName()));
    }
    contentBuilder.append("Runtime_Single_main.singleMain();\n");
    contentBuilder.append("System.out.println(\"Total execution took \" + (System.nanoTime() - absoluteStart) * (1e-9) + \" seconds to complete\");\n");
    contentBuilder.append("}\n");
    contentBuilder.append("}\n\n");
    final String content = contentBuilder.toString();
    if (file.exists()) {
        if (needsUpdate(file, content.toString())) {
            final InputStream outputStream = new ByteArrayInputStream(content.getBytes());
            file.setContents(outputStream, IResource.FORCE | IResource.KEEP_HISTORY, null);
        }
    } else {
        final InputStream outputStream = new ByteArrayInputStream(content.getBytes());
        file.create(outputStream, IResource.FORCE, null);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) UnknownHostException(java.net.UnknownHostException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Module(org.eclipse.titan.designer.AST.Module) IFolder(org.eclipse.core.resources.IFolder)

Example 78 with Module

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

the class BrokenPartsChecker method doChecking.

public void doChecking() {
    monitor.subTask("Semantic checking");
    final BrokenPartsViaReferences brokenParts = (BrokenPartsViaReferences) selectionMethod;
    if (brokenParts.getAnalyzeOnlyDefinitions()) {
        final Map<Module, List<Assignment>> moduleAndBrokenDefinitions = brokenParts.getModuleAndBrokenDefs();
        definitionsChecker(moduleAndBrokenDefinitions);
    } else {
        generalChecker();
    }
    monitor.subTask("Doing post semantic checks");
    for (Module module : selectionMethod.getModulesToCheck()) {
        module.postCheck();
    }
    progress.done();
}
Also used : List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 79 with Module

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

the class BrokenPartsChecker method generalChecker.

// TODO check if this can be merged with the following one
private void generalChecker() {
    progress.setTaskName("Semantic check");
    progress.setWorkRemaining(selectionMethod.getModulesToCheck().size());
    for (Module module : selectionMethod.getModulesToSkip()) {
        module.setSkippedFromSemanticChecking(true);
    }
    for (Module module : selectionMethod.getModulesToCheck()) {
        module.setSkippedFromSemanticChecking(false);
    }
    // process the modules one-by-one
    for (final Module module : selectionMethod.getModulesToCheck()) {
        progress.subTask("Semantically checking module: " + module.getName());
        module.check(compilationCounter);
        progress.worked(1);
    }
    for (final Module module : selectionMethod.getModulesToSkip()) {
        module.setSkippedFromSemanticChecking(false);
    }
}
Also used : Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 80 with Module

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

the class BrokenPartsChecker method definitionsChecker.

private void definitionsChecker(final Map<Module, List<Assignment>> moduleAndBrokenDefs) {
    progress.setTaskName("Semantic check");
    progress.setWorkRemaining(moduleAndBrokenDefs.size());
    for (Map.Entry<Module, List<Assignment>> entry : moduleAndBrokenDefs.entrySet()) {
        final Module module = entry.getKey();
        progress.subTask("Semantically checking broken parts in module: " + module.getName());
        if (module instanceof TTCN3Module) {
            ((TTCN3Module) module).checkWithDefinitions(compilationCounter, entry.getValue());
        } else {
            module.check(compilationCounter);
        }
        progress.worked(1);
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Map(java.util.Map)

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