Search in sources :

Example 11 with ProjectSourceParser

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

the class ProjectHandlingLibrary method analyzeProject.

/**
 * Starts the analysis of its project and waits until it finishes.
 */
public void analyzeProject() {
    LOGGER.info("Analyzing project: " + project.getName());
    ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    WorkspaceJob semanticInfoCleanerJob = sourceParser.clearSemanticInformation();
    try {
        semanticInfoCleanerJob.join();
    } catch (InterruptedException e1) {
        ErrorReporter.logExceptionStackTrace("", e1);
    }
    GlobalParser.clearAllInformation();
    LOGGER.info("Semantic analysis started on: " + project.getName());
    WorkspaceJob job = sourceParser.analyzeAll();
    for (int i = 0; i < 10 && job == null; ++i) {
        try {
            Thread.sleep(500);
            job = sourceParser.analyzeAll();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("", e);
        }
    }
    if (job != null) {
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("", e);
        }
    } else {
        LOGGER.severe("Couldn't analyze the project");
    }
    LOGGER.info("Semantic analysis finished on: " + project.getName());
    try {
        // Wait for the markers to show up
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace("", e);
    }
    LOGGER.info("Project analyzed: " + project.getName());
}
Also used : WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 12 with ProjectSourceParser

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

the class ReferenceSearch method runAction.

/**
 * Helper function used by FindReferences classes for TTCN-3, ASN.1 and
 * TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // find the module
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    final ReferenceFinder rf = new ReferenceFinder();
    boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
    if (!isDetected) {
        return;
    }
    final ReferenceSearchQuery query = new ReferenceSearchQuery(rf, module, file.getProject());
    for (ISearchQuery runningQuery : NewSearchUI.getQueries()) {
        NewSearchUI.cancelQuery(runningQuery);
    }
    NewSearchUI.runQueryInBackground(query);
}
Also used : IFile(org.eclipse.core.resources.IFile) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) TextSelection(org.eclipse.jface.text.TextSelection) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 13 with ProjectSourceParser

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

the class NewTTCN3ModuleCreationWizardPage method validatePage.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validatePage()
	 */
@Override
protected boolean validatePage() {
    if (!super.validatePage()) {
        return false;
    }
    final String extension = getContainerFullPath().append(getFileName()).getFileExtension();
    if (extension == null) {
        // test what will happen if we add the extension
        IPath fullPath = getContainerFullPath().append(getFileName()).addFileExtension(GlobalParser.SUPPORTED_TTCN3_EXTENSIONS[1]);
        // path is invalid if any prefix is occupied by a file
        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        while (fullPath.segmentCount() > 1) {
            if (root.getFile(fullPath).exists()) {
                setErrorMessage(OCCUPIED);
                return false;
            }
            fullPath = fullPath.removeLastSegments(1);
        }
    } else {
        // test the extension
        if (!GlobalParser.isSupportedTTCN3Extension(extension)) {
            setErrorMessage(ERROR_MESSAGE);
            return false;
        }
    }
    // check modulename
    final IPath path = getContainerFullPath();
    if (hasLicense && path != null) {
        final IFile file = createFileHandle(path.append(getFileName()));
        final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        if (projectSourceParser.getLastTimeChecked() == null) {
            final WorkspaceJob job = projectSourceParser.analyzeAll();
            if (job != null) {
                try {
                    job.join();
                } catch (InterruptedException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
            }
        }
        final String moduleName = getFileName();
        final int dotIndex = moduleName.indexOf('.');
        final String dotLessModuleName = dotIndex == -1 ? moduleName : moduleName.substring(0, dotIndex);
        final Module module = projectSourceParser.getModuleByName(dotLessModuleName);
        if (module != null) {
            setErrorMessage("A module with the name " + moduleName + " already exists in the project " + file.getProject().getName());
            return false;
        }
    }
    return validateName();
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 14 with ProjectSourceParser

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

the class OpenDeclaration method handleModuleParameters.

/**
 * Selects and reveals the selected module parameter.
 *
 * @param file
 *                The current file.
 * @param offset
 *                The position of the cursor.
 * @param document
 *                The document opened in the configuration file editor.
 * @return True
 */
public boolean handleModuleParameters(final IFile file, final int offset, final IDocument document) {
    ConfigReferenceParser refParser = new ConfigReferenceParser(false);
    Reference reference = refParser.findReferenceForOpening(file, offset, document);
    if (refParser.isModuleParameter()) {
        if (reference == null) {
            return false;
        }
        ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        String exactModuleName = refParser.getExactModuleName();
        ArrayList<Assignment> foundAssignments = new ArrayList<Assignment>();
        if (exactModuleName != null) {
            Module module = projectSourceParser.getModuleByName(exactModuleName);
            if (module != null) {
                Assignments assignments = module.getAssignments();
                for (int i = 0; i < assignments.getNofAssignments(); i++) {
                    Assignment assignment = assignments.getAssignmentByIndex(i);
                    if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                        foundAssignments.add(assignment);
                    }
                }
            }
        } else {
            for (String moduleName : projectSourceParser.getKnownModuleNames()) {
                Module module = projectSourceParser.getModuleByName(moduleName);
                if (module != null) {
                    Assignments assignments = module.getAssignments();
                    for (int i = 0; i < assignments.getNofAssignments(); i++) {
                        Assignment assignment = assignments.getAssignmentByIndex(i);
                        if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                            foundAssignments.add(assignment);
                        }
                    }
                }
            }
        }
        if (foundAssignments.isEmpty()) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTMODULEPARDECLARATION);
            return false;
        }
        // List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
        // DeclarationCollectionHelper declaration = null;
        Assignment assignment = null;
        if (foundAssignments.size() == 1) {
            assignment = foundAssignments.get(0);
        } else {
            Assignment result = openCollectionListDialog(foundAssignments);
            if (result != null) {
                assignment = result;
            }
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            for (Assignment tempAssignment : foundAssignments) {
                Location location = tempAssignment.getLocation();
                TITANDebugConsole.println("Module parameter: " + location.getFile() + ":" + location.getOffset() + "-" + location.getEndOffset());
            }
        }
        if (assignment != null) {
            Location location = assignment.getLocation();
            selectAndRevealRegion((IFile) location.getFile(), location.getOffset(), location.getEndOffset(), true);
        }
        return true;
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

Example 15 with ProjectSourceParser

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

the class ReconcilingStrategy method analyze.

void analyze() {
    final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return;
    }
    IProject project = file.getProject();
    if (project == null) {
        return;
    }
    ProjectConfigurationParser projectConfigurationParser = GlobalParser.getConfigSourceParser(project);
    projectConfigurationParser.reportOutdating(file);
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    projectSourceParser.analyzeAll();
}
Also used : ProjectConfigurationParser(org.eclipse.titan.designer.parsers.ProjectConfigurationParser) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

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