Example usage for org.eclipse.jdt.core IType getSuperInterfaceNames

List of usage examples for org.eclipse.jdt.core IType getSuperInterfaceNames

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType getSuperInterfaceNames.

Prototype

String[] getSuperInterfaceNames() throws JavaModelException;

Source Link

Document

Returns the names of interfaces that this type implements or extends, in the order in which they are listed in the source.

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  .  java2 s  .  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:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java

License:Open Source License

private void generateType(IType type, StringBuilder builder, String indent) throws JavaModelException {
    int flags = 0;

    appendAnnotationLabels(type.getAnnotations(), flags, builder, indent.substring(TAB.length()));
    builder.append(indent.substring(TAB.length()));
    builder.append(getModifiers(type.getFlags(), type.getFlags())).append(' ').append(getJavaType(type))
            .append(' ').append(type.getElementName());

    if (type.isResolved()) {
        BindingKey key = new BindingKey(type.getKey());
        if (key.isParameterizedType()) {
            String[] typeArguments = key.getTypeArguments();
            appendTypeArgumentSignaturesLabel(type, typeArguments, flags, builder);
        } else {//w  w  w .ja v a  2  s  .c  om
            String[] typeParameters = Signature.getTypeParameters(key.toSignature());
            appendTypeParameterSignaturesLabel(typeParameters, builder);
        }
    } else {
        appendTypeParametersLabels(type.getTypeParameters(), flags, builder);
    }

    if (!"java.lang.Object".equals(type.getSuperclassName())
            && !"java.lang.Enum".equals(type.getSuperclassName())) {

        builder.append(" extends ");
        if (type.getSuperclassTypeSignature() != null) {
            //                appendTypeSignatureLabel(type, type.getSuperclassTypeSignature(), flags, builder);
            builder.append(Signature.toString(type.getSuperclassTypeSignature()));
        } else {
            builder.append(type.getSuperclassName());
        }
    }
    if (!type.isAnnotation()) {
        if (type.getSuperInterfaceNames().length != 0) {
            builder.append(" implements ");
            String[] signatures = type.getSuperInterfaceTypeSignatures();
            if (signatures.length == 0) {
                signatures = type.getSuperInterfaceNames();
            }
            for (String interfaceFqn : signatures) {
                builder.append(Signature.toString(interfaceFqn)).append(", ");
            }
            builder.delete(builder.length() - 2, builder.length());
        }
    }
    builder.append(" {\n");

    List<IField> fields = new ArrayList<>();
    if (type.isEnum()) {
        builder.append(indent);
        for (IField field : type.getFields()) {
            if (field.isEnumConstant()) {
                builder.append(field.getElementName()).append(", ");
            } else {
                fields.add(field);
            }
        }
        if (", ".equals(builder.substring(builder.length() - 2))) {
            builder.delete(builder.length() - 2, builder.length());
        }
        builder.append(";\n");

    } else {
        fields.addAll(Arrays.asList(type.getFields()));
    }

    for (IField field : fields) {
        if (Flags.isSynthetic(field.getFlags())) {
            continue;
        }
        appendAnnotationLabels(field.getAnnotations(), flags, builder, indent);
        builder.append(indent).append(getModifiers(field.getFlags(), type.getFlags()));
        if (builder.charAt(builder.length() - 1) != ' ') {
            builder.append(' ');
        }

        builder.append(Signature.toCharArray(field.getTypeSignature().toCharArray())).append(' ')
                .append(field.getElementName());
        if (field.getConstant() != null) {
            builder.append(" = ");
            if (field.getConstant() instanceof String) {
                builder.append('"').append(field.getConstant()).append('"');
            } else {
                builder.append(field.getConstant());
            }
        }
        builder.append(";\n");
    }
    builder.append('\n');

    for (IMethod method : type.getMethods()) {
        if (method.getElementName().equals("<clinit>") || Flags.isSynthetic(method.getFlags())) {
            continue;
        }
        appendAnnotationLabels(method.getAnnotations(), flags, builder, indent);
        BindingKey resolvedKey = method.isResolved() ? new BindingKey(method.getKey()) : null;
        String resolvedSig = (resolvedKey != null) ? resolvedKey.toSignature() : null;
        builder.append(indent).append(getModifiers(method.getFlags(), type.getFlags()));

        if (builder.charAt(builder.length() - 1) != ' ') {
            builder.append(' ');
        }
        if (resolvedKey != null) {
            if (resolvedKey.isParameterizedMethod()) {
                String[] typeArgRefs = resolvedKey.getTypeArguments();
                if (typeArgRefs.length > 0) {
                    appendTypeArgumentSignaturesLabel(method, typeArgRefs, flags, builder);
                    builder.append(' ');
                }
            } else {
                String[] typeParameterSigs = Signature.getTypeParameters(resolvedSig);
                if (typeParameterSigs.length > 0) {
                    appendTypeParameterSignaturesLabel(typeParameterSigs, builder);
                    builder.append(' ');
                }
            }
        } else if (method.exists()) {
            ITypeParameter[] typeParameters = method.getTypeParameters();
            if (typeParameters.length > 0) {
                appendTypeParametersLabels(typeParameters, flags, builder);
                builder.append(' ');
            }
        }

        if (!method.isConstructor()) {

            String returnTypeSig = resolvedSig != null ? Signature.getReturnType(resolvedSig)
                    : method.getReturnType();
            appendTypeSignatureLabel(method, returnTypeSig, 0, builder);
            builder.append(' ');
            //                builder.append(Signature.toCharArray(method.getReturnType().toCharArray())).append(' ');
        }
        builder.append(method.getElementName());
        builder.append('(');
        for (ILocalVariable variable : method.getParameters()) {
            builder.append(Signature.toString(variable.getTypeSignature()));
            builder.append(' ').append(variable.getElementName()).append(", ");

        }

        if (builder.charAt(builder.length() - 1) == ' ') {
            builder.delete(builder.length() - 2, builder.length());
        }
        builder.append(')');
        String[] exceptionTypes = method.getExceptionTypes();
        if (exceptionTypes != null && exceptionTypes.length != 0) {
            builder.append(' ').append("throws ");
            for (String exceptionType : exceptionTypes) {
                builder.append(Signature.toCharArray(exceptionType.toCharArray())).append(", ");
            }
            builder.delete(builder.length() - 2, builder.length());
        }
        if (type.isInterface() || type.isAnnotation()) {
            builder.append(";\n\n");
        } else {
            builder.append(" {").append(METHOD_BODY).append("}\n\n");
        }
    }
    for (IType iType : type.getTypes()) {
        generateType(iType, builder, indent + indent);
    }
    builder.append(indent.substring(TAB.length()));
    builder.append("}\n");
}

