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

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

/*******************************************************************************
* 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 TMLScriptProperty {

    private String _name;
    private String _type;
    private String _classname;
    private boolean _static = false;
   
    public boolean isStatic() {
        return _static;
    }

    public void setStatic(boolean static1) {
        _static = static1;
    }


    public static final TMLScriptProperty PROPERTY_PACKAGES = new TMLScriptProperty("Packages", "Packages", ReflectionManager.GLOBAL_SCOPE_CLASSNAME);
   
    public TMLScriptProperty(String name, String type, String classname) {
        _name = name;
        _type = type;
        _classname = classname;
    }

    public String getName() {
        return _name;
    }

    public String getType() {
        return _type;
    }

   
    public List<TMLScriptCompletionProposal> createProposals(String prefix, int cursorOffset) {
        List<TMLScriptCompletionProposal> proposals = new ArrayList<TMLScriptCompletionProposal>();
       
        // special handling for "new Packages"
        if (this.equals(PROPERTY_PACKAGES) && prefix != null && prefix.startsWith("new")) {
            prefix = prefix.substring("new".length()).trim();
        }
       
        String name = getName();       
        if (!_classname.equals("de.innovationgate.wgpublisher.webtml.utils.TMLContext")) {           
            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();
                    }
                   
                    display.append(" : " + ReflectionManager.buildSimpleClassname(getType()));
        
                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());
                proposal.enableLRU(_classname);
                proposals.add(proposal);
            }
           
        }       
        return proposals;
    }
}
TOP

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

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.