當前位置: 首頁>>代碼示例>>Java>>正文


Java Expression類代碼示例

本文整理匯總了Java中java.beans.Expression的典型用法代碼示例。如果您正苦於以下問題:Java Expression類的具體用法?Java Expression怎麽用?Java Expression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Expression類屬於java.beans包,在下文中一共展示了Expression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: instantiate

import java.beans.Expression; //導入依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;

  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class.
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:ClassPersistenceDelegate.java

示例2: instantiate

import java.beans.Expression; //導入依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class type = oldInstance.getClass().getComponentType();

  // oldInstance is expected to be an array, then
  // getClass().getComponentType() should lead
  // to its component type.
  assert (type != null);

  // Not handling primitive types in a special way here
  // causes that Class.forName("int") is built as an Expression
  // later which would cause an exception if executed. A special
  // handling to avoid the execution for primitive types can be
  // java.beans.Encoder.writeExpression() .
  return new Expression(
                        oldInstance,
                        Array.class,
                        "newInstance",
                        new Object[] {
                          type,
                          new Integer(Array.getLength(oldInstance)) });
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:23,代碼來源:ArrayPersistenceDelegate.java

示例3: instantiate

import java.beans.Expression; //導入依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;
  
  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class. 
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:18,代碼來源:ClassPersistenceDelegate.java

示例4: instantiate

import java.beans.Expression; //導入依賴的package包/類
@Override
protected Expression instantiate( Object oldInstance, Encoder out ) {
    Class type = oldInstance.getClass();
    if ( !Modifier.isPublic( type.getModifiers() ) )
        throw new IllegalArgumentException( "Could not instantiate instance of non-public class: " + oldInstance );
    
    for ( Field field : type.getFields() ) {
        int mod = field.getModifiers();
        if ( Modifier.isPublic( mod ) && Modifier.isStatic( mod ) && Modifier.isFinal( mod ) && ( type == field.getDeclaringClass() ) ) {
            try {
                if ( oldInstance == field.get( null ) )
                    return new Expression( oldInstance, field, "get", new Object[]{null} );
            } catch ( IllegalAccessException exception ) {
                throw new IllegalArgumentException( "Could not get value of the field: " + field, exception );
            }
        }
    }
    throw new IllegalArgumentException( "Could not instantiate value: " + oldInstance );
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:20,代碼來源:PainterUtil.java

示例5: testDiamond

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testDiamond() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 7) {
        compile("import java.util.List; import java.util.LinkedList; public class A{ List<Integer> bar = new LinkedList<>(); }");
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
        symTable.pushSymbol("a", ReferenceType.VARIABLE, st, null);
        FieldAccessExpr expr = (FieldAccessExpr) ASTManager.parse(Expression.class, "a.bar");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("java.util.List", type.getName());
        Assert.assertNotNull(type.getParameterizedTypes());
        Assert.assertEquals("java.lang.Integer", type.getParameterizedTypes().get(0).getName());
    }
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:19,代碼來源:TypeVisitorAdapterTest.java

示例6: testTargetInference

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testTargetInference() throws Exception {

    compile("import java.util.Collections; " + "import java.util.List; "
            + "public class A { public static void processStringList(List<String> stringList) {}}");
    SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
    SymbolTable symTable = getSymbolTable();
    symTable.pushScope();
    symTable.pushSymbol("A", ReferenceType.TYPE, st, null);

    MethodCallExpr expr =
            (MethodCallExpr) ASTManager.parse(Expression.class, "A.processStringList(Collections.emptyList());");
    HashMap<String, Object> ctx = new HashMap<String, Object>();
    expressionAnalyzer.visit(expr, ctx);
    SymbolType type = (SymbolType) expr.getSymbolData();
    Assert.assertNotNull(type);
    Assert.assertEquals("void", type.getName());
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:19,代碼來源:TypeVisitorAdapterTest.java

示例7: testLambdaExpressionsWithExplicitArgs

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testLambdaExpressionsWithExplicitArgs() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 8) {
        String BCode = "public interface B { public int execute(int c); } ";

        compile("public class A{ public void run(B b){} " + BCode + "}");
        SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        symTable.pushSymbol("a", ReferenceType.TYPE, st, null);

        MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class, "a.run((int d)->d+1)");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("A$B", type.getMethod().getParameterTypes()[0].getName());
    }
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:20,代碼來源:TypeVisitorAdapterTest.java

示例8: testMethodReferencesToConstructors

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testMethodReferencesToConstructors() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 8) {
        compile("import java.util.HashSet; public class A{ public static void foo(B b) {} public interface B{ public Object get();}}");
        SymbolTable symTable = getSymbolTable();
        symTable.pushSymbol("this", ReferenceType.TYPE, new SymbolType(getClassLoader().loadClass("A")), null);
        MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class, "A.foo(HashSet::new)");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("foo", type.getMethod().getName());
        MethodReferenceExpr arg1 = (MethodReferenceExpr) expr.getArgs().get(0);

        SymbolType methodType = (SymbolType) arg1.getReferencedMethodSymbolData();
        Assert.assertNotNull(methodType);
        Assert.assertEquals("get", methodType.getMethod().getName());
    }
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:20,代碼來源:TypeVisitorAdapterTest.java