From source file:com.curlap.orb.plugin.generator.impl.CurlServiceClassGenerator.java

License:Open Source License

@Override
public VelocityContext generateClass() throws CurlGenerateException {
    ICompilationUnit source = iCompilationUnit;
    Set<String> importPackages = new HashSet<String>();
    List<Method> methods = new ArrayList<Method>();

    String packageName = null;/*from w w w .  jav  a2s  . c  o  m*/
    String targetInterface = null;
    JavadocContent classJavadoc = null;
    String className = null;
    boolean returnTypeIsNullable = true;
    boolean generateTestTemplate = false;
    boolean generateAsyncMethod = true;
    importPackages.add("COM.CURLAP.ORB");
    try {
        for (IType iType : source.getAllTypes()) {
            // package
            IPackageFragment iPackageFragment = iType.getPackageFragment();
            packageName = (iPackageFragment != null ? iPackageFragment.getElementName().toUpperCase() : "");

            // javadoc
            classJavadoc = JavaElementAnalyzer.getJavaDoc(iType);

            // class name
            className = iType.getElementName();
            if (className == null)
                throw new CurlGenerateException("There is no class name.");

            // superclass
            String superclass = iType.getSuperclassName();
            if (superclass != null) {
                methods.addAll(
                        addMethodsOfSuperclass(source, superclass, importPackages, returnTypeIsNullable));
                // NOTE: the following code would be not necessary 
                // superclassBuf.append(", ");
                // superclassBuf.append(superclass);
                // addImportedPackageIfNecessary(importPackages, superclass);
            }

            // annotation
            for (IAnnotation iAnnotation : iType.getAnnotations()) {
                if (iAnnotation.getElementName().equals("AutoGenerateCurlServiceClient")) {
                    for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) {
                        String memberName = pair.getMemberName();
                        if (memberName.equals("generateTestTemplate"))
                            generateTestTemplate = ((Boolean) pair.getValue()).booleanValue();
                        if (memberName.equals("generateAsyncMethod"))
                            generateAsyncMethod = ((Boolean) pair.getValue()).booleanValue();
                        if (memberName.equals("targetInterface"))
                            targetInterface = (String) pair.getValue();
                    }
                }
                if (iAnnotation.getElementName().equals("DefaultNotNull"))
                    returnTypeIsNullable = false;
            }

            // interface
            String[] interfaceNames = iType.getSuperInterfaceNames();
            if (interfaceNames.length > 0) {
                if (interfaceNames.length == 1)
                    targetInterface = interfaceNames[0]; // In the case of only one interface 
                else {
                    boolean hasSuchInterface = false;
                    for (String interfaceName : interfaceNames)
                        if (interfaceName.equals(targetInterface))
                            hasSuchInterface = true;
                    if (!hasSuchInterface)
                        throw new CurlGenerateException("'targetInterface' is wrong interface.");
                }
            }
            if (targetInterface != null) {
                // Add interfaces' methods
                TypeNameMatch typeNameMatch = new JavaElementSearcher(source).searchClassInfo(targetInterface);
                IType interfaceIType = typeNameMatch.getType();
                className = targetInterface;
                fileName = className + ".scurl";
                methods.addAll(getMethodsFromIType(interfaceIType, importPackages, returnTypeIsNullable));
                addImportedPackageIfNecessary(importPackages, targetInterface);

                // Add interfaces' methods of interface.
                for (String interfaceNamesOfInterface : interfaceIType.getSuperInterfaceNames()) {
                    TypeNameMatch typeNameMatchOfInterface = new JavaElementSearcher(
                            interfaceIType.getCompilationUnit()).searchClassInfo(interfaceNamesOfInterface);
                    methods.addAll(getMethodsFromIType(typeNameMatchOfInterface.getType(), importPackages,
                            returnTypeIsNullable));
                }
            } else {
                // methods 
                methods.addAll(getMethodsFromIType(iType, importPackages, returnTypeIsNullable));
            }
        }
    } catch (JavaModelException e) {
        throw new CurlGenerateException(e);
    }

    // merge to velocity.
    VelocityContext context = new VelocityContext();
    context.put("is_template", generateTestTemplate);
    context.put("has_async_method", generateAsyncMethod);
    context.put("package_name", packageName);
    context.put("import_packages", importPackages);
    context.put("javadocContent", classJavadoc);
    context.put("class_name", className);
    context.put("methods", methods);
    return context;
}

