use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class OccurencesMarker method doMark.
private void doMark(final IDocument document, final int offset) {
IAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel == null) {
removeOccurences(false);
error(document, offset, "AnnotationModel is null");
return;
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
removeOccurences(false);
error(document, offset, "can not determine the file in the editor.");
return;
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (projectSourceParser == null) {
removeOccurences(false);
error(document, offset, "Can not find the projectsourceparser for the project: " + file.getProject());
return;
}
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
removeOccurences(false);
error(document, offset, "The module can not be found in the project.");
return;
}
if (printASTElem.getValue()) {
ASTLocationChainVisitor locVisitor = new ASTLocationChainVisitor(offset);
module.accept(locVisitor);
locVisitor.printChain();
}
final Reference reference = getReferenceParser().findReferenceForOpening(file, offset, document);
if (reference == null) {
removeOccurences(false);
// "The reference can not be parsed.");
return;
}
final Location referenceLocaton = reference.getLocation();
if (referenceLocaton.getOffset() == referenceLocaton.getEndOffset()) {
removeOccurences(false);
return;
}
// if (reportDebugInformation) {
// ASTLocationConsistencyVisitor visitor = new
// ASTLocationConsistencyVisitor(document,
// module.get_moduletype()==Module.module_type.TTCN3_MODULE);
// module.accept(visitor);
// }
final List<Hit> result = findOccurrences(document, reference, module, offset);
if (result.isEmpty()) {
return;
}
Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
for (Hit hit : result) {
if (hit.identifier != null) {
int hitOffset = hit.identifier.getLocation().getOffset();
int hitEndOffset = hit.identifier.getLocation().getEndOffset();
if (hitOffset >= 0 && hitEndOffset >= 0 && hitEndOffset >= hitOffset) {
final Annotation annotationToAdd = new Annotation(ANNOTATION_TYPE, false, hit.identifier.getDisplayName());
final Position position = new Position(hitOffset, hitEndOffset - hitOffset);
annotationMap.put(annotationToAdd, position);
}
}
}
synchronized (getLockObject(annotationModel)) {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(occurrenceAnnotations, annotationMap);
} else {
if (occurrenceAnnotations != null) {
for (Annotation annotationToRemove : occurrenceAnnotations) {
annotationModel.removeAnnotation(annotationToRemove);
}
}
for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
occurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class T3Doc method getCommentStringBasedOnReference.
public static String getCommentStringBasedOnReference(final DeclarationCollector declarationCollector, final List<DeclarationCollectionHelper> collected, final IEditorPart targetEditor, final IRegion hoverRegion, final IReferenceParser referenceParser, final ITextViewer textViewer) {
if (!T3Doc.isT3DocEnable()) {
return null;
}
Reference ref = declarationCollector.getReference();
if (ref == null) {
return null;
}
if ((ref.getMyScope() instanceof NamedBridgeScope || ref.getMyScope() instanceof FormalParameterList) && !collected.isEmpty()) {
DeclarationCollectionHelper declaration = collected.get(0);
if (declaration.node instanceof TTCN3_Sequence_Type || declaration.node instanceof FormalParameter) {
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
Assignment ass = tempModule.getEnclosingAssignment(hoverRegion.getOffset());
if (ass != null) {
Reference reference = referenceParser.findReferenceForOpening(file, hoverRegion.getOffset(), textViewer.getDocument());
String str = reference.getDisplayName();
List<String> al = T3Doc.getCommentStrings(ass.getCommentLocation(), str);
if (!al.isEmpty()) {
final StringBuilder sb = new StringBuilder();
for (String string : al) {
sb.append(string);
}
return sb.toString();
}
}
}
}
return null;
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ASN1Editor method doSave.
@Override
public void doSave(final IProgressMonitor progressMonitor) {
final IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
if (file != null) {
FileSaveTracker.fileBeingSaved(file);
}
super.doSave(progressMonitor);
if (file != null && isSemanticCheckingDelayed()) {
final WorkspaceJob op = new WorkspaceJob("Reconciliation on save") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
projectSourceParser.reportOutdating(file);
strategy.analyze(true);
return Status.OK_STATUS;
}
};
op.setPriority(Job.LONG);
op.setSystem(true);
op.setUser(false);
op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
op.schedule();
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
if (targetEditor == null || !(targetEditor instanceof ASN1Editor)) {
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;
}
if (ResourceExclusionHelper.isExcluded(file)) {
MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
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 = ((ASN1Editor) targetEditor).getCarretOffset();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
// TODO: How could this happen??? (NPE occured)
return;
}
IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
return;
}
selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method runAction.
/**
* Helper function used by RenameRefactoringAction classes for TTCN-3,
* ASN.1 and TTCNPP editors
*/
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
statusLineManager.setErrorMessage(null);
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
statusLineManager.setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
statusLineManager.setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
final IPreferencesService prefs = Platform.getPreferencesService();
final 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.getConsole().newMessageStream().println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
}
// run semantic analysis to have up-to-date AST
// FIXME: it does not work for incremental parsing
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final WorkspaceJob job = projectSourceParser.analyzeAll();
if (job == null) {
if (reportDebugInformation) {
TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring: WorkspaceJob to analyze project could not be created.");
}
return;
}
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
// find the module
if (ResourceExclusionHelper.isExcluded(file)) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
return;
}
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
statusLineManager.setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
return;
}
ReferenceFinder rf = findOccurrencesLocationBased(module, offset);
if (rf == null) {
rf = new ReferenceFinder();
boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
if (!isDetected) {
return;
}
}
RenameRefactoring renameRefactoring = new RenameRefactoring(file, module, rf);
RenameRefactoringWizard renameWizard = new RenameRefactoringWizard(renameRefactoring);
RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(renameWizard);
try {
operation.run(targetEditor.getEditorSite().getShell(), "");
} catch (InterruptedException irex) {
// operation was canceled
if (reportDebugInformation) {
TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring has been cancelled");
}
} finally {
// ===================================
// === Re-analysis after renaming ====
// ===================================
Map<Module, List<Hit>> changed = rf.findAllReferences(module, file.getProject(), null, reportDebugInformation);
final Set<Module> modules = new HashSet<Module>();
modules.add(module);
modules.addAll(changed.keySet());
reanalyseAstAfterRefactoring(file.getProject(), modules);
}
}
Aggregations