use of org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser 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.editors.configeditor.ConfigReferenceParser in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method handleDefinitions.
/**
* Jumps to the definition of the constant selected by the user.
*
* @param file
* The current file.
* @param offset
* The position of the cursor.
* @param document
* The document opened in the configuration file editor.
*/
public void handleDefinitions(final IFile file, final int offset, final IDocument document) {
ConfigReferenceParser refParser = new ConfigReferenceParser(false);
refParser.findReferenceForOpening(file, offset, document);
String definitionName = refParser.getDefinitionName();
if (definitionName == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTDEFINITION);
return;
}
List<ConfigDeclarationCollectionHelper> collected = new ArrayList<ConfigDeclarationCollectionHelper>();
Map<String, CfgDefinitionInformation> definitions = GlobalParser.getConfigSourceParser(file.getProject()).getAllDefinitions();
CfgDefinitionInformation definition = definitions.get(definitionName);
if (definition != null) {
List<CfgLocation> locations = definition.getLocations();
for (CfgLocation location : locations) {
collected.add(new ConfigDeclarationCollectionHelper(definitionName, location));
}
} else {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTCONSTANTDEFINITION);
return;
}
if (collected.isEmpty()) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTCONSTANTDEFINITION);
return;
}
ConfigDeclarationCollectionHelper declaration = null;
if (collected.size() == 1) {
declaration = collected.get(0);
} else {
Object result = openCollectionListDialog(collected);
if (result != null) {
declaration = (ConfigDeclarationCollectionHelper) result;
}
}
if (declaration != null) {
selectAndRevealRegion(declaration.location.getFile(), declaration.location.getOffset(), declaration.location.getEndOffset(), true);
}
}
use of org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method handleIncludes.
/**
* Opens the included configuration file selected by the user.
*
* @param file
* The current file.
* @param offset
* The position of the cursor.
* @param document
* The document opened in the configuration file editor.
*/
public void handleIncludes(final IFile file, final int offset, final IDocument document) {
ConfigReferenceParser refParser = new ConfigReferenceParser(false);
String include = refParser.findIncludedFileForOpening(offset, document);
if (include == null || include.length() == 0) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(WRONGSELECTION);
return;
}
IFile fileToOpen = file.getProject().getFile(include);
if (fileToOpen == null || !fileToOpen.exists()) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(FILENOTFOUND, include));
return;
}
selectAndRevealRegion(fileToOpen, -1, -1, false);
}
Aggregations