Search in sources :

Example 6 with Module

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

the class Macro_Value method evaluateMacro.

/**
 * Evaluates the value of the macro.
 *
 * @param expectedValue the kind of the value to be expected
 *
 * @return the actual or the evaluated value
 */
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    lastTimeChecked = timestamp;
    lastValue = this;
    switch(value) {
        case MODULEID:
            if (myScope != null && myScope.getModuleScope() != null) {
                final Module module = myScope.getModuleScope();
                if (module.getIdentifier() != null) {
                    lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
                    lastValue.copyGeneralProperties(this);
                }
            }
            break;
        case DEFINITIONID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition != null) {
                        lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                        lastValue.copyGeneralProperties(this);
                    }
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case TESTCASEID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition == null) {
                        location.reportSemanticError(TESCASEIDINCONTROLPART);
                        setIsErroneous(true);
                    } else {
                        if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                            // folding is possible in testcases only
                            lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                            lastValue.copyGeneralProperties(this);
                        }
                    }
                } else {
                    location.reportSemanticError(TESTCASEIDNOTALLOWED);
                    setIsErroneous(true);
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case FILENAME:
        case BFILENAME:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(location.getFile().getName());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case FILEPATH:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                String canonicalPath;
                final IPath absolutePath = location.getFile().getLocation();
                if (absolutePath == null) {
                    location.reportSemanticError(UNDETERMINABLEPATH);
                    canonicalPath = location.getFile().getName();
                    setIsErroneous(true);
                } else {
                    final File file = absolutePath.toFile();
                    try {
                        canonicalPath = file.getCanonicalPath();
                    } catch (IOException e) {
                        location.reportSemanticError(UNDETERMINABLEPATH);
                        canonicalPath = location.getFile().getName();
                        setIsErroneous(true);
                    }
                }
                lastValue = new Charstring_Value(canonicalPath);
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(Long.toString(location.getLine()));
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER_C:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Integer_Value(location.getLine());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case SCOPE:
            if (myScope != null) {
                lastValue = new Charstring_Value(myScope.getScopeMacroName());
                lastValue.copyGeneralProperties(this);
            } else {
                location.reportSemanticError(UNDETERMINABLESCOPE);
                setIsErroneous(true);
            }
            break;
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IOException(java.io.IOException) Module(org.eclipse.titan.designer.AST.Module) File(java.io.File) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 7 with Module

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

the class ProjectSourceCompiler method generateParallelMain.

// FIXME comment
public static void generateParallelMain(final IProject project, final Collection<Module> modules, final boolean aDebug) throws CoreException {
    IFolder folder = project.getFolder(DIR_GENERATED_ROOT);
    IFile file = folder.getFile("Parallel_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_Parallel_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 Parallel_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_Parallel_main.parallelMain(args);\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 8 with Module

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

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

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

the class ImportModule method addProposal.

// FIXME ezeket sem teszteltuk
@Override
public /**
 * {@inheritDoc}
 */
void addProposal(final ProposalCollector propCollector, final Identifier targetModuleId) {
    final List<ISubReference> subrefs = propCollector.getReference().getSubreferences();
    if (propCollector.getReference().getModuleIdentifier() == null && subrefs.size() == 1) {
        propCollector.addProposal(identifier, ImageCache.getImage(getOutlineIcon()), KIND);
    }
    final Module savedReferredModule = referredModule;
    if (savedReferredModule != null) {
        final Assignments assignments = savedReferredModule.getAssignments();
        for (int i = 0, size = assignments.getNofAssignments(); i < size; i++) {
            final Assignment temporalAssignment = assignments.getAssignmentByIndex(i);
            if (savedReferredModule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, temporalAssignment)) {
                temporalAssignment.addProposal(propCollector, 0);
            }
        }
        if (savedReferredModule instanceof TTCN3Module) {
            final TTCN3Module ttcnmodule = (TTCN3Module) savedReferredModule;
            final List<ImportModule> imports = ttcnmodule.getImports();
            for (final ImportModule importation : imports) {
                if (importation.getVisibilityModifier() == VisibilityModifier.Public) {
                    importation.addProposal(propCollector, targetModuleId);
                } else if (importation.getVisibilityModifier() == VisibilityModifier.Friend) {
                    // The import is the friendly one
                    if (ttcnmodule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, importation)) {
                        importation.addProposal(propCollector, targetModuleId);
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module)

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