Java 类org.eclipse.xtext.xbase.lib.Functions.Function0 实例源码

项目:xtext-core    文件:RequestManagerTest.java   
@Test(timeout = 1000)
public void testRunReadAfterWrite() {
  try {
    final Function0<Object> _function = () -> {
      return null;
    };
    final Function2<CancelIndicator, Object, Integer> _function_1 = (CancelIndicator $0, Object $1) -> {
      return Integer.valueOf(this.sharedState.incrementAndGet());
    };
    this.requestManager.<Object, Integer>runWrite(_function, _function_1);
    final Function1<CancelIndicator, Integer> _function_2 = (CancelIndicator it) -> {
      return Integer.valueOf(this.sharedState.get());
    };
    final CompletableFuture<Integer> future = this.requestManager.<Integer>runRead(_function_2);
    Assert.assertEquals(1, (future.get()).intValue());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:RequestManagerTest.java   
@Test(timeout = 1000)
public void testRunWriteAfterRead() {
  final Function1<CancelIndicator, Integer> _function = (CancelIndicator it) -> {
    return Integer.valueOf(this.sharedState.incrementAndGet());
  };
  final CompletableFuture<Integer> previsousRead = this.requestManager.<Integer>runRead(_function);
  final Function0<Object> _function_1 = () -> {
    return null;
  };
  final Function2<CancelIndicator, Object, Integer> _function_2 = (CancelIndicator $0, Object $1) -> {
    int _xblockexpression = (int) 0;
    {
      while (((this.sharedState.get() == 0) && (!previsousRead.isCancelled()))) {
      }
      _xblockexpression = this.sharedState.incrementAndGet();
    }
    return Integer.valueOf(_xblockexpression);
  };
  this.requestManager.<Object, Integer>runWrite(_function_1, _function_2).join();
  Assert.assertEquals(2, this.sharedState.get());
}
项目:abattle    文件:DebugCells.java   
public DebugCells() {
  super(
    new Function0<String>() {
      @Override
      public String apply() {
        ComponentLookup _instance = ComponentLookup.getInstance();
        ConfigurationComponent _component = _instance.<ConfigurationComponent>getComponent(ConfigurationComponent.class);
        GraphicsConfigurationData _graphicsConfiguration = _component.getGraphicsConfiguration();
        return _graphicsConfiguration.getDebugCell();
      }
    }, 
    NoDebug.NAME);
  NoDebug _noDebug = new NoDebug();
  this.addSectableClass(_noDebug);
  HeightDebug _heightDebug = new HeightDebug();
  this.addSectableClass(_heightDebug);
  StrengthDebug _strengthDebug = new StrengthDebug();
  this.addSectableClass(_strengthDebug);
}
项目:abattle    文件:Fogs.java   
public Fogs() {
  super(
    new Function0<String>() {
      @Override
      public String apply() {
        ComponentLookup _instance = ComponentLookup.getInstance();
        ConfigurationComponent _component = _instance.<ConfigurationComponent>getComponent(ConfigurationComponent.class);
        GameConfigurationData _gameConfiguration = _component.getGameConfiguration();
        return _gameConfiguration.getFog();
      }
    }, SimpleFog.NAME);
  SimpleFog _simpleFog = new SimpleFog();
  this.addSectableClass(_simpleFog);
  NoFog _noFog = new NoFog();
  this.addSectableClass(_noFog);
}
项目:abattle    文件:Logics.java   
public Logics() {
  super(
    new Function0<String>() {
      @Override
      public String apply() {
        ComponentLookup _instance = ComponentLookup.getInstance();
        ConfigurationComponent _component = _instance.<ConfigurationComponent>getComponent(ConfigurationComponent.class);
        GameConfigurationData _gameConfiguration = _component.getGameConfiguration();
        return _gameConfiguration.getLogic();
      }
    }, 
    XBattleDistribute.NAME);
  SimpleDistributeArmies _simpleDistributeArmies = new SimpleDistributeArmies();
  this.addSectableClass(_simpleDistributeArmies);
  XBattleDistribute _xBattleDistribute = new XBattleDistribute();
  this.addSectableClass(_xBattleDistribute);
}
项目:xtext-extras    文件:OnTheFlyJavaCompiler2.java   
@SuppressWarnings("unchecked")
public <RT extends Object> Function0<RT> createFunction(final String expression, final Class<RT> returnType) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class __Generated implements org.eclipse.xtext.xbase.lib.Functions.Function0<");
    String _name = returnType.getName();
    _builder.append(_name);
    _builder.append("> {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("public ");
    String _name_1 = returnType.getName();
    _builder.append(_name_1, "\t");
    _builder.append(" apply() {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append(expression, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Class<?> clazz = this.compileToClass("__Generated", _builder.toString());
    Object _newInstance = clazz.newInstance();
    return ((Function0<RT>) _newInstance);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目: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    文件:LightweightTypeReferenceSerializerTest.java   
@Test
public void testFunctionType1() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function0.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.setReturnType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(String.class));
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "()=>java.lang.String"), "org.eclipse.xtext.xbase.lib.Functions$Function0<java.lang.String>");
}
项目:xtext-lib    文件:FunctionExtensions.java   
/**
 * Curries a function that takes one argument.
 * 
 * @param function
 *            the original function. May not be <code>null</code>.
 * @param argument
 *            the fixed argument.
 * @return a function that takes no arguments. Never <code>null</code>.
 */
