Java Code Examples for javax.lang.model.element.ExecutableElement#getSimpleName()

The following examples show how to use javax.lang.model.element.ExecutableElement#getSimpleName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openjdk-jdk9   File: LLNI.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected final String jniMethodName(ExecutableElement method, String cname,
                                     boolean longName)
            throws TypeSignature.SignatureException {
    String res = "Java_" + cname + "_" + method.getSimpleName();

    if (longName) {
        TypeMirror mType =  types.erasure(method.getReturnType());
        List<? extends VariableElement> params = method.getParameters();
        List<TypeMirror> argTypes = new ArrayList<>();
        for (VariableElement param: params) {
            argTypes.add(types.erasure(param.asType()));
        }

        res = res + "__";
        for (TypeMirror t: argTypes) {
            String tname = t.toString();
            TypeSignature newTypeSig = new TypeSignature(elems);
            String sig = newTypeSig.getTypeSignature(tname);
            res = res + nameToIdentifier(sig);
        }
    }
    return res;
}
 
Example 2
Source Project: jdk8u60   File: LLNI.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected final String jniMethodName(ExecutableElement method, String cname,
                                     boolean longName)
            throws TypeSignature.SignatureException {
    String res = "Java_" + cname + "_" + method.getSimpleName();

    if (longName) {
        TypeMirror mType =  types.erasure(method.getReturnType());
        List<? extends VariableElement> params = method.getParameters();
        List<TypeMirror> argTypes = new ArrayList<TypeMirror>();
        for (VariableElement param: params) {
            argTypes.add(types.erasure(param.asType()));
        }

        res = res + "__";
        for (TypeMirror t: argTypes) {
            String tname = t.toString();
            TypeSignature newTypeSig = new TypeSignature(elems);
            String sig = newTypeSig.getTypeSignature(tname);
            res = res + nameToIdentifier(sig);
        }
    }
    return res;
}
 
Example 3
Source Project: netbeans   File: AbstractTestGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the interface declare given method
 *
 * @param trgInterface interface to be declaring the method
 * @param srcMethod method to be declared
 * @return {@code true} if the method is declared by the interface, {@code false} otherwise
 */
private static boolean isMethodDeclaredByInterface(TypeElement trgInterface, ExecutableElement srcMethod) {
    List<? extends Element> enclosedElements = trgInterface.getEnclosedElements();
    List<? extends VariableElement> methodParameters = srcMethod.getParameters();
    for (Element enclosedElement : enclosedElements) {
        if (enclosedElement instanceof ExecutableElement) {
            ExecutableElement exElement = (ExecutableElement) enclosedElement;
            List<? extends VariableElement> elementParameters = exElement.getParameters();
            if (srcMethod.getSimpleName() != exElement.getSimpleName()
                    || (methodParameters.size() != elementParameters.size())) {
                continue;
            }
            for (int i = 0; i < methodParameters.size(); i++) {
                if (!((VariableElement) methodParameters.get(i)).asType().toString().equals(
                        ((VariableElement) elementParameters.get(i)).asType().toString())) {
                    continue;
                }
            }
            return true;
        }
    }
    return false;
}
 
Example 4
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 5
Source Project: dagger2-sample   File: MapKeyGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
ImmutableSet<JavaWriter> write(ClassName generatedTypeName, Element e) {
  JavaWriter writer = JavaWriter.inPackage(generatedTypeName.packageName());
  TypeWriter mapKeyWriter = writer.addClass(generatedTypeName.simpleName());
  mapKeyWriter.annotate(Generated.class).setValue(ComponentProcessor.class.getName());
  mapKeyWriter.addModifiers(PUBLIC);

  //create map key create method, which will return an instance of map key
  MethodWriter getMethodWriter = mapKeyWriter.addMethod(e.asType(), "create");
  //get parameter list of create method
  List<? extends Element> enclosingElements = e.getEnclosedElements();
  List<String> paraList = new ArrayList<String>();

  //Using AutoAnnotation to generate mapkey creator files later
  getMethodWriter.annotate(AutoAnnotation.class);
  getMethodWriter.addModifiers(PUBLIC, STATIC);

  for (Element element : enclosingElements) {
    if (element instanceof ExecutableElement) {
      ExecutableElement executableElement = (ExecutableElement) element;
      Name parameterName = executableElement.getSimpleName();
      getMethodWriter.addParameter(
          (TypeElement) ((DeclaredType) (executableElement.getReturnType())).asElement(),
          parameterName.toString());
      paraList.add(parameterName.toString());
    } else {
      throw new IllegalStateException();
    }
  }

  getMethodWriter.body().addSnippet(
      "return new AutoAnnotation_" + generatedTypeName.simpleName() + "_create(%s);",
      Joiner.on(", ").join(paraList));

  return ImmutableSet.of(writer);
}
 
Example 6
Source Project: openjdk-jdk8u   File: LLNI.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 7
Source Project: revapi   File: MethodElement.java    License: Apache License 2.0 4 votes vote down vote up
public static String createComparableSignature(ExecutableElement m, TypeMirror mType) {
    //the choice of '#' for a separator between the name and signature is because it precedes both '(' and any
    //legal character in a method name in the ASCII table
    return m.getSimpleName() + "#" + Util.toUniqueString(mType);
}
 
