Package de.innovationgate.eclipse.editors.tmlscript.parsing

Source Code of de.innovationgate.eclipse.editors.tmlscript.parsing.TMLScriptVariableDeclaration

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.editors.tmlscript.parsing;

import java.util.ArrayList;
import java.util.List;

import de.innovationgate.eclipse.editors.tmlscript.TMLScriptCompletionProposal;

public class TMLScriptVariableDeclaration {


    private TMLScriptScope _scope;   
    private String _name;
    private String _value;   
    private int _offset;
    private boolean _tmlVariable;

    // class (type) this variable evaluates to
    private String _type;
   
    public TMLScriptVariableDeclaration(TMLScriptScope scope, String name) {
        _scope = scope;
        _name = name;
    }
   
    public TMLScriptScope getScope() {
        return _scope;
    }

    public String getName() {
        return _name;
    }
   
    public String getValue() {
        return _value;
    }

    public void setValue(String value) {
        _value = value;
    }

    public int getOffset() {
        return _offset;
    }

    public void setOffset(int offset) {
        _offset = offset;
    }
   
    public String toString() {
        return _name + "=" + _value + " - (" + _type + ", " + _offset + ", " +  _tmlVariable + ")";
    }

    public void setType(String type) {
        _type = type;       
    }


    public String getType() {
        return _type;
    }
   
    public boolean isTmlVariable() {
        return _tmlVariable;
    }

    public void setTmlVariable(boolean tmlVariable) {
        _tmlVariable = tmlVariable;
    }


   
    public List<TMLScriptCompletionProposal> createProposals(String prefix, int cursorOffset) {
        List<TMLScriptCompletionProposal> proposals = new ArrayList<TMLScriptCompletionProposal>();
        String name = getName();                
        if (prefix == null || name.toLowerCase().startsWith(prefix.toLowerCase())) {                                                                   
            //build completion proposal
            int cursorAfterProposal = -1;
            StringBuffer display = new StringBuffer();
            StringBuffer replacement = new StringBuffer();
          
                display.append(name);
                replacement.append(name);

                if (cursorAfterProposal == -1) {
                    cursorAfterProposal = replacement.length();
                }
               
               
                if (getType() != null) {
                    display.append(" : " + ReflectionManager.buildSimpleClassname(getType()));
                } else {
                    display.append(" : unknown");
                }
    
            int replacementOffset = 0;
            int replacementLength = 0;
            if (prefix != null) {
                replacementOffset = cursorOffset - prefix.length();
                replacementLength = prefix.length();
            }
            TMLScriptCompletionProposal proposal = new TMLScriptCompletionProposal(replacement.toString(), replacementOffset, replacementLength, cursorAfterProposal, display.toString());
            proposals.add(proposal);
        }

        return proposals;
    }
   
}
TOP

Related Classes of de.innovationgate.eclipse.editors.tmlscript.parsing.TMLScriptVariableDeclaration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.