@Pure
public static <P1, RESULT> Function0<RESULT> curry(final Function1<? super P1, ? extends RESULT> function, final P1 argument) {
    if (function == null)
        throw new NullPointerException("function");
    return new Function0<RESULT>() {
        @Override
        public RESULT apply() {
            return function.apply(argument);
        }
    };
}
项目:xtext-core    文件:RequestManagerTest.java   
@Test(timeout = 1000)
public void testRunWrite() {
  final Function0<Object> _function = () -> {
    return null;
  };
  final Function2<CancelIndicator, Object, Integer> _function_1 = (CancelIndicator $0, Object $1) -> {
    return Integer.valueOf(this.sharedState.incrementAndGet());
  };
  this.requestManager.<Object, Integer>runWrite(_function, _function_1).join();
  Assert.assertEquals(1, this.sharedState.get());
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public void didOpen(final DidOpenTextDocumentParams params) {
  final Function0<BuildManager.Buildable> _function = () -> {
    return this.workspaceManager.didOpen(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), params.getTextDocument().getText());
  };
  final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
    return buildable.build(cancelIndicator);
  };
  this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public void didClose(final DidCloseTextDocumentParams params) {
  final Function0<BuildManager.Buildable> _function = () -> {
    return this.workspaceManager.didClose(this._uriExtensions.toUri(params.getTextDocument().getUri()));
  };
  final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
    return buildable.build(cancelIndicator);
  };
  this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public void didChangeWatchedFiles(final DidChangeWatchedFilesParams params) {
  final Function0<BuildManager.Buildable> _function = () -> {
    BuildManager.Buildable _xblockexpression = null;
    {
      final ArrayList<URI> dirtyFiles = CollectionLiterals.<URI>newArrayList();
      final ArrayList<URI> deletedFiles = CollectionLiterals.<URI>newArrayList();
      List<FileEvent> _changes = params.getChanges();
      for (final FileEvent fileEvent : _changes) {
        FileChangeType _type = fileEvent.getType();
        boolean _tripleEquals = (_type == FileChangeType.Deleted);
        if (_tripleEquals) {
          URI _uri = this._uriExtensions.toUri(fileEvent.getUri());
          deletedFiles.add(_uri);
        } else {
          URI _uri_1 = this._uriExtensions.toUri(fileEvent.getUri());
          dirtyFiles.add(_uri_1);
        }
      }
      _xblockexpression = this.workspaceManager.didChangeFiles(dirtyFiles, deletedFiles);
    }
    return _xblockexpression;
  };
  final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
    return buildable.build(cancelIndicator);
  };
  this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public void didChangeConfiguration(final DidChangeConfigurationParams params) {
  final Function0<Object> _function = () -> {
    this.workspaceManager.refreshWorkspaceConfig(CancelIndicator.NullImpl);
    return null;
  };
  final Function2<CancelIndicator, Object, Object> _function_1 = (CancelIndicator $0, Object $1) -> {
    return null;
  };
  this.requestManager.<Object, Object>runWrite(_function, _function_1);
}
项目:xtext-core    文件:RequestManager.java   
public <U extends Object, V extends Object> CompletableFuture<V> runWrite(final Function0<? extends U> nonCancellable, final Function2<? super CancelIndicator, ? super U, ? extends V> request) {
  final CompletableFuture<V> result = new CompletableFuture<V>();
  final CompletableFuture<Void> localWritePending = new CompletableFuture<Void>();
  this.writePending = localWritePending;
  final Callable<Boolean> _function = () -> {
    boolean _xblockexpression = false;
    {
      final RequestCancelIndicator cancelIndicator = new RequestCancelIndicator(result);
      boolean _xtrycatchfinallyexpression = false;
      try {
        boolean _xblockexpression_1 = false;
        {
          this.cancel();
          this.w.lock();
          localWritePending.complete(null);
          final U intermediateResult = nonCancellable.apply();
          this.toCancel.add(cancelIndicator);
          cancelIndicator.checkCanceled();
          _xblockexpression_1 = result.complete(request.apply(cancelIndicator, intermediateResult));
        }
        _xtrycatchfinallyexpression = _xblockexpression_1;
      } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
          final Throwable e = (Throwable)_t;
          _xtrycatchfinallyexpression = result.completeExceptionally(e);
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      } finally {
        this.toCancel.remove(cancelIndicator);
        this.w.unlock();
      }
      _xblockexpression = _xtrycatchfinallyexpression;
    }
    return Boolean.valueOf(_xblockexpression);
  };
  this.parallel.<Boolean>submit(_function);
  return result;
}
项目:Util    文件:SafeCallExtension.java   
/**
 * Calls some code safely.
 * Never throws an Exception.
 * @return
 * @return onError; if the code fails, otherwise the return value of call().
 */
