当前位置: 首页>>代码示例>>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;未经允许,请勿转载。