All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bogieclj.molecule.mods.ishell.DomainOperationsCompleter Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
/*
 * Copyright 2019 Vijayakumar Mohan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.bogieclj.molecule.mods.ishell;

import org.jline.reader.Candidate;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
import com.github.bogieclj.molecule.system.services.DomainService;

import java.util.List;
import java.util.Stack;

class DomainOperationsCompleter implements Completer{

    private DomainService domainService;
    private Stack domainStack;

    DomainOperationsCompleter(DomainService domainService,Stack domainStack){
        assert domainService != null;
        assert domainStack != null;
        this.domainService = domainService;
        this.domainStack = domainStack;
    }

    @Override
    public void complete(LineReader lineReader, ParsedLine parsedLine, List candidates) {
        assert candidates != null;

        //System.out.println(" ParsedLine "+parsedLine.word());

        String fullyQualifiedDomain = JLineInteractiveShell.getFullyQualifiedDomain(domainStack);

        List operationsAt = domainService.getOperationsAt(fullyQualifiedDomain);

        if(operationsAt != null && !operationsAt.isEmpty()){


            for (String opName : operationsAt) {
                String word = parsedLine.word();
                if(opName.startsWith(word)) {
                    Candidate candidate = new Candidate(opName);
                    candidates.add(candidate);
                }
            }

        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy