Package org.adoptopenjdk.jitwatch.model

Examples of org.adoptopenjdk.jitwatch.model.MetaMethod


  @Test
  public void testSourceSignatureRegExMatcher()
  {
    // single primitive param, void return
    Method m = getMethod("java.lang.AbstractStringBuilder", "ensureCapacity", new Class<?>[] { int.class });
    MetaMethod method = new MetaMethod(m, null);
    String sourceSig = "public void ensureCapacity(int foo)";
    Matcher matcher = Pattern.compile(method.getSignatureRegEx()).matcher(sourceSig);
    boolean match = matcher.find();
    assertTrue(match);

    // 2 primitive params,void return
    Method m2 = getMethod("java.lang.AbstractStringBuilder", "setCharAt", new Class<?>[] { int.class, char.class });
    MetaMethod method2 = new MetaMethod(m2, null);
    String sourceSig2 = "public void setCharAt(int foo, char bar)";
    Matcher matcher2 = Pattern.compile(method2.getSignatureRegEx()).matcher(sourceSig2);
    boolean match2 = matcher2.find();
    assertTrue(match2);

    // Object param and return type
    Method m3 = getMethod("java.lang.AbstractStringBuilder", "append", new Class<?>[] { java.lang.String.class });
    MetaMethod methodFQ = new MetaMethod(m3, null);
    String sourceSigFQ = "public AbstractStringBuilder append(String foo)";
    Matcher matcherFQ = Pattern.compile(methodFQ.getSignatureRegEx()).matcher(sourceSigFQ);
    boolean matchFQ = matcherFQ.find();
    assertTrue(matchFQ);

    // constructor with primitive params
    Constructor<?> c1 = getConstructor("java.lang.AbstractStringBuilder", new Class<?>[] { int.class });
    MetaConstructor con1 = new MetaConstructor(c1, null);
    String sourceSigC1 = "AbstractStringBuilder(int foo)";
    Matcher matcherC1 = Pattern.compile(con1.getSignatureRegEx()).matcher(sourceSigC1);
    boolean matchC1 = matcherC1.find();
    assertTrue(matchC1);

    // array return type, no params
    Method m4 = getMethod("java.lang.AbstractStringBuilder", "getValue", new Class<?>[0]);
    MetaMethod method4 = new MetaMethod(m4, null);
    String sourceSig4 = "final char[] getValue()";
    Matcher matcher4 = Pattern.compile(method4.getSignatureRegEx()).matcher(sourceSig4);
    boolean match4 = matcher4.find();
    assertTrue(match4);

    // array param and object return type
    Method m5 = getMethod("java.lang.AbstractStringBuilder", "append", new Class<?>[] { char[].class });
    MetaMethod method5 = new MetaMethod(m5, null);
    String sourceSig5 = "public AbstractStringBuilder append(char[] foo)";
    Matcher matcher5 = Pattern.compile(method5.getSignatureRegEx()).matcher(sourceSig5);
    boolean match5 = matcher5.find();
    assertTrue(match5);
  }
View Full Code Here


    Method m = getMethod("java.util.Properties", "loadConvert", new Class<?>[] {
        char[].class,
        int.class,
        int.class,
        char[].class });
    MetaMethod method = new MetaMethod(m, null);

    String sourceSig = "private String loadConvert (char[] in, int off, int len, char[] convtBuf) {";
    Matcher matcher = Pattern.compile(method.getSignatureRegEx()).matcher(sourceSig);
    boolean match = matcher.find();
    assertTrue(match);
  }
View Full Code Here

    // java.util.Arrays
    // public static <U,T> T[] copyOf(U[] original, int newLength, Class<?
    // extends T[]> newType) {

    Method m = getMethod("java.util.Arrays", "copyOf", new Class<?>[] { Object[].class, int.class, Class.class });
    MetaMethod method = new MetaMethod(m, null);

    // test for failure on matching internal (type erased) representation
    // against generics signature
    String sourceSig = "public static <U,T> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {";
    Matcher matcher = Pattern.compile(method.getSignatureRegEx()).matcher(sourceSig);
    boolean match = matcher.find();
    assertFalse(match);
  }
View Full Code Here

  public void testFindBestLineMatchForMemberSignature()
  {
    Method m = getMethod("java.util.Arrays", "copyOf", new Class<?>[] { Object[].class, int.class, Class.class });
   
    MetaClass metaClass = new MetaClass(null, "java.util.arrays");
    IMetaMember member = new MetaMethod(m, metaClass);
   
    List<String> srcLinesList = new ArrayList<>();

    srcLinesList.add("public static <T> T[] copyOf(T[] original, int newLength) {");
    srcLinesList.add("  return (T[]) copyOf(original, newLength, original.getClass());");
View Full Code Here

  public void testFindBestLineMatchForMemberSignatureBytecode()
  {
    Method m = getMethod("java.util.Arrays", "copyOf", new Class<?>[] { Object[].class, int.class, Class.class });
   
    MetaClass metaClass = new MetaClass(null, "java.util.arrays");
    IMetaMember member = new MetaMethod(m, metaClass);
   
    List<String> srcLinesList = new ArrayList<>();

    srcLinesList.add("public static <T extends java/lang/Object> T[] copyOf(T[], int);");
    srcLinesList
View Full Code Here

  public void testFindBestLineMatchForMemberSignatureBytecodeRegression()
  {
    Method m = getMethod("java.util.Arrays", "copyOf", new Class<?>[] { Object[].class, int.class });
       
    MetaClass metaClass = new MetaClass(null, "java.util.arrays");
    IMetaMember member = new MetaMethod(m, metaClass);

    List<String> srcLinesList = new ArrayList<>();

    srcLinesList
        .add("public static <T extends java/lang/Object, U extends java/lang/Object> T[] copyOf(U[], int, java.lang.Class<? extends T[]>);");
View Full Code Here

    String className = "java.lang.StringBuilder";
    String methodName = "charAt";

    Method m = getMethod(className, methodName, new Class<?>[] { int.class });
    MetaMethod method = new MetaMethod(m, null);

    String uqToString = method.toStringUnqualifiedMethodName(false);

    assertEquals(-1, uqToString.indexOf("volatile"));
  }
View Full Code Here

    String testMethodName = "unicodeMethodNameµµµµµ";

    Method method = getClass().getDeclaredMethod(testMethodName, new Class[0]);

    MetaMethod testMethod = new MetaMethod(method, metaClass);

    String sourceSig = "public void unicodeMethodNameµµµµµ()";

    Matcher matcher = Pattern.compile(testMethod.getSignatureRegEx()).matcher(sourceSig);
    boolean match = matcher.find();
    assertTrue(match);
  }
View Full Code Here

  {
    String className = "java.lang.StringBuilder";
    String methodName = "charAt";

    Method m = getMethod(className, methodName, new Class<?>[] { int.class });
    MetaMethod method = new MetaMethod(m, null);

    String bcSig = method.getSignatureForBytecode();

    ClassBC classBytecode = BytecodeLoader.fetchBytecodeForClass(new ArrayList<String>(), className);

    MemberBytecode memberBytecode = classBytecode.getMemberBytecode(bcSig);
View Full Code Here

        MetaPackage fakePackage = new MetaPackage("java.lang");

        MetaClass fakeClass = new MetaClass(fakePackage, "java.lang.Object");

        IMetaMember fakeMember = new MetaMethod(objToStringMethod, fakeClass);

        putMap(logSignature, fakeMember);

        return map.get(logSignature);
      }
View Full Code Here

TOP

Related Classes of org.adoptopenjdk.jitwatch.model.MetaMethod

Copyright © 2018 www.massapicom. 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.