use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ContentAssistProcessor method computeCompletionProposals.
// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
if (editor == null) {
return new ICompletionProposal[] {};
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
return new ICompletionProposal[] {};
}
IDocument doc = viewer.getDocument();
TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
if (ref == null || ref.getSubreferences().isEmpty()) {
return new ICompletionProposal[] {};
}
Scope scope = null;
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
Module tempModule = projectSourceParser.containedModule(file);
String moduleName = null;
if (tempModule != null) {
moduleName = tempModule.getName();
scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
ref.setMyScope(scope);
ref.detectModid();
}
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("parsed the reference: " + ref);
}
TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
propCollector.setProjectParser(projectSourceParser);
if (moduleName == null) {
// rootless behavior
if (ref.getModuleIdentifier() == null) {
Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
Module module;
for (String name : moduleNames) {
module = projectSourceParser.getModuleByName(name);
if (module != null) {
propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
module.getAssignments().addProposal(propCollector);
}
}
} else {
Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
if (module != null) {
module.getAssignments().addProposal(propCollector);
}
}
} else {
/*
* search for the best scope in the module's scope
* hierarchy and call proposal adding function on the
* found scope instead of what can be found here
*/
if (scope != null) {
scope.addProposal(propCollector);
}
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getSubreferences().size() != 1) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
for (String knownModuleName : knownModuleNames) {
Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getModuleIdentifier() == null) {
if (scope == null) {
TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
} else {
scope.addSkeletonProposal(propCollector);
}
propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.sortTillMarked();
propCollector.markPosition();
TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
if (scope == null) {
TTCN3Keywords.addKeywordProposals(propCollector);
} else {
scope.addKeywordProposal(propCollector);
}
propCollector.sortTillMarked();
propCollector.markPosition();
} else {
if (scope == null || !(scope instanceof StatementBlock)) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
String fakeModule = ref.getModuleIdentifier().getName();
if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
Component_Type.addAnyorAllProposal(propCollector, 0);
} else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
PortTypeBody.addAnyorAllProposal(propCollector, 0);
} else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
Timer.addAnyorAllProposal(propCollector, 0);
}
}
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ReconcilingStrategy method reconcile.
@Override
public void reconcile(final DirtyRegion dirtyRegion, final IRegion subRegion) {
if (editor == null || document == null) {
return;
}
int lineBreaks = 0;
try {
if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
actualCode.insert(dirtyRegion.getOffset(), dirtyRegion.getText());
lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(dirtyRegion.getText(), document.getLegalLineDelimiters());
} else {
lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(actualCode.substring(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength()), document.getLegalLineDelimiters());
actualCode.delete(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength());
}
} catch (StringIndexOutOfBoundsException e) {
ErrorReporter.logExceptionStackTrace(e);
ErrorReporter.logError("String length: " + actualCode.length() + " region type: " + dirtyRegion.getType() + " region offset: " + dirtyRegion.getOffset() + " region length: " + dirtyRegion.getLength() + " region text: '" + dirtyRegion.getText() + "'\n" + "Actual size of the document: " + document.get().length());
actualCode = new StringBuilder(document.get());
}
if (dirtyRegion.getOffset() == 0 && document.getLength() == dirtyRegion.getLength()) {
// thing
if (!editor.isDirty()) {
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
analyze(false);
}
return;
}
int firstLine;
try {
firstLine = document.getLineOfOffset(dirtyRegion.getOffset());
} catch (BadLocationException e) {
ErrorReporter.logWarningExceptionStackTrace(e);
firstLine = 0;
}
final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (editedFile == null) {
return;
}
final TTCN3ReparseUpdater reparser;
int length = dirtyRegion.getLength();
if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset(), length);
} else {
reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, -1 * lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset() + length, -1 * length);
}
final IProject project = editedFile.getProject();
if (project == null) {
return;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
sourceParser.updateSyntax(editedFile, reparser);
if (!editor.isSemanticCheckingDelayed()) {
sourceParser.analyzeAll();
WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
editor.updateFoldingStructure(positions);
editor.refreshOutlinePage();
}
});
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 {
sourceParser.reportSyntacticOutdatingOnly(editedFile);
sourceParser.analyzeAllOnlySyntactically();
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser 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.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
if (targetEditor == null || !(targetEditor instanceof TTCNPPEditor)) {
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 = ((TTCNPPEditor) targetEditor).getCarretOffset();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("Can not find the module.");
}
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 OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
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;
}
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 instanceof TextSelection && !selection.isEmpty() && !"".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();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
if (timestamp == null) {
TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
} else {
TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
}
}
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());
return;
}
Aggregations