use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class AddImport method run.
@Override
public void run(final IAction action) {
TITANDebugConsole.println("Add import called: ");
if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
return;
}
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.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((TTCN3Editor) targetEditor).getCarretOffset();
}
DeclarationCollector declarationCollector = OpenDeclarationHelper.findVisibleDeclarations(targetEditor, new TTCN3ReferenceParser(false), ((TTCN3Editor) targetEditor).getDocument(), offset, false);
if (declarationCollector == null) {
return;
}
List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
if (collected.isEmpty()) {
// FIXME add semantic check guard on project level.
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
for (String moduleName2 : projectSourceParser.getKnownModuleNames()) {
Module module2 = projectSourceParser.getModuleByName(moduleName2);
if (module2 != null) {
// Visit each file in the project one by
// one instead of
// "module2.getAssignments().addDeclaration(declarationCollector)".
Assignments assignments = module2.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
assignments.getAssignmentByIndex(i).addDeclaration(declarationCollector, 0);
}
}
}
if (declarationCollector.getCollectionSize() == 0) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTTTCN3DECLARATION);
return;
}
if (reportDebugInformation) {
TITANDebugConsole.println("Elements were only found in not visible modules");
}
DeclarationCollectionHelper resultToInsert = null;
if (collected.size() == 1) {
resultToInsert = collected.get(0);
} else {
OpenDeclarationLabelProvider labelProvider = new OpenDeclarationLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
dialog.setTitle("Add Import");
dialog.setMessage("Choose element to generate an import statement for.");
dialog.setElements(collected.toArray());
if (dialog.open() == Window.OK) {
if (reportDebugInformation) {
TITANDebugConsole.getConsole().newMessageStream().println("Selected: " + dialog.getFirstResult());
}
resultToInsert = (DeclarationCollectionHelper) dialog.getFirstResult();
}
}
if (resultToInsert == null) {
return;
}
IFile newfile = (IFile) resultToInsert.location.getFile();
Module newModule = projectSourceParser.containedModule(newfile);
if (newModule == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage("Could not identify the module in file " + newfile.getName());
return;
}
String ttcnName = newModule.getIdentifier().getTtcnName();
TITANDebugConsole.println("the new module to insert: " + ttcnName);
final IFile actualFile = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
Module actualModule = projectSourceParser.containedModule(actualFile);
int insertionOffset = ((TTCN3Module) actualModule).getAssignmentsScope().getLocation().getOffset() + 1;
MultiTextEdit multiEdit = new MultiTextEdit(insertionOffset, 0);
RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(((TTCN3Editor) targetEditor).getDocument(), multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
multiEdit.addChild(new InsertEdit(insertionOffset, "\nimport from " + ttcnName + " all;\n"));
try {
processor.performEdits();
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
} else {
if (reportDebugInformation) {
for (DeclarationCollectionHelper foundDeclaration : collected) {
TITANDebugConsole.println("declaration:" + foundDeclaration.location.getFile() + ": " + foundDeclaration.location.getOffset() + " - " + foundDeclaration.location.getEndOffset() + " is available");
}
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(null, "Study feature", "Adding a missing importation is still under study");
}
});
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ImportModule method checkImports.
@Override
public /**
* {@inheritDoc}
*/
void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
return;
}
symbols.checkUniqueness(timestamp);
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
if (null == parser || null == identifier) {
lastImportCheckTimeStamp = timestamp;
// FIXME: is it correct? lastImportCheckTimeStamp will be set in extreme case only - very early running
referredModule = null;
return;
}
final Module temp = referredModule;
referredModule = parser.getModuleByName(identifier.getName());
if (temp != referredModule) {
setUnhandledChange(true);
}
if (referredModule == null) {
identifier.getLocation().reportSemanticError(MessageFormat.format(MISSINGMODULE, identifier.getDisplayName()));
} else {
if (!(referredModule instanceof ASN1Module)) {
identifier.getLocation().reportSemanticError(MessageFormat.format(NOTASN1MODULE, identifier.getDisplayName()));
lastImportCheckTimeStamp = timestamp;
referredModule = null;
return;
}
moduleStack.add(referredModule);
if (!referenceChain.add(this)) {
moduleStack.remove(moduleStack.size() - 1);
lastImportCheckTimeStamp = timestamp;
return;
}
referredModule.checkImports(timestamp, referenceChain, moduleStack);
for (int i = 0; i < symbols.size(); i++) {
final Identifier id = symbols.getNthElement(i);
final List<ISubReference> list = new ArrayList<ISubReference>();
list.add(new FieldSubReference(id));
final Defined_Reference reference = new Defined_Reference(null, list);
reference.setLocation(identifier.getLocation());
if (null != referredModule.getAssBySRef(timestamp, reference)) {
if (!((ASN1Module) referredModule).exportsSymbol(timestamp, id)) {
identifier.getLocation().reportSemanticError(MessageFormat.format(SYMBOLNOTEXPORTED, id.getDisplayName(), referredModule.getIdentifier().getDisplayName()));
}
}
}
moduleStack.remove(moduleStack.size() - 1);
}
lastImportCheckTimeStamp = timestamp;
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ASN1Module method getAssBySRef.
@Override
public /**
* {@inheritDoc}
*/
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
Identifier moduleId = reference.getModuleIdentifier();
final Identifier id = reference.getId();
if (null == id) {
return null;
}
Module module = null;
if (null == moduleId || moduleId.getName().equals(identifier.getName())) {
if (assignments.hasLocalAssignmentWithID(timestamp, id)) {
return assignments.getLocalAssignmentByID(timestamp, id);
}
if (null != moduleId) {
id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENT, id.getDisplayName(), identifier.getDisplayName()));
return null;
}
if (imports.singularImportedSymbols_map.containsKey(id.getName())) {
module = imports.singularImportedSymbols_map.get(id.getName());
moduleId = module.getIdentifier();
imports.getImportedModuleById(moduleId).setUsedForImportation();
} else if (imports.pluralImportedSymbols.contains(id.getName())) {
id.getLocation().reportSemanticError(MessageFormat.format(MORESYMBOLS, id.getDisplayName(), identifier.getDisplayName()));
return null;
} else {
id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENTORSYMBOL, id.getDisplayName(), identifier.getDisplayName()));
return null;
}
}
if (null == module) {
if (!imports.hasImportedModuleWithId(moduleId)) {
moduleId.getLocation().reportSemanticError(MessageFormat.format(NOIMPORTEDMODULE, moduleId.getDisplayName()));
return null;
}
if (!imports.getImportedModuleById(moduleId).hasSymbol(id)) {
id.getLocation().reportSemanticError(MessageFormat.format(NOSYMBOLSIMPORTED, id.getDisplayName(), moduleId.getDisplayName()));
return null;
}
imports.getImportedModuleById(moduleId).setUsedForImportation();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
if (null == parser) {
return null;
}
module = parser.getModuleByName(moduleId.getName());
}
if (this == module || null == module) {
return null;
}
final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
newSubreferences.add(new FieldSubReference(id));
final Defined_Reference finalReference = new Defined_Reference(null, newSubreferences);
// FIXME add semantic check guard on project level.
return module.getAssBySRef(timestamp, finalReference);
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class TITANJavaBuilder method build.
@Override
protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor) throws CoreException {
IProject project = getProject();
if (!TITANInstallationValidator.check(true)) {
return project.getReferencedProjects();
}
if (!LicenseValidator.check()) {
return project.getReferencedProjects();
}
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
final boolean reportDebugInformation = store.getBoolean(PreferenceConstants.DISPLAYDEBUGINFORMATION);
final SubMonitor progress = SubMonitor.convert(monitor);
progress.beginTask("Build", 2);
ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
// TODO: this is temporary code!
sourceParser.makefileCreatingAnalyzeAll();
progress.worked(1);
BuildTimestamp timestamp = BuildTimestamp.getNewBuildCounter();
IProgressMonitor codeGeneratorMonitor = progress.newChild(1);
codeGeneratorMonitor.beginTask("Checking prerequisites", sourceParser.getModules().size() + 1);
for (Module module : sourceParser.getModules()) {
TITANDebugConsole.println("Generating code for module `" + module.getIdentifier().getDisplayName() + "'");
try {
ProjectSourceCompiler.compile(timestamp, module, reportDebugInformation);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("While generating Java code for module " + module.getIdentifier().getDisplayName(), e);
}
codeGeneratorMonitor.worked(1);
}
TITANDebugConsole.println("Generating code for single main");
try {
ProjectSourceCompiler.generateSingleMain(project, sourceParser.getModules(), reportDebugInformation);
ProjectSourceCompiler.generateParallelMain(project, sourceParser.getModules(), reportDebugInformation);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While generating Java code for main module ", e);
}
codeGeneratorMonitor.worked(1);
codeGeneratorMonitor.done();
return new IProject[0];
}
Aggregations