use of org.eclipse.titan.common.parsers.SyntacticErrorStorage 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();
}
}
});
}
}
Aggregations