use of org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceSemanticAnalyzer method analyzeMultipleProjectsSemantically.
/**
* Internal function.
* <p>
* Does the semantic checking of the modules located in multiple projects.
* It is important to call this function after the
* {@link #internalDoAnalyzeSyntactically(IProgressMonitor, CompilationTimeStamp)}
* function was executed on all involved projects, as the out-dated markers will be cleared here.
*
* @param tobeSemanticallyAnalyzed the list of projects to be analyzed.
* @param monitor
* the progress monitor to provide feedback to the user
* about the progress.
* @param compilationCounter
* the timestamp of the actual build cycle.
*
* @return the status of the operation when it finished.
*/
static IStatus analyzeMultipleProjectsSemantically(final List<IProject> tobeSemanticallyAnalyzed, final IProgressMonitor monitor, final CompilationTimeStamp compilationCounter) {
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
if (!tobeSemanticallyAnalyzed.get(i).isAccessible() || !TITANNature.hasTITANNature(tobeSemanticallyAnalyzed.get(i))) {
return Status.CANCEL_STATUS;
}
}
final long semanticCheckStart = System.nanoTime();
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
synchronized (semanticAnalyzer.outdatedModuleMap) {
semanticAnalyzer.outdatedModuleMap.clear();
}
semanticAnalyzer.moduleMap.clear();
}
// Semantic checking starts here
SubMonitor progress = SubMonitor.convert(monitor, 1);
progress.setTaskName("On-the-fly semantic checking of everything ");
progress.subTask("Checking the importations of the modules");
try {
// clean the instantiated parameterized assignments,
// from their instances
Ass_pard.resetAllInstanceCounters();
// check for duplicated module names
HashMap<String, Module> uniqueModules = new HashMap<String, Module>();
Set<String> duplicatedModules = new HashSet<String>();
// collect all modules and semantically checked modules to work on.
final List<Module> allModules = new ArrayList<Module>();
final List<String> semanticallyChecked = new ArrayList<String>();
// remove module name duplication markers. It shall be done before starting the next for-loop!
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
final ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
for (Module module : semanticAnalyzer.fileModuleMap.values()) {
if (module instanceof TTCN3Module) {
MarkerHandler.markAllSemanticMarkersForRemoval(module.getIdentifier());
}
}
}
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
final ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
for (Module module : semanticAnalyzer.fileModuleMap.values()) {
final String name = module.getIdentifier().getName();
allModules.add(module);
// ASN1 modules are not been analyzed incrementally, therefore their markers can be removed in one step:
if (module instanceof ASN1Module) {
MarkerHandler.markAllSemanticMarkersForRemoval(module.getLocation().getFile());
}
if (uniqueModules.containsKey(name)) {
final Location location = uniqueModules.get(name).getIdentifier().getLocation();
final Location location2 = module.getIdentifier().getLocation();
location.reportSemanticError(MessageFormat.format(DUPLICATEMODULE, module.getIdentifier().getDisplayName()));
location2.reportSemanticError(MessageFormat.format(DUPLICATEMODULE, module.getIdentifier().getDisplayName()));
duplicatedModules.add(name);
semanticAnalyzer.semanticallyUptodateModules.remove(name);
} else {
uniqueModules.put(name, module);
semanticAnalyzer.moduleMap.put(name, module);
if (semanticAnalyzer.semanticallyUptodateModules.contains(name)) {
semanticallyChecked.add(name);
}
}
}
}
int nofModulesTobeChecked = 0;
if (allModules.size() > semanticallyChecked.size()) {
// check and build the import hierarchy of the modules
ModuleImportationChain referenceChain = new ModuleImportationChain(CIRCULARIMPORTCHAIN, false);
// remove markers from import lines
for (Module module : allModules) {
if (module instanceof TTCN3Module) {
List<ImportModule> imports = ((TTCN3Module) module).getImports();
for (ImportModule imp : imports) {
MarkerHandler.markAllSemanticMarkersForRemoval(imp.getLocation());
}
}
// markers are removed in one step in ASN1 modules
}
for (Module module : allModules) {
module.checkImports(compilationCounter, referenceChain, new ArrayList<Module>());
referenceChain.clear();
}
progress.subTask("Calculating the list of modules to be checked");
BrokenPartsViaReferences selectionMethod = new BrokenPartsViaReferences(compilationCounter);
SelectionMethodBase selectionMethodBase = (SelectionMethodBase) selectionMethod;
selectionMethodBase.setModules(allModules, semanticallyChecked);
selectionMethod.execute();
if (OutOfMemoryCheck.isOutOfMemory()) {
OutOfMemoryCheck.outOfMemoryEvent();
return Status.CANCEL_STATUS;
}
BrokenPartsChecker brokenPartsChecker = new BrokenPartsChecker(progress.newChild(1), compilationCounter, selectionMethodBase);
brokenPartsChecker.doChecking();
// re-enable the markers on the skipped modules.
for (Module module2 : selectionMethodBase.getModulesToSkip()) {
MarkerHandler.reEnableAllMarkers((IFile) module2.getLocation().getFile());
}
nofModulesTobeChecked = selectionMethodBase.getModulesToCheck().size();
} else {
// re-enable all markers
for (Module module2 : allModules) {
MarkerHandler.reEnableAllMarkers((IFile) module2.getLocation().getFile());
}
}
// Not supported markers are handled here, at the and of checking. Otherwise they would be deleted
final IPreferencesService preferenceService = Platform.getPreferencesService();
final String option = preferenceService.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNSUPPORTEDCONSTRUCTS, GeneralConstants.WARNING, null);
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
// report the unsupported constructs in the project
ProjectSourceSyntacticAnalyzer syntacticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSyntacticAnalyzer();
for (IFile file : syntacticAnalyzer.unsupportedConstructMap.keySet()) {
List<TITANMarker> markers = syntacticAnalyzer.unsupportedConstructMap.get(file);
if (markers != null && file.isAccessible()) {
for (TITANMarker marker : markers) {
Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
location.reportConfigurableSemanticProblem(option, marker.getMessage());
}
}
}
}
if (preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println(" ** Had to start checking at " + nofModulesTobeChecked + " modules. ", stream);
TITANDebugConsole.println(" **On-the-fly semantic checking of projects (" + allModules.size() + " modules) took " + (System.nanoTime() - semanticCheckStart) * (1e-9) + " seconds", stream);
}
progress.subTask("Cleanup operations");
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
synchronized (semanticAnalyzer.semanticallyUptodateModules) {
semanticAnalyzer.semanticallyUptodateModules.clear();
semanticAnalyzer.semanticallyUptodateModules.addAll(semanticAnalyzer.moduleMap.keySet());
for (String name : duplicatedModules) {
semanticAnalyzer.semanticallyUptodateModules.remove(name);
}
}
}
} catch (Exception e) {
// This catch is extremely important, as it is supposed
// to protect the project parser, from whatever might go
// wrong inside the analysis.
ErrorReporter.logExceptionStackTrace(e);
}
progress.done();
for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).setLastTimeChecked(compilationCounter);
ProjectStructureDataCollector collector = GlobalProjectStructureTracker.getDataCollector(tobeSemanticallyAnalyzed.get(i));
for (Module module : GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer().moduleMap.values()) {
collector.addKnownModule(module.getIdentifier());
module.extractStructuralInformation(collector);
}
MarkerHandler.removeAllOnTheFlyMarkedMarkers(tobeSemanticallyAnalyzed.get(i));
}
return Status.OK_STATUS;
}
use of org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
// search
idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
// add the referred identifier to the map of found identifiers
Identifier refdIdentifier = rf.getReferredIdentifier();
Module refdModule = rf.assignment.getMyScope().getModuleScope();
if (idsMap.containsKey(refdModule)) {
idsMap.get(refdModule).add(new Hit(refdIdentifier));
} else {
ArrayList<Hit> identifierList = new ArrayList<Hit>();
identifierList.add(new Hit(refdIdentifier));
idsMap.put(refdModule, identifierList);
}
// scopes
if (rf.fieldId == null) {
// check that in all affected scopes there is no
// definition with the new name
Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
if (rf.scope.getModuleScope() instanceof ASN1Module) {
idType = Identifier_type.ID_ASN;
}
Identifier newId = new Identifier(idType, newIdentifierName);
// check for assignment with given id in all sub-scopes
// of the assignment's scope
// TODO: this does not detect runs on <-> component
// member conflicts because the RunsOnScope is not a
// sub-scope of the ComponentTypeBody scope,
// also it does not go into other modules
Scope rootScope = rf.assignment.getMyScope();
if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
rootScope = rootScope.getParentScope();
}
SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
module.accept(subScopeVisitor);
List<Scope> subScopes = subScopeVisitor.getSubScopes();
subScopes.add(rootScope);
for (Scope ss : subScopes) {
if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(newId));
Reference reference = new Reference(null, subReferences);
Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
if (assignment != null && assignment.getLocation() != null) {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
} else {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
}
// to avoid spam and multiple messages for the same conflict
return result;
}
}
} else {
boolean alreadyExists = false;
// name
if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
} else if (rf.type instanceof TTCN3_Enumerated_Type) {
alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
} else if (rf.type instanceof ASN1_Choice_Type) {
alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Enumerated_Type) {
alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Sequence_Type) {
alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Set_Type) {
alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
}
if (alreadyExists) {
result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module in project titan.EclipsePlug-ins by eclipse.
the class ImportModule method checkImports.
@Override
public /**
* {@inheritDoc}
*/
void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
return;
}
symbols.checkUniqueness(timestamp);
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
if (null == parser || null == identifier) {
lastImportCheckTimeStamp = timestamp;
// FIXME: is it correct? lastImportCheckTimeStamp will be set in extreme case only - very early running
referredModule = null;
return;
}
final Module temp = referredModule;
referredModule = parser.getModuleByName(identifier.getName());
if (temp != referredModule) {
setUnhandledChange(true);
}
if (referredModule == null) {
identifier.getLocation().reportSemanticError(MessageFormat.format(MISSINGMODULE, identifier.getDisplayName()));
} else {
if (!(referredModule instanceof ASN1Module)) {
identifier.getLocation().reportSemanticError(MessageFormat.format(NOTASN1MODULE, identifier.getDisplayName()));
lastImportCheckTimeStamp = timestamp;
referredModule = null;
return;
}
moduleStack.add(referredModule);
if (!referenceChain.add(this)) {
moduleStack.remove(moduleStack.size() - 1);
lastImportCheckTimeStamp = timestamp;
return;
}
referredModule.checkImports(timestamp, referenceChain, moduleStack);
for (int i = 0; i < symbols.size(); i++) {
final Identifier id = symbols.getNthElement(i);
final List<ISubReference> list = new ArrayList<ISubReference>();
list.add(new FieldSubReference(id));
final Defined_Reference reference = new Defined_Reference(null, list);
reference.setLocation(identifier.getLocation());
if (null != referredModule.getAssBySRef(timestamp, reference)) {
if (!((ASN1Module) referredModule).exportsSymbol(timestamp, id)) {
identifier.getLocation().reportSemanticError(MessageFormat.format(SYMBOLNOTEXPORTED, id.getDisplayName(), referredModule.getIdentifier().getDisplayName()));
}
}
}
moduleStack.remove(moduleStack.size() - 1);
}
lastImportCheckTimeStamp = timestamp;
}
use of org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module in project titan.EclipsePlug-ins by eclipse.
the class SpecialASN1Module method createSpecAsss.
/**
* Creates the special assignments by parsing the strings as if they
* were coming from an internal file and creating a module around them.
*
* @return the module of the special assignments created.
*/
private static ASN1Module createSpecAsss() {
if (null != specialAssignmentsModule) {
return specialAssignmentsModule;
}
final ASN1Assignments parsedAssignments = new ASN1Assignments();
ASN1Assignment actualAssignment;
for (String[] assignment : INTERNAL_ASSIGNMENTS) {
actualAssignment = SpecialASN1Module.parseSpecialInternalAssignment(assignment[1], new Identifier(Identifier_type.ID_ASN, assignment[0]));
parsedAssignments.addAssignment(actualAssignment);
}
// null as a project might not be a good idea
specialAssignmentsModule = new ASN1Module(new Identifier(Identifier_type.ID_ASN, INTERNAL_MODULE), null, Tag_types.AUTOMATIC_TAGS, false);
specialAssignmentsModule.setExports(new Exports(true));
specialAssignmentsModule.setImports(new Imports());
specialAssignmentsModule.setAssignments(parsedAssignments);
specialAssignmentsModule.setLocation(NULL_Location.INSTANCE);
specialAssignmentsModule.setScopeName(INTERNAL_MODULE);
final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
specialAssignmentsModule.checkImports(timestamp, referenceChain, new ArrayList<Module>());
specialAssignmentsModule.check(timestamp);
return specialAssignmentsModule;
}
Aggregations