Search in sources :

Example 71 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser 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)

Example 72 with ProjectSourceParser

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

the class ProjectAnalyzerJob method runInWorkspace.

/**
 * Runs the operation, which actually starts an other job for analyzing the
 * specified project. Before joining and after joining this analyzer job one
 * can execute operations by overriding the appropriate methods.
 */
@Override
public final IStatus runInWorkspace(final IProgressMonitor monitor) {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    if (project == null) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Project not specified for ProjectAnalyzerJob");
    }
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    final WorkspaceJob job = parser.analyzeAll();
    if (job == null) {
        // maybe parsing is disabled
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                final Display disp = Display.getDefault();
                final Shell shell = new Shell(disp, SWT.SHELL_TRIM);
                shell.setText("Unavailable operation");
                final String errorMessage = "This operation can not be executed while project parsing is disabled.\n\n" + "Please enable parsing on the preference page: Window/Preferences/ TITAN Preferences/" + "On-the-fly checker/ Enable parsing of TTCN-3, ASN.1 and Runtime Configuration files";
                MessageDialog.openInformation(shell, "Confronting settings", errorMessage);
            }
        });
        return Status.CANCEL_STATUS;
    }
    final IStatus preStatus = doPreWork(progress.newChild(20));
    progress.setWorkRemaining(80);
    if (!preStatus.isOK()) {
        return preStatus;
    }
    try {
        job.join();
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace("Error while analyzing", e);
    }
    progress.setWorkRemaining(30);
    return doPostWork(progress.newChild(30));
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) IStatus(org.eclipse.core.runtime.IStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Display(org.eclipse.swt.widgets.Display)

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