use of org.eclipse.titan.designer.editors.ISemanticTITANEditor in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceParser method analyzeAllOnlySyntactically.
/**
* Analyzes all of the files which are in the project, but only
* syntactically.
* <ul>
* <li>the files possibly needed to analyze are collected first
* <li>those files, which are known to be up-to-date are filtered from
* this list
* <li>the files left in the list are analyzed in a new workspace job
* </ul>
*
* @return the WorkspaceJob in which the operation is running
*/
public WorkspaceJob analyzeAllOnlySyntactically() {
IPreferencesService prefs = Platform.getPreferencesService();
if (!prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
return null;
}
final WorkspaceJob op = new WorkspaceJob(SOURCE_ANALYSING) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
if (!project.isAccessible() || !TITANNature.hasTITANNature(project)) {
syntaxAnalyzersRunning.decrementAndGet();
return Status.CANCEL_STATUS;
}
if (!LicenseValidator.check()) {
syntaxAnalyzersRunning.decrementAndGet();
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
syntaxAnalyzersRunning.decrementAndGet();
return Status.CANCEL_STATUS;
}
final int priority = getThread().getPriority();
try {
getThread().setPriority(Thread.MIN_PRIORITY);
long absoluteStart = System.nanoTime();
IPreferencesService preferenceService = Platform.getPreferencesService();
String compilerOption = preferenceService.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.COMPILERMARKERSAFTERANALYZATION, PreferenceConstantValues.COMPILEROPTIONOUTDATE, null);
if (PreferenceConstantValues.COMPILEROPTIONREMOVE.equals(compilerOption)) {
ParserMarkerSupport.removeAllCompilerMarkers(project);
} else if (PreferenceConstantValues.COMPILEROPTIONOUTDATE.equals(compilerOption)) {
for (Iterator<IFile> iterator = EditorTracker.keyset().iterator(); iterator.hasNext(); ) {
IFile file = iterator.next();
if (file.getProject() == project) {
ISemanticTITANEditor editor = EditorTracker.getEditor(file).get(0);
MarkerHandler.deprecateMarkers(editor, ParserMarkerSupport.getAllCompilerMarkers(project));
}
}
}
syntacticAnalyzer.internalDoAnalyzeSyntactically2(monitor);
boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (reportDebugInformation) {
// MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream(); //only once called
TITANDebugConsole.println("The whole syntax only analysis block took " + (System.nanoTime() - absoluteStart) * (1e-9) + " seconds to complete");
}
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
} finally {
syntaxAnalyzersRunning.decrementAndGet();
getThread().setPriority(priority);
}
return result;
}
};
op.setPriority(Job.LONG);
IPreferencesService preferenceService = Platform.getPreferencesService();
if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
op.setSystem(false);
op.setUser(true);
} else {
op.setSystem(true);
op.setUser(false);
}
op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
op.setRule(getSchedulingRule());
if (syntaxAnalyzersRunning.get() > 0) {
if (lastSyntaxAnalyzes != null && lastSyntaxAnalyzes.getState() != Job.RUNNING) {
lastSyntaxAnalyzes.cancel();
}
}
op.schedule();
lastSyntaxAnalyzes = op;
syntaxAnalyzersRunning.incrementAndGet();
return op;
}
use of org.eclipse.titan.designer.editors.ISemanticTITANEditor in project titan.EclipsePlug-ins by eclipse.
the class ProjectConfigurationParser method fileBasedAnalysis.
/**
* Parses the provided file.
*
* @param file (in) the file to be parsed
* @param aMacros (in/out) collected macro references
* @param aFilesChecked files, which are already processed (there are no duplicates)
* @param aFilesToCheck files, which will be processed (there are no duplicates)
*/
private void fileBasedAnalysis(final IFile file, final List<Macro> aMacros, final List<IFile> aFilesToCheck, final List<IFile> aFilesChecked) {
List<TITANMarker> warnings = null;
List<SyntacticErrorStorage> errorsStored = null;
IDocument document = null;
ISemanticTITANEditor tempEditor = null;
List<ISemanticTITANEditor> editors = null;
if (EditorTracker.containsKey(file)) {
editors = EditorTracker.getEditor(file);
tempEditor = editors.get(0);
document = tempEditor.getDocument();
}
ConfigTextEditor editor = null;
if (tempEditor instanceof ConfigTextEditor) {
editor = (ConfigTextEditor) tempEditor;
}
String oldConfigFilePath = fileMap.get(file);
if (oldConfigFilePath != null) {
fileMap.remove(file);
}
CfgAnalyzer cfgAnalyzer = new CfgAnalyzer();
cfgAnalyzer.parse(file, document == null ? null : document.get());
errorsStored = cfgAnalyzer.getErrorStorage();
final CfgParseResult cfgParseResult = cfgAnalyzer.getCfgParseResult();
if (cfgParseResult != null) {
warnings = cfgParseResult.getWarnings();
aMacros.addAll(cfgParseResult.getMacros());
definitions.putAll(cfgParseResult.getDefinitions());
// add included files to the aFilesToCheck list
final List<String> includeFilenames = cfgParseResult.getIncludeFiles();
for (final String includeFilename : includeFilenames) {
// example value: includeFilename == MyExample2.cfg
// example value: file == L/hw/src/MyExample.cfg
final IPath includeFilePath = PathConverter.getProjectRelativePath(file, includeFilename);
// example value: includeFilePath == src/MyExample2.cfg
if (includeFilePath != null) {
final IFile includeFile = project.getFile(includeFilePath);
// includeFile is null if the file does not exist in the project
if (includeFile != null && !uptodateFiles.containsKey(includeFile) && !aFilesChecked.contains(includeFile) && !aFilesToCheck.contains(includeFile)) {
removeMarkersAndDefinitions(includeFile);
aFilesToCheck.add(includeFile);
}
}
}
if (editor != null && editor.getDocument() != null) {
ConfigEditor parentEditor = editor.getParentEditor();
if (errorsStored == null || errorsStored.isEmpty()) {
parentEditor.setParseTreeRoot(cfgParseResult.getParseTreeRoot());
parentEditor.setTokens(cfgParseResult.getTokens());
parentEditor.refresh(cfgAnalyzer);
parentEditor.setErrorMessage(null);
} else {
if (errorsStored.size() > 1) {
parentEditor.setErrorMessage("There were " + errorsStored.size() + " problems found while parsing");
} else {
parentEditor.setErrorMessage("There was 1 problem found while parsing");
}
}
}
}
fileMap.put(file, file.getFullPath().toOSString());
uptodateFiles.put(file, file.getFullPath().toOSString());
if (document != null) {
GlobalIntervalHandler.putInterval(document, cfgAnalyzer.getRootInterval());
}
if (warnings != null) {
for (TITANMarker marker : warnings) {
if (file.isAccessible()) {
Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
location.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
}
}
}
if (errorsStored != null && !errorsStored.isEmpty()) {
String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
int errorLevel;
if (GeneralConstants.ERROR.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_ERROR;
} else if (GeneralConstants.WARNING.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_WARNING;
} else {
return;
}
for (int i = 0; i < errorsStored.size(); i++) {
ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errorsStored.get(i), errorLevel);
}
}
if (document != null && editors != null) {
ConfigFoldingSupport foldingSupport = new ConfigFoldingSupport();
final IDocument tempDocument = document;
final List<ISemanticTITANEditor> editors2 = editors;
final List<Position> positions = foldingSupport.calculatePositions(tempDocument);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
for (ISemanticTITANEditor editor : editors2) {
editor.updateFoldingStructure(positions);
editor.invalidateTextPresentation();
}
}
});
}
}
use of org.eclipse.titan.designer.editors.ISemanticTITANEditor in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceParser method analyzeAll.
/**
* Analyzes all of the files which are in the project.
* <ul>
* <li>the files possibly needed to analyze are collected first
* <li>those files, which are known to be up-to-date are filtered from
* this list
* <li>the files left in the list are analyzed in a new workspace job
* </ul>
*
* @param allowQuickExit
* if set to true and there is an analysis going on
* already for the same project, the new analysis will
* quit immediately.
* @return the WorkspaceJob in which the operation is running
*/
public WorkspaceJob analyzeAll(final boolean allowQuickExit) {
IPreferencesService prefs = Platform.getPreferencesService();
if (!prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
return null;
}
WorkspaceJob configAnalyzes = GlobalParser.getConfigSourceParser(project).doSyntaticalAnalyze();
WorkspaceJob analyzes = new WorkspaceJob(SOURCE_ANALYSING) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
if (!project.isAccessible() || !TITANNature.hasTITANNature(project)) {
return Status.CANCEL_STATUS;
}
if (!LicenseValidator.check()) {
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final int priority = getThread().getPriority();
try {
getThread().setPriority(Thread.MIN_PRIORITY);
long absoluteStart = System.nanoTime();
IPreferencesService preferenceService = Platform.getPreferencesService();
String compilerOption = preferenceService.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.COMPILERMARKERSAFTERANALYZATION, PreferenceConstantValues.COMPILEROPTIONOUTDATE, null);
if (PreferenceConstantValues.COMPILEROPTIONREMOVE.equals(compilerOption)) {
ParserMarkerSupport.removeAllCompilerMarkers(project);
} else if (PreferenceConstantValues.COMPILEROPTIONOUTDATE.equals(compilerOption)) {
for (Iterator<IFile> iterator = EditorTracker.keyset().iterator(); iterator.hasNext(); ) {
IFile file = iterator.next();
if (file.getProject() == project) {
List<ISemanticTITANEditor> editors = EditorTracker.getEditor(file);
if (editors != null && !editors.isEmpty()) {
ISemanticTITANEditor editor = editors.get(0);
MarkerHandler.deprecateMarkers(editor, ParserMarkerSupport.getAllCompilerMarkers(project));
}
}
}
}
result = internalDoAnalyzeWithReferences(SubMonitor.convert(monitor));
boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (reportDebugInformation) {
// MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream(); //used only once
TITANDebugConsole.println("The whole analysis block took " + (System.nanoTime() - absoluteStart) * (1e-9) + " seconds to complete");
}
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
} finally {
getThread().setPriority(priority);
}
return result;
}
};
analyzes.setPriority(Job.LONG);
IPreferencesService preferenceService = Platform.getPreferencesService();
if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
analyzes.setSystem(false);
analyzes.setUser(true);
} else {
analyzes.setSystem(true);
analyzes.setUser(false);
}
analyzes.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
final ISchedulingRule rule = getSchedulingRule();
analyzes.setRule(rule);
if (fullAnalyzersRunning.get() > 0) {
if (lastFullAnalyzes != null && lastFullAnalyzes.getState() != Job.RUNNING) {
lastFullAnalyzes.cancel();
}
lastFullAnalyzes = analyzes;
}
analyzes.schedule();
fullAnalyzersRunning.incrementAndGet();
final WorkspaceJob temp = analyzes;
final WorkspaceJob temp2 = configAnalyzes;
WorkspaceJob extensions = new WorkspaceJob("Executing Titan extensions") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
final SubMonitor progress = SubMonitor.convert(monitor, 100);
final int priortity = getThread().getPriority();
try {
getThread().setPriority(Thread.MIN_PRIORITY);
progress.setTaskName("Executing Titan extensions");
progress.subTask("Waiting for semantic analysis");
try {
temp.join();
temp2.join();
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
}
progress.subTask("Executing extensions");
if (Status.OK_STATUS.equals(temp.getResult())) {
ExtensionHandler.INSTANCE.executeContributors(progress.newChild(100), project);
}
} finally {
progress.done();
fullAnalyzersRunning.decrementAndGet();
getThread().setPriority(priortity);
}
return Status.OK_STATUS;
}
};
if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
extensions.setSystem(false);
extensions.setUser(true);
} else {
extensions.setSystem(true);
extensions.setUser(false);
}
extensions.setRule(rule);
extensions.schedule();
return extensions;
}
use of org.eclipse.titan.designer.editors.ISemanticTITANEditor in project titan.EclipsePlug-ins by eclipse.
the class PreprocessedTokenStream method processIncludeDirective.
/**
* Adds a new lexer to the lexer stack to read tokens from the included
* file
*
* @param fileName
* the file name paramtere of the #include directive
*/
private void processIncludeDirective(final PreprocessorDirective ppDirective) {
if (ppDirective.str == null || "".equals(ppDirective.str)) {
TITANMarker marker = new TITANMarker("File name was not provided", ppDirective.line, -1, -1, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL);
unsupportedConstructs.add(marker);
return;
}
IFile includedFile = GlobalParser.getProjectSourceParser(actualFile.getProject()).getTTCN3IncludeFileByName(ppDirective.str);
if (includedFile == null) {
TITANMarker marker = new TITANMarker(MessageFormat.format("Included file `{0}'' could not be found", ppDirective.str), ppDirective.line, -1, -1, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL);
unsupportedConstructs.add(marker);
return;
}
// check extension
if (!GlobalParser.TTCNIN_EXTENSION.equals(includedFile.getFileExtension())) {
TITANMarker marker = new TITANMarker(MessageFormat.format("File `{0}'' does not have the `{1}'' extension", ppDirective.str, GlobalParser.TTCNIN_EXTENSION), ppDirective.line, -1, -1, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL);
warnings.add(marker);
}
// check if the file is already loaded into an editor
String code = null;
if (EditorTracker.containsKey(includedFile)) {
List<ISemanticTITANEditor> editors = EditorTracker.getEditor(includedFile);
ISemanticTITANEditor editor = editors.get(0);
IDocument document = editor.getDocument();
code = document.get();
}
// create lexer and set it up
Reader reader = null;
CharStream charStream = null;
Ttcn3Lexer lexer = null;
int rootInt;
if (code != null) {
reader = new StringReader(code);
charStream = new UnbufferedCharStream(reader);
lexer = new Ttcn3Lexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
rootInt = code.length();
} else {
try {
InputStreamReader temp = new InputStreamReader(includedFile.getContents());
if (!includedFile.getCharset().equals(temp.getEncoding())) {
try {
temp.close();
} catch (IOException e) {
ErrorReporter.logWarningExceptionStackTrace(e);
}
temp = new InputStreamReader(includedFile.getContents(), includedFile.getCharset());
}
reader = new BufferedReader(temp);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
} catch (UnsupportedEncodingException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
charStream = new UnbufferedCharStream(reader);
lexer = new Ttcn3Lexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
lexerListener = new TitanListener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
IFileStore store;
try {
store = EFS.getStore(includedFile.getLocationURI());
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
IFileInfo fileInfo = store.fetchInfo();
rootInt = (int) fileInfo.getLength();
}
lexer.setTokenFactory(new CommonTokenFactory(true));
lexer.setTTCNPP();
lexer.initRootInterval(rootInt);
lexer.setActualFile(includedFile);
// add the lexer to the stack of lexers
tokenStreamStack.push(new TokenStreamData(lexer, includedFile, reader));
if (parser != null) {
parser.setActualFile(includedFile);
}
includedFiles.add(includedFile);
}
Aggregations