Example 8
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
Example 9
Source Project: cxf   File: DumpJavaDoc.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean run(DocletEnvironment docEnv) {
    final Elements utils = docEnv.getElementUtils();
    final DocTrees docTrees = docEnv.getDocTrees();
    
    try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
        final Properties javaDocMap = new Properties();
        for (Element element : docEnv.getIncludedElements()) {
            if (element.getKind() == ElementKind.CLASS) {
                final TypeElement classDoc = (TypeElement) element;
                final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
                
                if (classCommentTree != null) {
                    javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
                }
                
                for (Element member: classDoc.getEnclosedElements()) {
                    // Skip all non-public methods
                    if (!member.getModifiers().contains(Modifier.PUBLIC)) {
                        continue;
                    }
                    
                    if (member.getKind() == ElementKind.METHOD) {
                        final ExecutableElement method = (ExecutableElement) member;
                        final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
                        final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
                        
                        if (methodCommentTree == null) {
                            javaDocMap.put(qualifiedName, "");
                        } else  {
                            javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
                            for (DocTree tree: methodCommentTree.getBlockTags()) {
                                if (tree.getKind() == DocTree.Kind.RETURN) {
                                    final ReturnTree returnTree = (ReturnTree) tree;
                                    javaDocMap.put(qualifiedName + ".returnCommentTag", 
                                        getAllComments(returnTree.getDescription()));
                                } else if (tree.getKind() == DocTree.Kind.PARAM) {
                                    final ParamTree paramTree = (ParamTree) tree;
                                    final int index = getParamIndex(method, paramTree);
                                    if (index >= 0) {
                                        javaDocMap.put(qualifiedName + ".paramCommentTag." + index, 
                                            getAllComments(paramTree.getDescription()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        
        javaDocMap.store(os, "");
        os.flush();
    } catch (final IOException ex) {
        reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
    }
    
    return true;
}
 
Example 10
Source Project: FreeBuilder   File: MethodFinder.java    License: Apache License 2.0 4 votes vote down vote up
Signature(ExecutableElement method) {
  name = method.getSimpleName();
  params = method.getParameters().size();
}
 
Example 11
protected void writeMethods(Writer out, ClassSymbol sym, String cname)
        throws IOException, TypeSignature.SignatureException {
    List<ExecutableElement> classmethods = ElementFilter.methodsIn(sym.getEnclosedElements());
    for (ExecutableElement md: classmethods) {
        if(md.getModifiers().contains(Modifier.NATIVE)){
            TypeMirror mtr = types.erasure(md.getReturnType());
            String sig = signature(md);
            TypeSignature newtypesig = new TypeSignature(elements);
            CharSequence methodName = md.getSimpleName();
            boolean longName = false;
            for (ExecutableElement md2: classmethods) {
                if ((md2 != md)
                    && (methodName.equals(md2.getSimpleName()))
                    && (md2.getModifiers().contains(Modifier.NATIVE)))
                    longName = true;

            }
            println(out, "/*");
            println(out, " * Class:     " + cname);
            println(out, " * Method:    " +
                       mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
            println(out, " * Signature: " + newtypesig.getTypeSignature(sig, mtr));
            println(out, " */");
            println(out, "JNIEXPORT " + jniType(mtr) +
                       " JNICALL " +
                       mangler.mangleMethod(md, sym,
                                           (longName) ?
                                           Mangle.Type.METHOD_JNI_LONG :
                                           Mangle.Type.METHOD_JNI_SHORT));
            print(out, "  (JNIEnv *, ");
            List<? extends VariableElement> paramargs = md.getParameters();
            List<TypeMirror> args = new ArrayList<TypeMirror>();
            for (VariableElement p: paramargs) {
                args.add(types.erasure(p.asType()));
            }
            if (md.getModifiers().contains(Modifier.STATIC))
                print(out, "jclass");
            else
                print(out, "jobject");

            for (TypeMirror arg: args) {
                print(out, ", ");
                print(out, jniType(arg));
            }
            println(out, ");"
                    + lineSep);
        }
    }
}
 
Example 12
Source Project: jdk8u60   File: JNI.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
Example 13
Source Project: jdk8u60   File: JNIWriter.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected void writeMethods(Writer out, ClassSymbol sym, String cname)
        throws IOException, TypeSignature.SignatureException {
    List<ExecutableElement> classmethods = ElementFilter.methodsIn(sym.getEnclosedElements());
    for (ExecutableElement md: classmethods) {
        if(md.getModifiers().contains(Modifier.NATIVE)){
            TypeMirror mtr = types.erasure(md.getReturnType());
            String sig = signature(md);
            TypeSignature newtypesig = new TypeSignature(elements);
            CharSequence methodName = md.getSimpleName();
            boolean longName = false;
            for (ExecutableElement md2: classmethods) {
                if ((md2 != md)
                    && (methodName.equals(md2.getSimpleName()))
                    && (md2.getModifiers().contains(Modifier.NATIVE)))
                    longName = true;

            }
            println(out, "/*");
            println(out, " * Class:     " + cname);
            println(out, " * Method:    " +
                       mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
            println(out, " * Signature: " + newtypesig.getTypeSignature(sig, mtr));
            println(out, " */");
            println(out, "JNIEXPORT " + jniType(mtr) +
                       " JNICALL " +
                       mangler.mangleMethod(md, sym,
                                           (longName) ?
                                           Mangle.Type.METHOD_JNI_LONG :
                                           Mangle.Type.METHOD_JNI_SHORT));
            print(out, "  (JNIEnv *, ");
            List<? extends VariableElement> paramargs = md.getParameters();
            List<TypeMirror> args = new ArrayList<TypeMirror>();
            for (VariableElement p: paramargs) {
                args.add(types.erasure(p.asType()));
            }
            if (md.getModifiers().contains(Modifier.STATIC))
                print(out, "jclass");
            else
                print(out, "jobject");

            for (TypeMirror arg: args) {
                print(out, ", ");
                print(out, jniType(arg));
            }
            println(out, ");"
                    + lineSep);
        }
    }
}
 
Example 14
protected String fullName(ExecutableElement m) {
    return ((TypeElement) m.getEnclosingElement()).getQualifiedName().toString()+'#'+m.getSimpleName();
}
 
Example 15
Source Project: openjdk-8   File: JNI.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
Example 16
Source Project: auto   File: BuilderMethodClassifier.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns an {@code Optional} containing a function to use {@code copyOfMethod} to copy the
 * {@code parameterType} to the {@code targetType}, or {@code Optional.empty()} if the method
 * can't be used. For example, we might have a property of type {@code ImmutableSet<T>} and our
 * setter has a parameter of type {@code Set<? extends T>}. Can we use {@code ImmutableSet<E>
 * ImmutableSet.copyOf(Collection<? extends E>)} to set the property? What about {@code
 * ImmutableSet<E> ImmutableSet.copyOf(E[])}?
 *
 * <p>The example here is deliberately complicated, in that it has a type parameter of its own,
 * presumably because the {@code @AutoValue} class is {@code Foo<T>}. One subtle point is that the
 * builder will then be {@code Builder<T>} where this {@code T} is a <i>different</i> type
 * variable. However, we've used {@link TypeVariables} to ensure that the {@code T} in {@code
 * ImmutableSet<T>} is actually the one from {@code Builder<T>} instead of the original one from
 * {@code Foo<T>}.}
 *
 * @param copyOfMethod the candidate method to do the copy, {@code
 *     ImmutableSet.copyOf(Collection<? extends E>)} or {@code ImmutableSet.copyOf(E[])} in the
 *     examples.
 * @param targetType the type of the property to be set, {@code ImmutableSet<T>} in the example.
 * @param parameterType the type of the setter parameter, {@code Set<? extends T>} in the example.
 * @return a function that maps a string parameter to a method call using that parameter. For
 *     example it might map {@code foo} to {@code ImmutableList.copyOf(foo)}.
 */
private Optional<Function<String, String>> getConvertingSetterFunction(
    ExecutableElement copyOfMethod, DeclaredType targetType, TypeMirror parameterType) {
  // We have a parameter type, for example Set<? extends T>, and we want to know if it can be
  // passed to the given copyOf method, which might for example be one of these methods from
  // ImmutableSet:
  //    public static <E> ImmutableSet<E> copyOf(Collection<? extends E> elements)
  //    public static <E> ImmutableSet<E> copyOf(E[] elements)
  // Additionally, if it can indeed be passed to the method, we want to know whether the result
  // (here ImmutableSet<? extends T>) is compatible with the property to be set.
  // We can't use Types.asMemberOf to do the substitution for us, because the methods in question
  // are static. So even if our target type is ImmutableSet<String>, if we ask what the type of
  // copyOf is in ImmutableSet<String> it will still tell us <T> Optional<T> (T).
  // Instead, we do the variable substitutions ourselves.
  if (TypeVariables.canAssignStaticMethodResult(
      copyOfMethod, parameterType, targetType, typeUtils)) {
    String method = TypeEncoder.encodeRaw(targetType) + "." + copyOfMethod.getSimpleName();
    return Optional.of(s -> method + "(" + s + ")");
  }
  return Optional.empty();
}
 
Example 17
Source Project: hottub   File: JNI.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
Example 18
protected String fullName(ExecutableElement m) {
    return ((TypeElement) m.getEnclosingElement()).getQualifiedName().toString()+'#'+m.getSimpleName();
}
 
Example 19
public String methodToString(ExecutableElement method) {
    StringBuilder buf = new StringBuilder(method.getSimpleName());
    for (VariableElement param : method.getParameters())
        buf.append(';').append(param.asType());
    return buf.toString();
}
 
Example 20
protected String fullName(ExecutableElement m) {
    return ((TypeElement) m.getEnclosingElement()).getQualifiedName().toString()+'#'+m.getSimpleName();
}