Example usage for org.eclipse.jdt.core IMethod getFlags

List of usage examples for org.eclipse.jdt.core IMethod getFlags

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IMethod getFlags.

Prototype

int getFlags() throws JavaModelException;

Source Link

Document

Returns the modifier flags for this member.

Usage

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.JDTHelper.java

License:Open Source License

private TypeData createData(List<IMethod> allMethods, IJavaProject jproject) throws JavaModelException {
    TypeData d = new TypeData();
    for (IMethod m : allMethods) {
        if (!Flags.isPublic(m.getFlags())) {
            continue;
        }//from  w ww.jav  a2s  .c  o m

        if (m.getElementName().startsWith("impl_") || m.getElementName().startsWith("getImpl_")) {
            continue;
        }

        if (m.getElementName().startsWith("get") && m.getParameterNames().length == 0) {
            String returnSignature = Signature.toString(m.getReturnType());
            if (returnSignature.startsWith("javafx.event.EventHandler<? super ")
                    || returnSignature.startsWith("javafx.event.EventHandler<")) {
                String eventType;
                if (returnSignature.startsWith("javafx.event.EventHandler<? super ")) {
                    eventType = returnSignature.substring("javafx.event.EventHandler<? super ".length(),
                            returnSignature.length() - 1);
                } else {
                    eventType = returnSignature.substring("javafx.event.EventHandler<".length(),
                            returnSignature.length() - 1);
                }

                EventValueProperty p = new EventValueProperty(m, extractAttributename(m.getElementName()),
                        m.getParent().getElementName(), eventType);
                d.properties.add(p);

            } else {
                String propName = extractAttributename(m.getElementName());
                String ownerName = m.getParent().getElementName();
                boolean isReadonly = isReadonlySetter(propName, allMethods);

                if ("double".equals(returnSignature) || "float".equals(returnSignature)) {
                    if (!isReadonly) {
                        FloatingValueProperty p = new FloatingValueProperty(m, propName, ownerName,
                                returnSignature);
                        d.properties.add(p);
                    }
                } else if ("int".equals(returnSignature) || "long".equals(returnSignature)
                        || "short".equals(returnSignature) || "byte".equals(returnSignature)
                        || "char".equals(returnSignature)) {
                    if (!isReadonly) {
                        IntegerValueProperty p = new IntegerValueProperty(m, propName, ownerName,
                                returnSignature);
                        d.properties.add(p);
                    }
                } else {
                    IType type;
                    if (returnSignature.indexOf('<') == -1) {
                        type = jproject.findType(returnSignature);
                    } else {
                        type = jproject.findType(returnSignature.substring(0, returnSignature.indexOf('<')));
                    }

                    if (type == null) {
                        continue;
                    }

                    if (type.isEnum()) {
                        if (!isReadonly) {
                            EnumValueProperty p = new EnumValueProperty(m, propName, ownerName, returnSignature,
                                    type);
                            d.properties.add(p);
                        }
                    } else {
                        boolean isLists = false;
                        boolean isMap = false;
                        if ("java.util.List".equals(type.getFullyQualifiedName())) {
                            isLists = true;
                        } else {
                            for (String i : type.getSuperInterfaceNames()) {
                                if (i.equals("java.util.List")) {
                                    isLists = true;
                                }
                            }
                        }

                        if (!isLists) {
                            if ("java.util.Map".equals(type.getFullyQualifiedName())) {
                                isMap = true;
                            } else {
                                for (String i : type.getSuperInterfaceNames()) {
                                    if (i.equals("java.util.Map")) {
                                        isMap = true;
                                    }
                                }
                            }
                        }

                        if (isLists) {
                            String listType;
                            if (returnSignature.indexOf('<') != -1) {
                                listType = returnSignature.substring(returnSignature.indexOf('<') + 1,
                                        returnSignature.lastIndexOf('>'));
                            } else {
                                listType = "?";
                            }

                            if (!propName.endsWith("Unmodifiable")) {
                                ListValueProperty p = new ListValueProperty(m, propName, ownerName, listType,
                                        isReadonly);
                                d.properties.add(p);
                            }
                        } else if (isMap) {
                            MapValueProperty p = new MapValueProperty(m, propName, ownerName);
                            d.properties.add(p);
                        } else if (type.getFullyQualifiedName().equals("java.lang.String")) {
                            if (!isReadonly) {
                                StringValueProperty p = new StringValueProperty(m, propName, ownerName,
                                        returnSignature);
                                d.properties.add(p);
                            }
                        } else {
                            if (!isReadonly) {
                                List<Proposal> props = getProposals(type, jproject);
                                ElementValueProperty p = new ElementValueProperty(m, propName, ownerName,
                                        returnSignature, props);
                                d.properties.add(p);
                            }
                        }
                    }
                }
            }
        } else if (m.getElementName().startsWith("is") && m.getParameterNames().length == 0
                && "Z".equals(m.getReturnType())) {
            String propName = extractAttributename(m.getElementName());
            boolean isReadonly = isReadonlySetter(propName, allMethods);

            if (!isReadonly) {
                BooleanValueProperty p = new BooleanValueProperty(m, propName, m.getParent().getElementName(),
                        "boolean");
                d.properties.add(p);
            }
        }
    }
    return d;
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.JDTHelper.java

License:Open Source License

private List<Proposal> getProposals(IType type, IJavaProject jp) {
    if (PROVIDERS.containsKey(type.getFullyQualifiedName())) {
        return PROVIDERS.get(type.getFullyQualifiedName()).getProposals(jp);
    } else {/*w ww  . j a v  a 2s.co  m*/
        try {
            for (IMethod m : type.getMethods()) {
                if (Flags.isStatic(m.getFlags()) && "valueOf".equals(m.getElementName())) {
                    Proposal p = new Proposal("\"<string>\"");
                    p.hover = new HoverImpl(m);
                    return Collections.singletonList(p);
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return Collections.emptyList();
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.JDTHelper.java

License:Open Source License

private boolean isReadonlySetter(String name, List<IMethod> methods) throws JavaModelException {
    for (IMethod m : methods) {
        if (!m.getElementName().startsWith("set") || !Flags.isPublic(m.getFlags())) {
            continue;
        }/*from w w w  . j  ava 2 s .c om*/

        if (name.equals(extractAttributename(m.getElementName()))) {
            return false;
        }
    }
    return true;
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.prop.KeyCombinationProvider.java

License:Open Source License

protected IMethod findMethod(IJavaProject jp) {
    try {//  www  .ja v a  2 s  .c  o m
        IType t = jp.findType("javafx.scene.input.KeyCombination");
        for (IMethod m : t.getMethods()) {
            if (Flags.isStatic(m.getFlags()) && "valueOf".equals(m.getElementName())) {
                return m;
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.prop.PaintProposalProvider.java

License:Open Source License

protected IMethod findMethod(IJavaProject jp) {
    try {//from w w  w .j  a v a 2  s.c o m
        IType t = jp.findType("javafx.scene.paint.Color");
        for (IMethod m : t.getMethods()) {
            if (Flags.isStatic(m.getFlags()) && "web".equals(m.getElementName())
                    && m.getParameters().length == 1) {
                return m;
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:at.bestsolution.efxclipse.tooling.model.internal.FXClass.java

License:Open Source License

@Override
public IMethod getValueOf() {
    //      if( ! valueOfResolved ) {
    try {//from   w  w  w . j  ava2s .com
        for (IMethod m : type.getMethods()) {
            if (Flags.isStatic(m.getFlags()) && Flags.isPublic(m.getFlags())
                    && "valueOf".equals(m.getElementName())) {
                if (m.getParameterTypes().length == 1) {
                    //                     String fqnType = Util.toFQN((IType) m.getParent(),m.getParameterTypes()[0]);
                    //                     if("java.lang.String".equals( fqnType) ) {
                    valueOfMethod = m;
                    break;
                    //                     }
                }
            }
        }
        valueOfResolved = true;
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //      }
    return valueOfMethod;
}

From source file:at.bestsolution.efxclipse.tooling.model.internal.FXObjectPoperty.java

License:Open Source License

public IMethod getValueOfMethod() {
    if (!valueOfMethodResolved) {
        try {//  w  ww.j a  va  2  s.  co  m
            for (IMethod m : getElementType().getMethods()) {
                if (Flags.isStatic(m.getFlags()) && Flags.isPublic(m.getFlags())
                        && "valueOf".equals(m.getElementName())) {
                    valueOfMethod = m;
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        valueOfMethodResolved = true;
    }

    return valueOfMethod;
}

From source file:at.bestsolution.efxclipse.tooling.model.internal.utils.PropertiesUtil.java

License:Open Source License

public static Map<String, IFXProperty> resolveProperties(FXClass fxClass) throws JavaModelException {
    Map<String, IFXProperty> rv = new HashMap<String, IFXProperty>();

    if ("java.lang.Object".equals(fxClass.getFQN())) {
        return rv;
    }// w ww. j a v a 2s.c om

    Map<String, IMethod> beanProperties = new HashMap<String, IMethod>();
    Map<String, IMethod> builderProperties = new HashMap<String, IMethod>();

    String builder = fxClass.getType().getFullyQualifiedName() + "Builder";
    IType builderType = fxClass.getJavaProject().findType(builder);
    if (builderType != null) {
        for (IMethod m : builderType.getMethods()) {
            // Only public and none static methods
            if (!Flags.isPublic(m.getFlags()) || Flags.isStatic(m.getFlags())) {
                continue;
            }

            String name = m.getElementName();

            // omit the build method
            if ("build".equals(name) || "applyTo".equals(name)) {
                continue;
            }

            if (m.getParameterNames().length == 1) {
                String param = m.getParameterTypes()[0];
                if (Signature.getArrayCount(param) == 0) {
                    builderProperties.put(name, m);
                }
            }
        }
    }

    for (IMethod m : fxClass.getType().getMethods()) {
        // Only public and none static methods
        if (!Flags.isPublic(m.getFlags()) || Flags.isStatic(m.getFlags())) {
            continue;
        }

        String name = m.getElementName();

        // do not use impl methods they are private
        if (name.startsWith("getImpl") || name.startsWith("isImpl") || name.startsWith("setImpl")
                || name.contains("Unmodifiable")) {
            continue;
        }

        if (name.startsWith("get") || name.startsWith("is")) {
            name = name.startsWith("get") ? name.substring(3) : name.substring(2);
            name = Character.toLowerCase(name.charAt(0)) + name.substring(1);

            // Only set if there's not already one stored
            if (!beanProperties.containsKey(name)) {
                beanProperties.put(name, m);
            }
        } else if (m.getElementName().startsWith("set") && m.getParameters().length == 1) {
            name = name.substring(3);
            name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
            beanProperties.put(name, m);
        }
    }

    for (Entry<String, IMethod> e : beanProperties.entrySet()) {
        FXProperty p = getProperty(fxClass, e.getKey(), e.getValue());
        if (p != null) {
            rv.put(e.getKey(), p);
        }
    }

    for (Entry<String, IMethod> e : builderProperties.entrySet()) {
        IFXProperty p = rv.get(e.getKey());
        if (p == null) {
            continue;
        }

        if (!(p instanceof IFXCollectionProperty)) {
            if (!p.isSetable()) {
                p = getProperty(fxClass, e.getKey(), e.getValue());
                if (p != null) {
                    rv.put(e.getKey(), p);
                }
            }
        }
    }

    return rv;
}

From source file:at.bestsolution.efxclipse.tooling.model.internal.utils.PropertiesUtil.java

License:Open Source License

public static Map<String, IFXProperty> resolveStaticProperties(FXClass fxClass) throws JavaModelException {
    Map<String, IFXProperty> rv = new HashMap<String, IFXProperty>();

    if ("java.lang.Object".equals(fxClass.getFQN())) {
        return rv;
    }/*from  w w w .j a  v a2s  . c  om*/

    for (IMethod m : fxClass.getType().getMethods()) {
        if (!Flags.isPublic(m.getFlags()) || !Flags.isStatic(m.getFlags())) {
            continue;
        }

        String name = m.getElementName();

        if (name.startsWith("setImpl")) {
            continue;
        }

        if (name.startsWith("set") && m.getParameterTypes().length == 2) {
            name = name.substring(3);
            name = Character.toLowerCase(name.charAt(0)) + name.substring(1);

            FXProperty p = null;

            String signature = m.getParameterTypes()[1];

            String genericType = Signature.toString(signature);

            if (FXPrimitiveProperty.isPrimitive(genericType)) {
                p = new FXPrimitiveProperty(fxClass, name, m, Type.parseType(genericType), true);
            } else {
                String erasedFQNType = Util.getFQNType((IType) m.getParent(),
                        Signature.getTypeErasure(genericType));
                if (erasedFQNType != null) {
                    if (FXEnumProperty.isEnum(fxClass.getJavaProject(), erasedFQNType)) {
                        p = new FXEnumProperty(fxClass, name, m, erasedFQNType, true);
                    } else {
                        p = new FXObjectPoperty(fxClass, name, m, erasedFQNType, true);
                    }
                }
            }

            if (p != null) {
                rv.put(p.getName(), p);
            }
        }
    }

    return rv;
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static boolean isDefaultMethod(IMethod method) throws JavaModelException {
    return Flags.isDefaultMethod(method.getFlags());
}