示例9: testTargetInferenceShouldFail

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testTargetInferenceShouldFail() throws Exception {

    compile("import java.util.Collections; " + "import java.util.List; "
            + "public class A { public static <T> void processStringList(T[] args) {}}");
    SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
    SymbolTable symTable = getSymbolTable();
    symTable.pushScope();
    symTable.pushSymbol("A", ReferenceType.TYPE, st, null);

    try {
        MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class,
                "A.processStringList(Collections.emptyList());");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        fail("should not be reached: type=" + expr.getSymbolData().getMethod());
    } catch (NoSuchExpressionTypeException e) {
        Assert.assertTrue(e.getMessage(), e.getMessage()
                .contains("Ops! The method call A.processStringList(Collections.emptyList()) is not resolved"));
    }
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:22,代碼來源:TypeVisitorAdapterTest.java

示例10: testStatic

import java.beans.Expression; //導入依賴的package包/類
/**
 * The test checks the correct static method is initialized
 */
public void testStatic() throws Exception {
    SampleBean theBean = new SampleBean();
    Expression expr = new Expression(SampleBean.class, "create",
            new Object[] { "hello", theBean });

    Object result = expr.getValue();
    if (result != null && result instanceof SampleBean) {
        SampleBean bean = (SampleBean) result;
        assertEquals("hello", bean.getText());
        assertEquals(theBean, bean.getObject());
    } else {
        fail("Cannot instantiate an instance of Bean class by "
                + "static method.");
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:19,代碼來源:ExpressionTest.java

示例11: testMethodReferencesToAnArrayItem

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testMethodReferencesToAnArrayItem() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 8) {
        compile("import java.util.Arrays; public class A{}");
        SymbolType st = new SymbolType(String.class);
        st.setArrayCount(1);
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        symTable.pushSymbol("stringArray", ReferenceType.TYPE, st, null);
        symTable.pushSymbol("this", ReferenceType.TYPE, new SymbolType(getClassLoader().loadClass("A")), null);
        MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class,
                "Arrays.sort(stringArray, String::compareToIgnoreCase)");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("sort", type.getMethod().getName());
        MethodReferenceExpr arg1 = (MethodReferenceExpr) expr.getArgs().get(1);

        SymbolType methodType = (SymbolType) arg1.getReferencedMethodSymbolData();
        Assert.assertNotNull(methodType);
        Assert.assertEquals("compare", methodType.getMethod().getName());
    }
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:25,代碼來源:TypeVisitorAdapterTest.java

示例12: testGenericMethodsExplicitTypeInvocation

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testGenericMethodsExplicitTypeInvocation() throws Exception {
    compile("import java.util.ArrayList; import java.io.Serializable;"
            + " public class A { public static <T> T pick(T a1, T a2) { return a2; }}");
    SymbolTable symTable = getSymbolTable();
    ASTSymbolTypeResolver.getInstance().setSymbolTable(symTable);
    symTable.pushScope();
    SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
    symTable.pushSymbol("A", ReferenceType.TYPE, st, null);

    MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class,
            "A.<Serializable>pick(\"d\", new ArrayList<String>())");
    HashMap<String, Object> ctx = new HashMap<String, Object>();
    expressionAnalyzer.visit(expr, ctx);
    SymbolType type = (SymbolType) expr.getSymbolData();
    Assert.assertNotNull(type);
    Assert.assertEquals("java.io.Serializable", type.getName());
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:19,代碼來源:TypeVisitorAdapterTest.java

示例13: testTargetInference2

import java.beans.Expression; //導入依賴的package包/類
public void testTargetInference2() throws Exception {

        compile("import java.util.Collections; " + "import java.util.List; "
                + "public class A { public static void processAList(List<A> stringList) {}}");
        SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        symTable.pushSymbol("A", ReferenceType.TYPE, st, null);

        MethodCallExpr expr =
                (MethodCallExpr) ASTManager.parse(Expression.class, "A.processAList(Collections.emptyList());");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("void", type.getName());
    }
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:18,代碼來源:TypeVisitorAdapterTest.java

示例14: testReferencesToInnerClasses

import java.beans.Expression; //導入依賴的package包/類
@Test
public void testReferencesToInnerClasses() throws Exception {
    compile(true, "public class OuterClass { public class InnerClass { } }");

    SymbolTable symTable = getSymbolTable();
    ASTSymbolTypeResolver.getInstance().setSymbolTable(symTable);
    symTable.pushScope();
    SymbolType st = new SymbolType(getClassLoader().loadClass("OuterClass"));
    symTable.pushSymbol("outerObject", ReferenceType.VARIABLE, st, null);
    org.walkmod.javalang.ast.expr.Expression expr = (org.walkmod.javalang.ast.expr.Expression) ASTManager
            .parse(Expression.class, "outerObject.new InnerClass()");
    HashMap<String, Object> ctx = new HashMap<String, Object>();
    expr.accept(expressionAnalyzer, ctx);
    SymbolType type = (SymbolType) expr.getSymbolData();
    Assert.assertNotNull(type);
    Assert.assertEquals("OuterClass$InnerClass", type.getName());
}
 
開發者ID:rpau,項目名稱:javalang-compiler,代碼行數:18,代碼來源:TypeVisitorAdapterTest.java

示例15: instantiate

import java.beans.Expression; //導入依賴的package包/類
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
    byte[] e = (byte[]) oldInstance;
    return new Expression(e, ByteArrayPersistenceDelegate.class,
            "decode",
            new Object[] { ByteArrayPersistenceDelegate.encode(e) });
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:8,代碼來源:XMLSerializer.java


注:本文中的java.beans.Expression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。