Search in sources :

Example 1 with ConfigReferenceParser

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;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

Example 2 with ConfigReferenceParser

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);
    }
}
Also used : CfgDefinitionInformation(org.eclipse.titan.common.parsers.cfg.CfgDefinitionInformation) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser) ArrayList(java.util.ArrayList) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation)

Example 3 with ConfigReferenceParser

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser)

Aggregations

ConfigReferenceParser (org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser)3 ArrayList (java.util.ArrayList)2 CfgLocation (org.eclipse.titan.common.parsers.cfg.CfgLocation)2 IFile (org.eclipse.core.resources.IFile)1 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)1 CfgDefinitionInformation (org.eclipse.titan.common.parsers.cfg.CfgDefinitionInformation)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 Assignments (org.eclipse.titan.designer.AST.Assignments)1 Location (org.eclipse.titan.designer.AST.Location)1 Module (org.eclipse.titan.designer.AST.Module)1 Reference (org.eclipse.titan.designer.AST.Reference)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1