use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class NewTTCN3ModuleCreationWizardPage method validatePage.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validatePage()
*/
@Override
protected boolean validatePage() {
if (!super.validatePage()) {
return false;
}
final String extension = getContainerFullPath().append(getFileName()).getFileExtension();
if (extension == null) {
// test what will happen if we add the extension
IPath fullPath = getContainerFullPath().append(getFileName()).addFileExtension(GlobalParser.SUPPORTED_TTCN3_EXTENSIONS[1]);
// path is invalid if any prefix is occupied by a file
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
while (fullPath.segmentCount() > 1) {
if (root.getFile(fullPath).exists()) {
setErrorMessage(OCCUPIED);
return false;
}
fullPath = fullPath.removeLastSegments(1);
}
} else {
// test the extension
if (!GlobalParser.isSupportedTTCN3Extension(extension)) {
setErrorMessage(ERROR_MESSAGE);
return false;
}
}
// check modulename
final IPath path = getContainerFullPath();
if (hasLicense && path != null) {
final IFile file = createFileHandle(path.append(getFileName()));
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (projectSourceParser.getLastTimeChecked() == null) {
final WorkspaceJob job = projectSourceParser.analyzeAll();
if (job != null) {
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
}
final String moduleName = getFileName();
final int dotIndex = moduleName.indexOf('.');
final String dotLessModuleName = dotIndex == -1 ? moduleName : moduleName.substring(0, dotIndex);
final Module module = projectSourceParser.getModuleByName(dotLessModuleName);
if (module != null) {
setErrorMessage("A module with the name " + moduleName + " already exists in the project " + file.getProject().getName());
return false;
}
}
return validateName();
}
use of org.eclipse.titan.designer.AST.Module 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.Module in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method handleModuleParameters.
/**
* Selects and reveals the selected module parameter.
*
* @param file
* The current file.
* @param offset
* The position of the cursor.
* @param document
* The document opened in the configuration file editor.
* @return True
*/
public boolean handleModuleParameters(final IFile file, final int offset, final IDocument document) {
ConfigReferenceParser refParser = new ConfigReferenceParser(false);
Reference reference = refParser.findReferenceForOpening(file, offset, document);
if (refParser.isModuleParameter()) {
if (reference == null) {
return false;
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
String exactModuleName = refParser.getExactModuleName();
ArrayList<Assignment> foundAssignments = new ArrayList<Assignment>();
if (exactModuleName != null) {
Module module = projectSourceParser.getModuleByName(exactModuleName);
if (module != null) {
Assignments assignments = module.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
Assignment assignment = assignments.getAssignmentByIndex(i);
if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
foundAssignments.add(assignment);
}
}
}
} else {
for (String moduleName : projectSourceParser.getKnownModuleNames()) {
Module module = projectSourceParser.getModuleByName(moduleName);
if (module != null) {
Assignments assignments = module.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
Assignment assignment = assignments.getAssignmentByIndex(i);
if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
foundAssignments.add(assignment);
}
}
}
}
}
if (foundAssignments.isEmpty()) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTMODULEPARDECLARATION);
return false;
}
// List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
// DeclarationCollectionHelper declaration = null;
Assignment assignment = null;
if (foundAssignments.size() == 1) {
assignment = foundAssignments.get(0);
} else {
Assignment result = openCollectionListDialog(foundAssignments);
if (result != null) {
assignment = result;
}
}
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
for (Assignment tempAssignment : foundAssignments) {
Location location = tempAssignment.getLocation();
TITANDebugConsole.println("Module parameter: " + location.getFile() + ":" + location.getOffset() + "-" + location.getEndOffset());
}
}
if (assignment != null) {
Location location = assignment.getLocation();
selectAndRevealRegion((IFile) location.getFile(), location.getOffset(), location.getEndOffset(), true);
}
return true;
}
return false;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ReferenceSearchQuery method run.
@Override
public IStatus run(final IProgressMonitor monitor) {
result.removeAll();
Map<Module, List<Hit>> map = referenceFinder.findAllReferences(module, project, monitor, false);
for (Map.Entry<Module, List<Hit>> entry : map.entrySet()) {
IResource resource = entry.getKey().getLocation().getFile();
if (!(resource instanceof IFile)) {
continue;
}
for (Hit hit : entry.getValue()) {
result.addMatch(new ReferenceSearchMatch(hit.identifier));
}
}
monitor.done();
return new Status(IStatus.OK, ProductConstants.PRODUCT_ID_DESIGNER, IStatus.OK, "Search done.", null);
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class DefinitionFinder method getDefinitionsOfProject.
private List<Object> getDefinitionsOfProject(final IProject project) {
final List<Object> result = new ArrayList<Object>();
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
if (filter.showOnlyModules()) {
result.addAll(parser.getModules());
} else {
for (Module module : parser.getModules()) {
if (filter.filter(module)) {
result.add(module);
}
for (Assignment ass : module.getAssignments()) {
if (filter.filter(ass)) {
result.add(ass);
}
}
}
}
return result;
}
Aggregations