微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.eclipse.xtext.xbase.lib.Functions的实例源码

项目:xtext-extras    文件XFunctionTypeRefs.java   
public static String buildUri(final boolean procedure,final int functionParamCount) {
  final int paramCount = Math.min(6,functionParamCount);
  if (procedure) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("java:/Objects/");
    String _canonicalName = Procedures.class.getCanonicalName();
    _builder.append(_canonicalName);
    _builder.append("#");
    String _canonicalName_1 = Procedures.class.getCanonicalName();
    _builder.append(_canonicalName_1);
    _builder.append("$Procedure");
    _builder.append(paramCount);
    return _builder.toString();
  }
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("java:/Objects/");
  String _canonicalName_2 = Functions.class.getCanonicalName();
  _builder_1.append(_canonicalName_2);
  _builder_1.append("#");
  String _canonicalName_3 = Functions.class.getCanonicalName();
  _builder_1.append(_canonicalName_3);
  _builder_1.append("$Function");
  _builder_1.append(paramCount);
  return _builder_1.toString();
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_exceptionInFilter() {
    final RuntimeException expectedException = new RuntimeException();
    Function1<Integer,Boolean> filter = new Functions.Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            throw expectedException;
        }
    };
    for(IterableOrIterator testMe: testData(first,second,third)) {
        try {
            findFirst(testMe,filter);
            fail("expected exception");
        } catch(RuntimeException e) {
            assertSame(expectedException,e);
        }
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_exceptionInFilter() {
    final RuntimeException expectedException = new RuntimeException();
    Function1<Integer,third)) {
        try {
            findLast(testMe,e);
        }
    }
}
项目:xtext-extras    文件ClosureClient2.java   
public ClosureClient2(Functions.Function0<String>... functions) {
    StringBuilder builder = new StringBuilder("varargs:");
    for(Functions.Function0<String> function: functions) {
        builder.append(function.apply());
    }
    value = builder.toString();
}
项目:xtext-extras    文件ClosureClient.java   
public <Obj> Functions.Function1<Obj,Obj> getIdentityFunction() {
    return new Functions.Function1<Obj,Obj>() {
        @Override
        public Obj apply(Obj p) {
            return p;
        }

    };
}
项目:xtext-extras    文件ClosureClient.java   
/**
 * @since 2.3
 */
public String concatStrings(Functions.Function0<String>... functions) {
    StringBuilder result = new StringBuilder("varargs:");
    for(Functions.Function0<String> function: functions) {
        result.append(function.apply());
    }
    return result.toString();
}
项目:xtext-extras    文件ClosureClient.java   
/**
 * @since 2.3
 */
