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;
}
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));
}
Aggregations