use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class CycleCheck method process.
@Override
public void process(final IProject project, final Problems problems) {
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<Module> modules = new ArrayList<Module>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
modules.add(projectSourceParser.getModuleByName(moduleName));
}
Collections.sort(modules, new Comparator<Module>() {
@Override
public int compare(final Module o1, final Module o2) {
return o1.getName().compareTo(o2.getName());
}
});
final CycleCheck check = new CycleCheck(modules);
for (final List<Module> cycle : check.cycles) {
final StringBuilder sb = new StringBuilder("Importation cycle detected: ");
for (final Module module : cycle) {
sb.append(module.getName());
sb.append(" -> ");
}
sb.append(cycle.get(0).getName());
final String errMsg = sb.toString();
// Try to find the locations to report, i.e. the import statements.
// We handle only the case of TTCN3Module-s.
final Iterator<Module> it = cycle.iterator();
Module imported = it.next();
Module importer;
while (it.hasNext()) {
importer = it.next();
if (importer instanceof TTCN3Module) {
for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
if (im.getName().equals(imported.getName())) {
problems.report(im.getLocation(), errMsg);
}
}
}
imported = importer;
}
importer = cycle.get(0);
if (importer instanceof TTCN3Module) {
for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
if (im.getName().equals(imported.getName())) {
problems.report(im.getLocation(), errMsg);
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class ReconcilingStrategy method analyze.
public void analyze(final boolean isInitial) {
final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
return;
}
IProject project = editedFile.getProject();
if (project == null) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
getEditor().updateFoldingStructure(positions);
}
});
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
if (isInitial || !editor.isSemanticCheckingDelayed()) {
projectSourceParser.reportOutdating(editedFile);
projectSourceParser.analyzeAll();
WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!MarkerHandler.hasMarker(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, editedFile)) {
getEditor().updateOutlinePage();
}
Module module = projectSourceParser.containedModule(editedFile);
if (module != null && module instanceof TTCN3Module) {
final List<Location> icList = ((TTCN3Module) module).getInactiveCodeLocations();
getEditor().updateInactiveCodeAnnotations(icList);
}
}
});
return Status.OK_STATUS;
}
};
op.setPriority(Job.LONG);
op.setSystem(true);
op.setUser(false);
op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
op.setRule(project);
op.schedule();
} else {
projectSourceParser.reportSyntacticOutdatingOnly(editedFile);
projectSourceParser.analyzeAllOnlySyntactically();
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module 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.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class BrokenPartsChecker method definitionsChecker.
private void definitionsChecker(final Map<Module, List<Assignment>> moduleAndBrokenDefs) {
progress.setTaskName("Semantic check");
progress.setWorkRemaining(moduleAndBrokenDefs.size());
for (Map.Entry<Module, List<Assignment>> entry : moduleAndBrokenDefs.entrySet()) {
final Module module = entry.getKey();
progress.subTask("Semantically checking broken parts in module: " + module.getName());
if (module instanceof TTCN3Module) {
((TTCN3Module) module).checkWithDefinitions(compilationCounter, entry.getValue());
} else {
module.check(compilationCounter);
}
progress.worked(1);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class BrokenPartsViaReferences method processStartModules.
public void processStartModules(final List<Module> startModules, final Map<Module, List<AssignmentHandler>> moduleAndBrokenAssignments) {
for (Module startModule : startModules) {
if (isTooSlow()) {
return;
}
if (startModule instanceof TTCN3Module && startModule.getLastCompilationTimeStamp() != null && !startModule.isCheckRoot()) {
// definition name has not changed but module semantically has not been checked:
final Assignments startAssignments = startModule.getAssignments();
final List<AssignmentHandler> brokens = new ArrayList<AssignmentHandler>();
final List<AssignmentHandler> notBrokens = new ArrayList<AssignmentHandler>();
for (Assignment assignment : startAssignments) {
MarkerHandler.markAllSemanticMarkersForRemoval(assignment);
}
for (int d = 0; d < startAssignments.getNofAssignments(); ++d) {
final Assignment startAssignment = startAssignments.getAssignmentByIndex(d);
final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(startAssignment);
startAssignment.check(timestamp);
startAssignment.accept(assignmentHandler);
if (startAssignment.isCheckRoot()) {
assignmentHandler.setIsInfected(true);
startAssignment.notCheckRoot();
assignmentHandler.addReason("Definition's infected, because of incremental parsing.");
brokens.add(assignmentHandler);
} else if (assignmentHandler.getIsInfected()) {
assignmentHandler.addReason("Definition contains an infected reference.");
brokens.add(assignmentHandler);
} else {
notBrokens.add(assignmentHandler);
}
}
if (!brokens.isEmpty()) {
checkLocalAssignments(brokens, notBrokens);
if (moduleAndBrokenAssignments.containsKey(startModule)) {
moduleAndBrokenAssignments.get(startModule).addAll(brokens);
} else {
moduleAndBrokenAssignments.put(startModule, brokens);
}
}
} else {
if (startModule.getLastCompilationTimeStamp() == null) {
// The markers have been marked for removal only for ASN1 modules
startModule.check(timestamp);
}
// puts additional markers!
final List<AssignmentHandler> startAssignments = getAssignmentsFrom(startModule);
for (AssignmentHandler assignmentHandler : startAssignments) {
assignmentHandler.initStartParts();
assignmentHandler.assignment.notCheckRoot();
assignmentHandler.addReason("Parent module's CompilationTimeStamp is null.");
}
if (moduleAndBrokenAssignments.containsKey(startModule)) {
moduleAndBrokenAssignments.get(startModule).addAll(startAssignments);
} else {
moduleAndBrokenAssignments.put(startModule, startAssignments);
}
}
startModule.notCheckRoot();
}
}
Aggregations