Search in sources :

Example 1 with ProposalCollector

use of org.eclipse.titan.designer.editors.ProposalCollector in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    ASN1ReferenceParser refParser = new ASN1ReferenceParser();
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    if (tempModule != null) {
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    TemplateContextType contextType = new TemplateContextType(ASN1CodeSkeletons.CONTEXT_IDENTIFIER, ASN1CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_ASN, ASN1CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    if (scope != null) {
        scope.addProposal(propCollector);
        propCollector.sortTillMarked();
        propCollector.markPosition();
    }
    if (ref.getSubreferences().size() != 1) {
        return propCollector.getCompletitions();
    }
    if (scope == null) {
        propCollector.addProposal(CodeScanner.TAGS, null, KEYWORD);
    } else {
        ASN1CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    propCollector.addProposal(CodeScanner.VERBS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.COMPARE_TYPES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STATUS_TYPE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STORAGE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.MODIFIER, null, KEYWORD);
    propCollector.addProposal(CodeScanner.ACCESS_TYPE, null, KEYWORD);
    propCollector.sortTillMarked();
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 2 with ProposalCollector

use of org.eclipse.titan.designer.editors.ProposalCollector in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    if (editor == null) {
        return new ICompletionProposal[] {};
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return new ICompletionProposal[] {};
    }
    IDocument doc = viewer.getDocument();
    TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    String moduleName = null;
    if (tempModule != null) {
        moduleName = tempModule.getName();
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    propCollector.setProjectParser(projectSourceParser);
    if (moduleName == null) {
        // rootless behavior
        if (ref.getModuleIdentifier() == null) {
            Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
            Module module;
            for (String name : moduleNames) {
                module = projectSourceParser.getModuleByName(name);
                if (module != null) {
                    propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
                    module.getAssignments().addProposal(propCollector);
                }
            }
        } else {
            Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
            if (module != null) {
                module.getAssignments().addProposal(propCollector);
            }
        }
    } else {
        /*
			 * search for the best scope in the module's scope
			 * hierarchy and call proposal adding function on the
			 * found scope instead of what can be found here
			 */
        if (scope != null) {
            scope.addProposal(propCollector);
        }
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getSubreferences().size() != 1) {
        if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
            propCollector.sortAll();
        }
        return propCollector.getCompletitions();
    }
    Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    for (String knownModuleName : knownModuleNames) {
        Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
        Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
        propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getModuleIdentifier() == null) {
        if (scope == null) {
            TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        } else {
            scope.addSkeletonProposal(propCollector);
        }
        propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.sortTillMarked();
        propCollector.markPosition();
        TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        if (scope == null) {
            TTCN3Keywords.addKeywordProposals(propCollector);
        } else {
            scope.addKeywordProposal(propCollector);
        }
        propCollector.sortTillMarked();
        propCollector.markPosition();
    } else {
        if (scope == null || !(scope instanceof StatementBlock)) {
            if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
                propCollector.sortAll();
            }
            return propCollector.getCompletitions();
        }
        String fakeModule = ref.getModuleIdentifier().getName();
        if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
            Component_Type.addAnyorAllProposal(propCollector, 0);
        } else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
            PortTypeBody.addAnyorAllProposal(propCollector, 0);
        } else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
            Timer.addAnyorAllProposal(propCollector, 0);
        }
    }
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Template(org.eclipse.jface.text.templates.Template) ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 3 with ProposalCollector

use of org.eclipse.titan.designer.editors.ProposalCollector in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    int ofs = findWordStart(offset, doc);
    String incompleteString = "";
    try {
        if (doc != null && offset >= ofs) {
            incompleteString = doc.get(ofs, offset - ofs);
        }
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    String[] reference = incompleteString.trim().split(REFERENCE_SPLITTER, -1);
    Reference ref = new Reference(null);
    ref.setLocation(new Location(file, 0, 0, offset - ofs));
    FieldSubReference subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[0]));
    subref.setLocation(new Location(file, 0, 0, reference[0].length()));
    ref.addSubReference(subref);
    if (reference.length > 1) {
        subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[1]));
        subref.setLocation(new Location(file, 0, reference[0].length() + 1, offset - ofs));
        ref.addSubReference(subref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, ofs);
    TTCN3CodeSkeletons.addSkeletonProposals(doc, offset, propCollector);
    TTCN3Keywords.addKeywordProposals(propCollector);
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Example 4 with ProposalCollector

use of org.eclipse.titan.designer.editors.ProposalCollector in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    int ofs = findWordStart(offset, doc);
    String incompleteString = "";
    try {
        if (doc != null && offset >= ofs) {
            incompleteString = doc.get(ofs, offset - ofs);
        }
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    String[] reference = incompleteString.trim().split(REFERENCE_SPLITTER, -1);
    Reference ref = new Reference(null);
    ref.setLocation(new Location(file, 0, 0, offset - ofs));
    FieldSubReference subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[0]));
    subref.setLocation(new Location(file, 0, 0, reference[0].length()));
    ref.addSubReference(subref);
    if (reference.length > 1) {
        subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[1]));
        subref.setLocation(new Location(file, 0, reference[0].length() + 1, offset - ofs));
        ref.addSubReference(subref);
    }
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, doc, ref, ofs);
    propCollector.addProposal(CodeScanner.SECTION_TITLES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.MASK_OPTIONS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.EXTERNAL_COMMAND_TYPES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.OPTIONS, null, KEYWORD);
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

IFile (org.eclipse.core.resources.IFile)4 IDocument (org.eclipse.jface.text.IDocument)4 Reference (org.eclipse.titan.designer.AST.Reference)4 ProposalCollector (org.eclipse.titan.designer.editors.ProposalCollector)4 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Location (org.eclipse.titan.designer.AST.Location)2 Module (org.eclipse.titan.designer.AST.Module)2 Scope (org.eclipse.titan.designer.AST.Scope)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 Template (org.eclipse.jface.text.templates.Template)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)1