use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class OutlinePage method getModule.
private Module getModule() {
final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
return null;
}
// FIXME add semantic check guard on project level.
ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(file.getProject());
return sourceParser.containedModule(file);
}
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(getDocument());
getEditor().updateFoldingStructure(positions);
}
});
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
if (isInitial || !TTCN3Editor.isSemanticCheckingDelayed()) {
if (!isInitial) {
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();
}
}
});
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 ReconcilingStrategy method reconcileSemantics.
/**
* Activates reconciling of the semantic meanings.
*/
public void reconcileSemantics() {
final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
return;
}
final WorkspaceJob tempLastIncrementalSyntaxCheck = lastIncrementalSyntaxCheck;
if (tempLastIncrementalSyntaxCheck != null) {
try {
tempLastIncrementalSyntaxCheck.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
IProject project = editedFile.getProject();
if (project == null) {
return;
}
TITANDebugConsole.println("Reconciling semantics at " + System.nanoTime() + " time.");
ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
sourceParser.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().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();
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class TTCN3Editor method analyzeOpenedFile.
/**
* Analyze or reanalyze the file opened in the current editor in case of semantic check is delayed.
* <p>
* It is necessary if
* <p> - if the file is just saved OR
* <p> - if the file is just opened and therefore it contain just partial semantic check information
* (This is the case when functionality "minimized memory usage" is switched on)
*
* @param jobname The name of the workspace job
* @param file the file being saved
* @author Kristof Szabados
*/
private void analyzeOpenedFile(final String jobname, final IFile file) {
if (file != null && TTCN3Editor.isSemanticCheckingDelayed()) {
final IReconcilingStrategy strategy = reconciler.getReconcilingStrategy(IDocument.DEFAULT_CONTENT_TYPE);
if (strategy instanceof ReconcilingStrategy) {
WorkspaceJob op = new WorkspaceJob(jobname) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
if (reconciler.isIncrementalReconciler()) {
((ReconcilingStrategy) strategy).reconcileSemantics();
} else {
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
projectSourceParser.reportOutdating(file);
((ReconcilingStrategy) 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 ChangeCreator method createFileChange.
/**
* Creates the {@link #change} object, which contains all the inserted and edited texts
* in the selected resources.
*/
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
//
// collect functions
Set<Definition> funcs;
final FunctionCollector vis = new FunctionCollector();
if (defSelection == null) {
module.accept(vis);
funcs = vis.getResult();
} else {
if (defSelection instanceof Def_Function || defSelection instanceof Def_Testcase) {
// TODO any other possibilities for the type of 'defSelection'?
funcs = new HashSet<Definition>();
funcs.add(defSelection);
} else {
ErrorReporter.logError("Variable scope reduction called for " + defSelection.getIdentifier().getDisplayName() + ", but it is only supported for functions and testcases. ");
return null;
}
}
// create edits
final List<Edit> allEdits = new ArrayList<Edit>();
for (Definition def : funcs) {
final List<Edit> edits = analyzeFunction(def);
if (edits == null) {
continue;
}
allEdits.addAll(edits);
}
if (allEdits.isEmpty()) {
return null;
}
final String fileContents = loadFileContent(toVisit);
// create text edits
//
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
// TODO this is an O(n^2) algorithm
// merge overlapping DeleteEdits
// used, when removing all parts of a multi-declaration statement:
// the DeleteEdit for removing the last part covers all the DeleteEdits for the other parts
// WARNING merging edits might make debugging more difficult, since the overlapping edit errors are avoided
final List<TextEdit> allTes = new LinkedList<TextEdit>();
// collect processed (insert) edits with their created insert edit
final Map<Edit, InsertEdit> editsDone = new HashMap<Edit, InsertEdit>();
for (Edit e : allEdits) {
final TextEdit[] tes = createTextEdit(toVisit, fileContents, e, editsDone);
for (TextEdit te : tes) {
if (!(te instanceof DeleteEdit)) {
allTes.add(te);
// System.err.println("$ nonde added: " + te.getOffset() + "-" + te.getExclusiveEnd());
continue;
}
DeleteEdit dte = (DeleteEdit) te;
final ListIterator<TextEdit> it = allTes.listIterator();
while (it.hasNext()) {
final TextEdit currTe = it.next();
if (!(currTe instanceof DeleteEdit)) {
continue;
}
final DeleteEdit currDte = (DeleteEdit) currTe;
// if the new edit (dte) overlaps currDte, merge them
if (doesDeleteEditsOverlap(dte, currDte)) {
// System.err.println("$ de removed: " + currDte.getOffset() + "-" + currDte.getExclusiveEnd());
it.remove();
dte = mergeDeleteEdits(dte, currDte);
// System.err.println("$ merged des: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
}
}
// System.err.println("$ de added: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
allTes.add(dte);
}
}
Collections.reverse(allTes);
for (TextEdit te : allTes) {
rootEdit.addChild(te);
}
return tfc;
}
Aggregations