public static <R> R attempt(final Function0<R> code, final R onError) {
    try {
        return code.apply();
    } catch (final Throwable t) {
        LOG.log(Level.SEVERE, t.getMessage(), t);
        return onError;
    }
}
项目:srcrepo    文件:SrcRepoActivator.java   
public static void debug(Function0<String> message) {
    if (INSTANCE.isDebug) {
        String output = message.apply();
        if (output != null) {
            INSTANCE.debug(output); 
        }           
    }
}
项目:xtext-extras    文件:OnTheFlyJavaCompiler.java   
@SuppressWarnings("unchecked")
public <RT> Functions.Function0<RT> createFunction(String expression,
        Class<RT> returnType) {
    return (Function0<RT>) internalCreateFunction(expression, returnType);
}
项目:xtext-extras    文件:LightweightTypeReferenceSerializerTest.java   
@Test
public void testFunctionType() {
  this.assertInJava(this.assertInXtend(this.getOwner().newFunctionTypeReference(this.type(Function0.class)), "()=>void"), "org.eclipse.xtext.xbase.lib.Functions$Function0");
}
项目:xtext-gef    文件:EmbeddedResourceValidator.java   
@Pure
public Function0<? extends String> getEmbeddedTextProvider() {
  return this.embeddedTextProvider;
}
项目:xtext-gef    文件:EmbeddedResourceValidator.java   
public void setEmbeddedTextProvider(final Function0<? extends String> embeddedTextProvider) {
  this.embeddedTextProvider = embeddedTextProvider;
}
项目:xtext-gef    文件:EmbeddedResourceValidator.java   
@Pure
public Function0<? extends ITextRegion> getVisibleRegionProvider() {
  return this.visibleRegionProvider;
}
项目:xtext-gef    文件:EmbeddedResourceValidator.java   
public void setVisibleRegionProvider(final Function0<? extends ITextRegion> visibleRegionProvider) {
  this.visibleRegionProvider = visibleRegionProvider;
}
项目:abattle    文件:SelectableClassList.java   
public SelectableClassList(final Function0<String> getter, final String defaultName) {
  HashMap<String, T> _newHashMap = CollectionLiterals.<String, T>newHashMap();
  this.classMap = _newHashMap;
  this.getter = getter;
  this.defaultName = defaultName;
}
项目:Util    文件:SafeCallExtension.java   
/**
 * Calls some code safely.
 * Never throws an Exception.
 * @return
 * @return null if the code fails, otherwise the return value of call().
 */
@Inline("com.blockwithme.util.xtend.SafeCallExtension.attempt($1, null)")
public static <R> R attempt(final Function0<R> code) {
    return attempt(code, null);
}