From source file:com.github.rotty3000.baseline.linter.builder.DiffMarker.java

License:Open Source License

public void doImplements(IFile file, Diff diff, Diff parentDiff, Info info) throws Exception {

    if ((parentDiff.getDelta() == Delta.ADDED) || (diff.getDelta() != Delta.ADDED)) {

        return;//from   ww  w .  j a  va  2s  . com
    }

    IType type = javaProject.findType(parentDiff.getName());

    if (type.getSuperInterfaceNames().length <= 0) {
        return;
    }

    doType2(file, parentDiff.getName(), info, "Implements " + diff.getDelta().toString().toLowerCase()
            + "! Change package version to " + info.suggestedVersion);
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

private static void determineType(IType type, List<IType> entities, List<IType> proxys,
        HashMap<String, IType> requests) throws JavaModelException {

    if (type.isInterface()) {
        List<String> interfaces = Arrays.asList(type.getSuperInterfaceNames());
        if (interfaces.contains("ValueProxy") //$NON-NLS-1$
                || interfaces.contains("EntityProxy")) { //$NON-NLS-2$
            proxys.add(type);//  ww  w  . j a va2s.co  m
            return;
        }
        if (interfaces.contains("RequestContext")) { //$NON-NLS-N$
            IAnnotation annotation = type.getAnnotation("ServiceName"); //$NON-NLS-N$
            if (annotation.exists()) {
                IMemberValuePair[] values = annotation.getMemberValuePairs();
                requests.put((String) values[0].getValue(), type);
                return;
            }
        }
        return;
    }
    IAnnotation[] annotations = type.getAnnotations();
    for (IAnnotation annotation : annotations) {
        if (isEntityAnnotation(annotation)) {
            if (!isFrameworkClass(type)) {
                entities.add(type);
            }
        }
    }
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

private static boolean isProxyType(IType type) throws JavaModelException {
    if (type.isInterface()) {
        List<String> interfaces = Arrays.asList(type.getSuperInterfaceNames());
        if (interfaces.contains("ValueProxy") //$NON-NLS-1$
                || interfaces.contains("EntityProxy")) { //$NON-NLS-2$
            return true;
        }//from ww  w . j  a  va  2 s . c o m
    }
    return false;
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

private static boolean isRequestFactoryType(IType type) throws JavaModelException {
    if (type.isInterface()) {
        List<String> interfaces = Arrays.asList(type.getSuperInterfaceNames());
        if (interfaces.contains("RequestFactory")) { //$NON-NLS-N$
            return true;
        }//from  www .ja va  2s  . c om
    }
    return false;
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

private static boolean isRequestType(IType type) throws JavaModelException {
    if (type.isInterface()) {
        List<String> interfaces = Arrays.asList(type.getSuperInterfaceNames());
        if (interfaces.contains("RequestContext")) { //$NON-NLS-N$
            return true;
        }/*from   w ww.j  av a2s.  com*/
    }
    return false;
}

From source file:com.google.inject.tools.ideplugin.eclipse.EclipseContextDefinitionListener.java

License:Apache License

@Override
protected boolean isTypeWeCareAbout(IType type) throws JavaModelException {
    for (String s : type.getSuperInterfaceNames()) {
        if (s.equals(iterableLongModuleLong) || s.equals(iterableLongModule) || s.equals(iterableModuleLong)
                || s.equals(iterableModule)) {
            return true;
        }/*  w  ww .  j a  va 2 s.  c o m*/
    }
    return false;
}

From source file:com.iw.plugins.spindle.core.util.CoreUtils.java

License:Mozilla Public License

/**
 * Answers true iff the candidate type implements the interface
 * /*  w w  w.ja va  2  s .c  om*/
 * @param candidate
 *            IType the candidate
 * @param interfaceName
 *            String the fully qualified name of an interface
 * @return true iff the candidate type implements the interface.
 * @throws JavaModelException
 */
public static boolean implementsInterface(IType candidate, String interfaceName) throws JavaModelException {
    boolean match = false;
    String[] superInterfaces = candidate.getSuperInterfaceNames();
    if (superInterfaces != null && superInterfaces.length > 0) {
        for (int i = 0; i < superInterfaces.length; i++) {
            if (candidate.isBinary() && interfaceName.endsWith(superInterfaces[i])) {
                match = true;
            } else {
                match = interfaceName.equals(superInterfaces[i]);
            }
        }
    } else {
        match = false;
    }
    return match;
}