public String concatStrings(Functions.Function0<String> function1,Functions.Function0<String> function2) {
    StringBuilder result = new StringBuilder("twoArgs:");
    result.append(function1.apply());
    result.append(function2.apply());
    return result.toString();
}
项目:xtext-extras    文件OnTheFlyJavaCompiler.java   
@SuppressWarnings("unchecked")
public <RT,T1,T2> Functions.Function2<T1,T2,RT> createFunction(
        String body,Class<RT> returnType,Class<T1> paramType1,Class<T2> paramType2) {
    return (Functions.Function2<T1,RT>) internalCreateFunction(body,returnType,Tuples.pair((Type) paramType1,"p1"),Tuples.pair((Type) paramType2,"p2"));
}
项目:xtext-extras    文件FunctionTypes.java   
private Class<?> loadFunctionClass(String simpleFunctionName,boolean procedure) {
    try {
        if (!procedure) {
            return Functions.class.getClassLoader().loadClass(
                    Functions.class.getCanonicalName() + "$" + simpleFunctionName);
        } else {
            return Procedures.class.getClassLoader().loadClass(
                    Procedures.class.getCanonicalName() + "$" + simpleFunctionName);
        }
    } catch (ClassNotFoundException e) {
        throw new WrappedException(e);
    }
}
项目:xtext-extras    文件FunctionTypes.java   
public FunctionTypeKind getFunctionTypeKind(ParameterizedTypeReference typeReference) {
    JvmType type = typeReference.getType();
    if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
        JvmDeclaredType outerType = ((JvmGenericType) type).getDeclaringType();
        if (outerType != null) {
            if (Procedures.class.getName().equals(outerType.getIdentifier())) {
                return FunctionTypeKind.PROCEDURE;
            }
            if (Functions.class.getName().equals(outerType.getIdentifier())) {
                return FunctionTypeKind.FUNCTION;
            }
        }
    }
    return FunctionTypeKind.NONE;
}
项目:xtext-extras    文件XbaseInterpreter.java   
protected Object _doEvaluate(XClosure closure,IEvaluationContext context,CancelIndicator indicator) {
    Class<?> functionIntf = null;
    switch (closure.getFormalParameters().size()) {
        case 0:
            functionIntf = getClass(Functions.Function0.class);
            break;
        case 1:
            functionIntf = getClass(Functions.Function1.class);
            break;
        case 2:
            functionIntf = getClass(Functions.Function2.class);
            break;
        case 3:
            functionIntf = getClass(Functions.Function3.class);
            break;
        case 4:
            functionIntf = getClass(Functions.Function4.class);
            break;
        case 5:
            functionIntf = getClass(Functions.Function5.class);
            break;
        case 6:
            functionIntf = getClass(Functions.Function6.class);
            break;
        default:
            throw new IllegalStateException("Closures with more then 6 parameters are not supported.");
    }
    ClosureInvocationHandler invocationHandler = new ClosureInvocationHandler(closure,context,this,indicator);
    Object proxy = Proxy.newProxyInstance(classLoader,new Class<?>[] { functionIntf },invocationHandler);
    return proxy;
}
项目:xtext-extras    文件EvaluationCompilerTest.java   
protected Functions.Function0<Object> compile(String code) {
    String javaCode = compiletoJavaCode(code);
    try {
        Function0<Object> function = javaCompiler.createFunction(javaCode,Object.class);
        return function;
    } catch (Exception e) {
        throw new RuntimeException("Java compilation Failed. Java code was : \n" + javaCode,e);
    }
}
项目:xtext-extras    文件XbaseExpectedTypeProviderTest.java   
@Test public void testTypeParamInference_04() throws Exception {
    XBlockExpression block = (XBlockExpression) expression("{ var Integer i = new testdata.ClosureClient().invoke1([e|null],'foo') }");
    XVariableDeclaration var = (XVariableDeclaration) block.getExpressions().get(0);
    XMemberFeatureCall fc = (XMemberFeatureCall) var.getRight();
    final XExpression closure = fc.getMemberCallArguments().get(0);
    assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String,java.lang.Integer>",closure);
}
项目:xtext-extras    文件XbaseExpectedTypeProviderTest.java   
@Test
public void testTypeParamInference_07() throws Exception {
    XBlockExpression block = (XBlockExpression) expression("{ var this = new testdata.ClosureClient() invoke1([ String e|e.length],'foo') }");
    XFeatureCall fc = (XFeatureCall) block.getExpressions().get(1);
    final XExpression closure = fc.getFeatureCallArguments().get(0);
    assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String,closure);
}
项目:xtext-extras    文件XbaseExpectedTypeProviderTest.java   
@Test
public void testTypeParamInference_07_b() throws Exception {
    XBlockExpression block = (XBlockExpression) expression("{ var this = new testdata.ClosureClient() invoke1([ e|e.length],closure);
}
项目:xtext-extras    文件XbaseExpectedTypeProviderTest.java   
@Test public void testTypeParamInference_09() throws Exception {
    XBlockExpression block = (XBlockExpression) expression("{ var this = new testdata.ClosureClient() var Integer i = invoke1([e|null],'foo') }");
    XVariableDeclaration var = (XVariableDeclaration) block.getExpressions().get(1);
    XFeatureCall fc = (XFeatureCall) var.getRight();
    final XExpression closure = fc.getFeatureCallArguments().get(0);
    assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String,closure);
}
项目:xtext-extras    文件AbstractXbaseLinkingTest.java   
@Test public void testRecursiveClosure_02() throws Exception {
    XBlockExpression block = (XBlockExpression) expression("{ val (int)=>int fun = [ self.apply(it) ] }");
    XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
    XClosure closure = (XClosure) variable.getRight();
    XBlockExpression body = (XBlockExpression) closure.getExpression();
    XMemberFeatureCall member = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall recursive = (XFeatureCall) member.getMemberCallTarget();
    assertEquals(Functions.Function1.class.getName(),recursive.getFeature().getQualifiedname('$'));
}
项目:xtext-extras    文件OnTheFlyJavaCompilerTest.java   
@Before
public void setUp() throws Exception {
    compiler.setTemporaryFolder(tempFolder);
    compiler.setParentClassLoader(OnTheFlyJavaCompilerTest.class.getClassLoader());
    compiler.addClasspathOfClass(OnTheFlyJavaCompilerTest.class);
    compiler.addClasspathOfClass(Functions.class);
}
项目:xtext-extras    文件OnTheFlyJavaCompilerTest.java   
@SuppressWarnings("unchecked")
@Test public void testCompiletoClass() throws Exception {
    Class<?> class1 = compiler.compiletoClass("Foo","public class Foo implements "+Functions.Function0.class.getCanonicalName()+"<String> {" +
            "   public String apply() {\n" + 
            "      return \"foo\";\n" + 
            "   }" +
            "}");
    assertEquals("foo",((Functions.Function0<String>)class1.newInstance()).apply());
}
项目:xtext-lib    文件IteratorExtensionsTest.java   
@Test public void testFlatMap () {
    ArrayList<String> list = newArrayList("foo","bar");

    final Functions.Function1<String,Iterator<String>> function = new Functions.Function1<String,Iterator<String>>() {
        @Override
        public Iterator<String> apply(String p) {
            return newArrayList("Hello",p).iterator();
        }
    };
    assertEquals(newArrayList("Hello","foo","Hello","bar"),newArrayList(IteratorExtensions.flatMap(list.iterator(),function)));
}
项目:xtext-lib    文件IterableExtensionsTest.java   
@Test public void testSortBy() throws Exception {
    List<? extends CharSequence> list = newArrayList("foo","bar","baz");
    List<? extends CharSequence> sorted = IterableExtensions.sortBy(list,new Functions.Function1<CharSequence,String>() {
        @Override
        public String apply(CharSequence p) {
            return p.toString();
        }
    });
    assertNotSame(list,sorted);
    assertEquals(sorted,newArrayList("bar","baz","foo"));
}
项目:xtext-lib    文件IterableExtensionsTest.java   
@Test public void testJoinWithBeforeAndAfter() throws Exception {
    ArrayList<String> list = newArrayList("foo","bar");
    ArrayList<String> singletonList = newArrayList("foo");
    ArrayList<String> emptylist = new ArrayList<String>();

    final Functions.Function1<String,String> function = new Functions.Function1<String,String>() {
        @Override
        public String apply(String p) {
            return p;
        }
    };
    assertEquals("<foo,bar>",IterableExtensions.join(list,"<",",">",function));
    assertEquals("<foo>",IterableExtensions.join(singletonList,function));
    assertEquals("",IterableExtensions.join(emptylist,function));

    assertEquals("foo,null,function));
    assertEquals("foo>",function));

    assertEquals("<foobar>",function));

    assertEquals("<foo,bar",function));
    assertEquals("<foo",function));
}
项目:xtext-lib    文件IterableExtensionsTest.java   
@Test public void testFlatMap () {
    ArrayList<String> list = newArrayList("foo",Iterable<String>> function = new Functions.Function1<String,Iterable<String>>() {
        @Override
        public Iterable<String> apply(String p) {
            return newArrayList("Hello",p);
        }
    };
    assertEquals(newArrayList("Hello",newArrayList(IterableExtensions.flatMap(list,function)));
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_empty() {
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            return true;
        }
    };
    for(IterableOrIterator testMe: testData()) {
        Integer last = findFirst(testMe,filter);
        assertNull("empty input yields null",last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_nomatch() {
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            return false;
        }
    };
    for(IterableOrIterator testMe: testData(first,third)) {
        Integer last = findFirst(testMe,filter);
        assertNull("unmatched input yields null",last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_allMatches() {
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            return true;
        }
    };
    for(IterableOrIterator testMe: testData(first,filter);
        assertEquals(first,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_onematch() {
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            return second.equals(p);
        }
    };
    for(IterableOrIterator testMe: testData(first,filter);
        assertEquals(second,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_exceptionInFilter_emptyinput() {
    final RuntimeException expectedException = new RuntimeException();
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            throw expectedException;
        }
    };
    for(IterableOrIterator testMe: testData()) {
        assertNull(findFirst(testMe,filter));
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindFirst_NPE_noinput() {
    try {
        findLast(null,new Functions.Function1<Integer,Boolean>() {
            @Override
            public Boolean apply(Integer p) {
                return true;
            }
        });
        fail("Expected NPE");
    } catch(NullPointerException npe) {
        // expected
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_empty() {
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            return true;
        }
    };
    for(IterableOrIterator testMe: testData()) {
        Integer last = findLast(testMe,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_nomatch() {
    Function1<Integer,third)) {
        Integer last = findLast(testMe,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_allMatches() {
    Function1<Integer,filter);
        assertEquals(third,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_onematch() {
    Function1<Integer,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_exceptionInFilter_emptyinput() {
    final RuntimeException expectedException = new RuntimeException();
    Function1<Integer,Boolean>() {
        @Override
        public Boolean apply(Integer p) {
            throw expectedException;
        }
    };
    for(IterableOrIterator testMe: testData()) {
        Integer last = findLast(testMe,filter);
        assertEquals(null,last);
    }
}
项目:xtext-lib    文件BaseIterablesIteratorsTest.java   
@Test public void testFindLast_NPE_noinput() {
    try {
        findLast(null,Boolean>() {
            @Override
            public Boolean apply(Integer p) {
                return true;
            }
        });
        fail("Expected NPE");
    } catch(NullPointerException npe) {
        // expected
    }
}
项目:xtext-core    文件AntlrGrammarGenUtil.java   
/**
 * @since 2.9
 */
public static String getDefaultArgumentList(ParserRule rule) {
    String result = IterableExtensions.join(rule.getParameters(),"[","]",new Functions.Function1<Parameter,String>() {
        @Override
        public String apply(Parameter p) {
            return Boolean.FALSE.toString();
        }
    });
    return result;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。