| /******************************************************************************* |
| * Copyright (c) 2004-2008 Istvan Rath and Daniel Varro |
| * 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: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.frameworkgui.content.nativefunctions;
|
|
|
| import java.lang.annotation.Annotation; |
| import java.util.ArrayList; |
| |
| import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| import org.eclipse.ui.views.properties.IPropertySource2; |
| import org.eclipse.ui.views.properties.PropertyDescriptor; |
| import org.eclipse.viatra2.natives.ASMNativeFunction; |
| import org.eclipse.viatra2.natives.NativeFunctionParameter; |
| import org.eclipse.viatra2.natives.VIATRANativeFunction; |
|
|
| public class NativeFunctionPropertySource implements IPropertySource2
|
| {
|
|
|
| ASMNativeFunction fNf;
|
| VIATRANativeFunction fNfA;
|
|
|
| public NativeFunctionPropertySource(ASMNativeFunction nf)
|
| {
|
| fNf = nf;
|
| }
|
|
|
| enum PROP_IDS { NAME, ID, DESC, ANNOTATIONS, REMARK, SIGNATURE };
|
|
|
|
|
| public boolean isPropertyResettable(Object id) { return false; }
|
|
|
|
|
| public boolean isPropertySet(Object id) { return false; }
|
|
|
|
|
| public Object getEditableValue() { return null; }
|
|
|
|
|
| public IPropertyDescriptor[] getPropertyDescriptors() {
|
| ArrayList<IPropertyDescriptor> ret = new ArrayList<IPropertyDescriptor>();
|
| PropertyDescriptor pd = new PropertyDescriptor(PROP_IDS.NAME, "Name");
|
| pd.setCategory("General");
|
| ret.add(pd);
|
| pd = new PropertyDescriptor(PROP_IDS.ID, "ID");
|
| pd.setCategory("General");
|
| ret.add(pd);
|
| pd = new PropertyDescriptor(PROP_IDS.DESC, "Description");
|
| pd.setCategory("General");
|
| ret.add(pd);
|
|
|
|
|
| // process annotations
|
| for (Annotation a : fNf.getClass().getAnnotations())
|
| {
|
| if (a.annotationType().equals(VIATRANativeFunction.class))
|
| {
|
| fNfA = (VIATRANativeFunction) a;
|
|
|
| pd = new PropertyDescriptor(PROP_IDS.REMARK, "Remark");
|
| pd.setCategory("General");
|
| ret.add(pd);
|
|
|
| pd = new PropertyDescriptor(PROP_IDS.SIGNATURE, "Signature");
|
| pd.setCategory("General");
|
| ret.add(pd);
|
|
|
| for (NativeFunctionParameter p : fNfA.params())
|
| {
|
| pd = new PropertyDescriptor(":"+p.name(),p.name());
|
| pd.setCategory("Parameters");
|
| ret.add(pd);
|
| }
|
| }
|
| }
|
|
|
| return ret.toArray(new IPropertyDescriptor[]{});
|
| }
|
|
|
|
|
| public Object getPropertyValue(Object id) {
|
| if (id.equals(PROP_IDS.ID))
|
| return fNf.getID();
|
| else if (id.equals(PROP_IDS.NAME))
|
| return fNf.getName();
|
| else if (id.equals(PROP_IDS.DESC))
|
| return fNf.getDescription();
|
| else if (id.equals(PROP_IDS.REMARK))
|
| return fNfA!=null?fNfA.remark():"";
|
| else if (id.equals(PROP_IDS.SIGNATURE))
|
| return fNfA!=null?getFunctionSignature(fNfA):"";
|
| else if ( ((String)id).startsWith(":") )
|
| // parameter signature
|
| {
|
| // parse parameter name
|
| String pname = ((String)id).substring(1);
|
| for (NativeFunctionParameter p : fNfA.params())
|
| {
|
| if (p.name().equals(pname))
|
| {
|
| return p.description() + " (variable argument number: "+p.isVarArg()+")";
|
| }
|
| }
|
| }
|
| return null;
|
| }
|
|
|
| protected String getParameterSignature(NativeFunctionParameter p)
|
| {
|
| String signature = "";
|
| for (NativeFunctionParameter.ParameterType t : p.type())
|
| {
|
| signature+="|"+t.name();
|
| if (p.isVarArg()) signature+="*";
|
| }
|
| signature = signature.substring(1);
|
| return signature;
|
| }
|
|
|
| protected String getFunctionSignature(VIATRANativeFunction f)
|
| {
|
| String s = f.name() + "( ";
|
| int i = 0;
|
| for (NativeFunctionParameter p : f.params())
|
| {
|
| s += i>0?(", "+getParameterSignature(p)):getParameterSignature(p);
|
| i++;
|
| s += " " + p.name();
|
| }
|
| String ret = "";
|
| for (NativeFunctionParameter.ParameterType t : f.returns())
|
| {
|
| ret+="|"+t.name();
|
| }
|
| return s+" ) : "+ret.substring(1);
|
| }
|
|
|
|
|
| public void resetPropertyValue(Object id) { }
|
|
|
|
|
| public void setPropertyValue(Object id, Object value) { }
|
|
|
| }
|