Search in sources :

Example 56 with Location

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

the class StatementBlock method registerDefinition.

/**
 * Registers a definition (for example new variable) into the list of
 * definitions available in this statement block.
 *
 * Please note, that this is done while the semantic check is happening,
 * as it must not be allowed to reach definitions not yet defined.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param definition
 *                the definition to register.
 */
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
    if (definition == null) {
        return;
    }
    final Identifier identifier = definition.getIdentifier();
    if (identifier == null) {
        return;
    }
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(3);
    }
    final String definitionName = identifier.getName();
    if (definitionMap.containsKey(definitionName)) {
        if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
            final Location otherLocation = definitionMap.get(definitionName).getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        }
    } else {
        definitionMap.put(definitionName, definition);
        if (parentScope != null && definition.getLocation() != null) {
            if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                definition.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName()));
                final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(identifier));
                final Reference reference = new Reference(null, subReferences);
                final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                if (assignment != null && assignment.getLocation() != null) {
                    assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                }
            } else if (parentScope.isValidModuleId(identifier)) {
                definition.getLocation().reportSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 57 with Location

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

the class OutputAnalyzer method addTITANMarker.

/**
 * Places a Marker on the right place.
 * <p>
 * how it works:
 * <ul>
 * <li>first it searches in the files map to find the right resource to
 * a file name.
 * <li>if no such resource can be found, but the project is available,
 * then the marker will be placed on the project.
 * <li>tries to put the marker on the right place. With errors coming
 * from pre-processed files, it can happen that their column number
 * point to full wrong, or not even existing positions.
 *
 * </ul>
 *
 * Please note that the textFileBufferManagers are created only once for
 * every file resource, their disconnection is done in the dispose()
 * method.
 *
 * @see #dispose()
 *
 * @param fileName
 *                the file name
 * @param startLineNumber
 *                the line number of the beginning of the error or
 *                <code>0</code>
 * @param startOffset
 *                the offset of the beginning of the error in line given
 *                by startLineNumber or <code>-1</code>
 * @param endLineNumber
 *                the line number of of the ending of the error or
 *                equals startLineNumber
 * @param endOffset
 *                the offset of the end of the error in line given by
 *                endLineNumber or <code>-1</code>
 * @param type
 *                the type of the message: can be error / warning / note
 * @param message
 *                the text of the error.
 *
 * @return whether it was successful or not
 */
private boolean addTITANMarker(final String fileName, final int startLineNumber, final int startOffset, final int endLineNumber, final int endOffset, final String type, final String message) {
    IResource resource = null;
    if (files.containsKey(fileName)) {
        resource = files.get(fileName);
    } else {
        boolean found = false;
        final IPath filePath = new Path(fileName);
        final String lastSegment = filePath.lastSegment();
        if (files.containsKey(lastSegment)) {
            resource = files.get(lastSegment);
            found = true;
        }
        if (!found) {
            for (IFile file2 : files.values()) {
                final IPath path2 = file2.getProject().getLocation().append(fileName);
                final String temp = path2.toOSString();
                if (files.containsKey(temp)) {
                    resource = files.get(temp);
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            for (IFile file2 : files.values()) {
                final IPath workingDir = ProjectBasedBuilder.getProjectBasedBuilder(file2.getProject()).getWorkingDirectoryPath(true);
                if (workingDir != null) {
                    final IPath path2 = workingDir.append(fileName);
                    final String temp = path2.toOSString();
                    if (files.containsKey(temp)) {
                        resource = files.get(temp);
                        found = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            final URI workingDirUri = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryURI(true);
            if (workingDirUri != null) {
                final URI uri2 = URIUtil.append(workingDirUri, fileName);
                final IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
                final IFile[] results = wroot.findFilesForLocationURI(uri2);
                if (results != null && results.length > 0) {
                    resource = results[0];
                    found = true;
                }
            }
        }
    }
    Location location = null;
    if (resource == null || !resource.isAccessible()) {
        if (project != null && project.isAccessible()) {
            location = new Location(project);
            if (ERROR.equals(type)) {
                location.reportExternalProblem(message.trim(), IMarker.SEVERITY_ERROR, GeneralConstants.COMPILER_ERRORMARKER);
            } else {
                location.reportExternalProblem(message.trim(), IMarker.SEVERITY_WARNING, GeneralConstants.COMPILER_WARNINGMARKER);
            }
            processedErrorMessages = true;
            return true;
        }
        return false;
    }
    try {
        if (startLineNumber > 0 && startOffset != -1 && endOffset != -1) {
            IDocument document = null;
            if (documentMap.containsKey(resource)) {
                document = documentMap.get(resource);
            } else {
                final ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
                final IPath fullPath = resource.getFullPath();
                if (manager != null) {
                    manager.connect(fullPath, LocationKind.IFILE, null);
                    final ITextFileBuffer buffer = manager.getTextFileBuffer(fullPath, LocationKind.IFILE);
                    document = buffer.getDocument();
                    documentMap.put(resource, document);
                    filesOpened.add(fullPath);
                }
            }
            try {
                if (document != null && endLineNumber < document.getNumberOfLines() && document.getLineLength(startLineNumber - 1) > startOffset && document.getLineLength(endLineNumber - 1) >= endOffset) {
                    location = new Location(resource, startLineNumber, document.getLineOffset(startLineNumber - 1) + startOffset - 1, document.getLineOffset(endLineNumber - 1) + endOffset);
                }
            } catch (BadLocationException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
        }
        if (location == null) {
            location = new Location(resource, startLineNumber);
        }
        if (ERROR.equals(type)) {
            location.reportExternalProblem(message, IMarker.SEVERITY_ERROR, GeneralConstants.COMPILER_ERRORMARKER);
        } else {
            location.reportExternalProblem(message, IMarker.SEVERITY_WARNING, GeneralConstants.COMPILER_WARNINGMARKER);
        }
        processedErrorMessages = true;
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) URI(java.net.URI) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Example 58 with Location

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

the class ProjectBasedBuilder method checkCodeSplittingEquality.

/**
 * Checks whether the code splitting modes are the same in the referred projects as splitting mode in the current project.
 * If difference was found, compilation error marker is placed on the current project
 * @return true if the splitting modes are the same, otherwise false
 */
public boolean checkCodeSplittingEquality() {
    final Location location = new Location(project);
    String codeSplitting = "";
    boolean errorFound = false;
    StringBuilder wrongProjects = new StringBuilder();
    wrongProjects.append("Code splitting setting failure in project(s): ");
    try {
        codeSplitting = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.CODE_SPLITTING_PROPERTY));
        if (codeSplitting == null) {
            ErrorReporter.logError("Code splitting value is not set for " + project.getName());
            return false;
        }
        String tempCodeSplitting;
        final IProject[] projects = getReferencedProjects();
        for (IProject tempProject : projects) {
            if (tempProject.isAccessible()) {
                tempCodeSplitting = tempProject.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.CODE_SPLITTING_PROPERTY));
                if (!codeSplitting.equals(tempCodeSplitting)) {
                    ErrorReporter.logError("Code splitting error found in project " + tempProject.getName() + "; Project " + project.getName() + " expected " + codeSplitting + ", got " + tempCodeSplitting);
                    if (errorFound != false) {
                        wrongProjects.append(',');
                    }
                    ;
                    wrongProjects.append(tempProject.getName());
                    errorFound = true;
                }
            } else {
                ErrorReporter.logError("This referenced project is not accessible:" + tempProject);
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    if (errorFound) {
        wrongProjects.append("; Project ").append(project.getName()).append(" expected ").append(codeSplitting);
        location.reportExternalProblem(wrongProjects.toString(), IMarker.SEVERITY_ERROR, GeneralConstants.COMPILER_ERRORMARKER);
        return false;
    } else {
        return true;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) IProject(org.eclipse.core.resources.IProject) Location(org.eclipse.titan.designer.AST.Location)

Example 59 with Location

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

the class FindDefinitionAction method showInEditor.

private void showInEditor(final ILocateableNode node) {
    final Location location = node.getLocation();
    final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
    if (desc == null) {
        TITANDebugConsole.println("Cannot find the editor");
        return;
    }
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        final IEditorPart editorPart = activePage.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
        if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
            ((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace("Error while opening the editor", e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Location(org.eclipse.titan.designer.AST.Location)

Example 60 with Location

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

the class ImportSelectionDialog method findReferenceInProject.

/**
 * Try to find the declaration of the reference in any module of the
 * project.
 * <p>
 * If exactly one declaration is found, then its location is returned. If
 * multiple modules contain a valid declaration of the reference, then a
 * dialog is displayed to the user to choose one. If none found, or the user
 * cancels the dialog, <code>null</code> is returned.
 * </p>
 *
 * @param reference
 *            The (missing) reference we are searching for.
 * @param project
 *            The project in which we search the declaration.
 * @return The location of the declaration, if uniquely found,
 *         <code>null</code> otherwise.
 */
public static Location findReferenceInProject(final Reference reference, final IProject project) {
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final List<DeclarationCollectionHelper> collected = new ArrayList<DeclarationCollectionHelper>();
    final Identifier identifier = reference.getId();
    for (final String moduleName : projectSourceParser.getKnownModuleNames()) {
        final Module m = projectSourceParser.getModuleByName(moduleName);
        if (m != null && m.getAssignments().hasLocalAssignmentWithID(CompilationTimeStamp.getBaseTimestamp(), identifier)) {
            Assignment assignment = m.getAssignments().getLocalAssignmentByID(CompilationTimeStamp.getBaseTimestamp(), identifier);
            if (assignment != null) {
                collected.add(new DeclarationCollectionHelper(assignment.getProposalDescription(), assignment.getIdentifier().getLocation(), assignment));
            }
        }
    }
    Location loc = null;
    if (collected.size() > 1) {
        final List<String> files = new ArrayList<String>();
        for (final DeclarationCollectionHelper c : collected) {
            files.add(c.location.getFile().getName());
        }
        TITANDebugConsole.println("Multiple possible imports for " + reference.getDisplayName() + ": " + files.toString());
        final ImportSelectionDialog dialog = new ImportSelectionDialog(reference, collected, reference.getLocation().getFile());
        Display.getDefault().syncExec(dialog);
        loc = dialog.getSelected();
    } else if (collected.size() == 1) {
        DeclarationCollectionHelper declaration = collected.get(0);
        loc = declaration.location;
        TITANDebugConsole.println("Exactly one module for " + reference.getDisplayName() + " is found: " + loc.getFile().getName());
    } else {
        TITANDebugConsole.println("No imports for " + reference.getDisplayName() + " is found");
    }
    return loc;
}
Also used : DeclarationCollectionHelper(org.eclipse.titan.designer.editors.actions.DeclarationCollectionHelper) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7