org.eclipse.xtext.xbase.lib.Functions.Function2 Java Examples

The following examples show how to use org.eclipse.xtext.xbase.lib.Functions.Function2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #2
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000, expected = ExecutionException.class)
public void testRunWriteCatchException() {
  final Runnable _function = () -> {
    try {
      final Function0<Object> _function_1 = () -> {
        throw new RuntimeException();
      };
      final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
        return null;
      };
      final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
      Assert.assertEquals("Foo", future.get());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  };
  LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  Assert.fail("unreachable");
}
 
Example #3
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Evaluate the predicates.
 *
 * @param helper the helper.
 * @param operation the operation to adapt.
 * @param context the context or {@code null} if none.
 * @return the view to the operation with adaptations.
 */
public boolean applyAdaptations(IOperationHelper helper, JvmOperation operation, ISideEffectContext context) {
	synchronized (this) {
		if (this.predicates != null && !this.predicates.isEmpty()) {
			for (final Function2<? super JvmOperation, ? super IOperationHelper, ? extends Boolean> predicate : this.predicates) {
				final IOperationHelper hlp;
				if (context != null && helper instanceof SARLOperationHelper) {
					hlp = new SubHelper((SARLOperationHelper) helper, context);
				} else {
					hlp = helper;
				}
				final Boolean bool = predicate.apply(operation, hlp);
				if (bool != null && bool.booleanValue()) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #4
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunWriteLogExceptionCancellable() {
  final Runnable _function = () -> {
    final Function0<Object> _function_1 = () -> {
      throw new RuntimeException();
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
      return null;
    };
    final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example #5
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunWriteLogExceptionNonCancellable() {
  final Runnable _function = () -> {
    final Function0<Object> _function_1 = () -> {
      return null;
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
      throw new RuntimeException();
    };
    final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example #6
Source File: AbstractExternalHighlightingFragment2.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Write the given lines into the file.
 *
 * @param basename the basename of the file.
 * @param content the content of the style file.
 * @param outputDirectoryFilter the output directory.
 * @throws RuntimeException a runtime exception
 * @since 0.6
 */
protected void writeFile(String basename, byte[] content,
		Function2<? super File, ? super String, ? extends File> outputDirectoryFilter) {
	for (final String output : getOutputs()) {
		File directory = new File(output).getAbsoluteFile();
		if (outputDirectoryFilter != null) {
			directory = outputDirectoryFilter.apply(directory, basename);
		}
		try {
			final File outputFile = new File(directory, basename);
			outputFile.getParentFile().mkdirs();
			Files.write(Paths.get(outputFile.getAbsolutePath()), content);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
 
Example #7
Source File: EclipseFileSystemSupportImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected java.net.URI toURI(final URI uri, final List<String> trailingSegments) {
  java.net.URI _xblockexpression = null;
  {
    final IResource resource = this.findMember(uri);
    if ((resource == null)) {
      String _lastSegment = uri.lastSegment();
      trailingSegments.add(_lastSegment);
      return this.toURI(uri.trimSegments(1), trailingSegments);
    }
    final Function2<IPath, String, IPath> _function = (IPath $0, String $1) -> {
      return $0.append($1);
    };
    _xblockexpression = URIUtil.toURI(IterableExtensions.<String, IPath>fold(ListExtensions.<String>reverse(trailingSegments), resource.getLocation(), _function));
  }
  return _xblockexpression;
}
 
Example #8
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public synchronized <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>();
  try {
    result.complete(request.apply(CancelIndicator.NullImpl, nonCancellable.apply()));
  } catch (final Throwable _t) {
    if (_t instanceof Throwable) {
      final Throwable t = (Throwable)_t;
      boolean _isCancelException = this.isCancelException(t);
      if (_isCancelException) {
        result.cancel(true);
      } else {
        result.completeExceptionally(t);
      }
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
  return result;
}
 
Example #9
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testConvertNullInput() throws Exception {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

		@Override
		public Object apply(String lexerRule, INode node) {
			if ("foo".equals(lexerRule) ) {
				return "FOO";
			}
			return null;
		}
	};
	DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
	factory.setConverterService(new MockedConverterService(toValueImpl));
	factory.set(eClass, "name", null, "foo", null);

	assertEquals("FOO", eClass.getName());
}
 
Example #10
Source File: Solution_023.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isAbundant(final int input) {
  final int sqrt = Double.valueOf(Math.floor(Math.sqrt(input))).intValue();
  final Function1<Integer, Boolean> _function = (Integer div) -> {
    return Boolean.valueOf((((div).intValue() != input) && ((input % (div).intValue()) == 0)));
  };
  final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
    int _xblockexpression = (int) 0;
    {
      final int other = (input / (i2).intValue());
      int _xifexpression = (int) 0;
      if (((other != (i2).intValue()) && (other != input))) {
        _xifexpression = (((i1).intValue() + (i2).intValue()) + other);
      } else {
        _xifexpression = ((i1).intValue() + (i2).intValue());
      }
      _xblockexpression = _xifexpression;
    }
    return Integer.valueOf(_xblockexpression);
  };
  final Integer sumOfDivisors = IterableExtensions.<Integer, Integer>fold(IterableExtensions.<Integer>filter(new IntegerRange(2, sqrt), _function), Integer.valueOf(1), _function_1);
  return ((sumOfDivisors).intValue() > input);
}
 
Example #11
Source File: Solution_021.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static Integer sumOfDivisors(final int input) {
  Integer _xblockexpression = null;
  {
    final int sqrt = Double.valueOf(Math.floor(Math.sqrt(input))).intValue();
    final Function1<Integer, Boolean> _function = (Integer div) -> {
      return Boolean.valueOf(((input % (div).intValue()) == 0));
    };
    final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
      int _xblockexpression_1 = (int) 0;
      {
        final int other = (input / (i2).intValue());
        int _xifexpression = (int) 0;
        if ((other != (i2).intValue())) {
          _xifexpression = (((i1).intValue() + (i2).intValue()) + other);
        } else {
          _xifexpression = ((i1).intValue() + (i2).intValue());
        }
        _xblockexpression_1 = _xifexpression;
      }
      return Integer.valueOf(_xblockexpression_1);
    };
    _xblockexpression = IterableExtensions.<Integer, Integer>fold(IterableExtensions.<Integer>filter(new IntegerRange(2, sqrt), _function), Integer.valueOf(1), _function_1);
  }
  return _xblockexpression;
}
 
Example #12
Source File: Solution_005.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  ArrayList<Integer> result = CollectionLiterals.<Integer>newArrayList();
  IntegerRange _upTo = new IntegerRange(2, 20);
  for (final Integer i : _upTo) {
    {
      Integer j = i;
      for (final Integer k : result) {
        if ((((j).intValue() % (k).intValue()) == 0)) {
          j = Integer.valueOf(((j).intValue() / (k).intValue()));
        }
      }
      if (((j).intValue() != 1)) {
        result.add(j);
      }
    }
  }
  final Function2<Integer, Integer, Integer> _function = (Integer m1, Integer m2) -> {
    return Integer.valueOf(((m1).intValue() * (m2).intValue()));
  };
  InputOutput.<Integer>println(IterableExtensions.<Integer>reduce(result, _function));
}
 
Example #13
Source File: Solution_021.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  HashSet<Integer> result = CollectionLiterals.<Integer>newHashSet();
  final int max = 10000;
  IntegerRange _upTo = new IntegerRange(1, max);
  for (final Integer i : _upTo) {
    boolean _contains = result.contains(i);
    boolean _not = (!_contains);
    if (_not) {
      final Integer sumOfDivisors = Solution_021.sumOfDivisors((i).intValue());
      if (((!Objects.equal(sumOfDivisors, i)) && ((sumOfDivisors).intValue() <= max))) {
        final Integer otherSumOfDivisors = Solution_021.sumOfDivisors((sumOfDivisors).intValue());
        boolean _equals = Objects.equal(otherSumOfDivisors, i);
        if (_equals) {
          result.add(i);
          result.add(sumOfDivisors);
        }
      }
    }
  }
  final Function2<Integer, Integer, Integer> _function = (Integer i1, Integer i2) -> {
    return Integer.valueOf(((i1).intValue() + (i2).intValue()));
  };
  InputOutput.<Integer>println(IterableExtensions.<Integer>reduce(result, _function));
}
 
Example #14
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testValueConverterException() throws Exception {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	final ILeafNode node = new LeafNode();
	final ValueConverterException expected = new ValueConverterException("Foo", node, null);
	
	Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

		@Override
		public Object apply(String lexerRule, INode nodeParam) {
			if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
				throw expected;
			}
			fail();
			return null;
		}
	};

	DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
	factory.setConverterService(new MockedConverterService(toValueImpl));
	try {
		factory.set(eClass, "abstract", null, "foo", node);
		fail("Expected ValueConverterException");
	} catch (ValueConverterException ex) {
		assertSame(expected, ex);
	}
}
 
Example #15
Source File: TemplateLiteralImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public String getValueAsString() {
	final StringBuilder result = new StringBuilder("`");
	final Function1<Expression, StringBuilder> _function = new Function1<Expression, StringBuilder>() {
		public StringBuilder apply(final Expression expr) {
			StringBuilder _switchResult = null;
			boolean _matched = false;
			if (expr instanceof Literal) {
				_matched=true;
				_switchResult = result.append(TemplateLiteralImpl.this.getValueAsString());
			}
			if (!_matched) {
				_switchResult = result.append("<<").append(TemplateLiteralImpl.this.eClass().getName()).append(">>");
			}
			return _switchResult;
		}
	};
	final Function1<Expression, StringBuilder> appender = _function;
	final Function2<Boolean, Expression, Boolean> _function_1 = new Function2<Boolean, Expression, Boolean>() {
		public Boolean apply(final Boolean isRaw, final Expression expression) {
			if ((!(isRaw).booleanValue())) {
				result.append("${");
				appender.apply(expression);
				result.append("}");
			}
			else {
				appender.apply(expression);
			}
			return Boolean.valueOf((!(isRaw).booleanValue()));
		}
	};
	IterableExtensions.<Expression, Boolean>fold(this.getSegments(), Boolean.valueOf(true), _function_1);
	result.append("`");
	return result.toString();
}
 
Example #16
Source File: WorkspaceManagerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoRead() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("type Test {");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("string foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final URI path = this.operator_mappedTo("MyType1.testlang", _builder);
  this.workspaceManger.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(path)), CollectionLiterals.<URI>emptyList(), null);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("type Test {");
  _builder_1.newLine();
  _builder_1.append("    ");
  _builder_1.append("Test foo");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  final String inMemContents = _builder_1.toString();
  this.workspaceManger.didOpen(path, Integer.valueOf(1), inMemContents).build(null);
  final Function2<Document, XtextResource, String> _function = (Document $0, XtextResource $1) -> {
    return $0.getContents();
  };
  Assert.assertEquals(inMemContents, this.workspaceManger.<String>doRead(path, _function));
}
 
Example #17
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNullInput() throws Exception {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	final ILeafNode node = new LeafNode();
	
	Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

		@Override
		public Object apply(String lexerRule, INode nodeParam) {
			if ("foo".equals(lexerRule) && nodeParam.equals(node)) {
				return null;
			}
			fail();
			return null;
		}
	};

	DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
	factory.setConverterService(new MockedConverterService(toValueImpl));
	try {
		factory.set(eClass, "abstract", null, "foo", node);
		fail("Expected ValueConverterException");
	} catch (ValueConverterException ex) {
		assertNull(ex.getCause());
		assertTrue(ex.getMessage().indexOf("ValueConverter returned null for") >= 0);
		assertSame(node, ex.getNode());
	}
}
 
Example #18
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #19
Source File: WriteRequest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public WriteRequest(RequestManager requestManager, Function0<? extends U> nonCancellable,
		Function2<? super CancelIndicator, ? super U, ? extends V> cancellable,
		CompletableFuture<Void> allPreviousRequests) {
	super(requestManager);
	this.nonCancellable = nonCancellable;
	this.cancellable = cancellable;
	this.allPreviousRequests = allPreviousRequests;
}
 
Example #20
Source File: WorkspaceManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Find the resource and the document with the given URI and performa a read operation.
 */
public <T> T doRead(URI uri, Function2<? super Document, ? super XtextResource, ? extends T> work) {
	URI resourceURI = uri.trimFragment();
	ProjectManager projectMnr = getProjectManager(resourceURI);
	if (projectMnr != null) {
		XtextResource resource = (XtextResource) projectMnr.getResource(resourceURI);
		Document doc = getDocument(resource);
		return work.apply(doc, resource);
	}
	return work.apply(null, null);
}
 
Example #21
Source File: MarkdownParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void updateBlockFormatter() {
	final Function2<String, String, String> formatter;
	if (isGithubExtensionEnable()) {
		formatter = SarlDocumentationParser.getFencedCodeBlockFormatter();
	} else {
		formatter = SarlDocumentationParser.getBasicCodeBlockFormatter();
	}
	getDocumentParser().setBlockCodeTemplate(formatter);
}
 
Example #22
Source File: SarlDocumentationParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the fenced code block formatter.
 *
 * <p>This code block formatter is usually used by Github.
 *
 * @return the formatter.
 */
public static Function2<String, String, String> getFencedCodeBlockFormatter() {
	return (languageName, content) -> {
		/*final StringBuilder result = new StringBuilder();
		result.append("<div class=\\\"highlight"); //$NON-NLS-1$
		if (!Strings.isNullOrEmpty(languageName)) {
			result.append(" highlight-").append(languageName); //$NON-NLS-1$
		}
		result.append("\"><pre>\n").append(content).append("</pre></div>\n"); //$NON-NLS-1$ //$NON-NLS-2$
		return result.toString();*/
		return "```" + Strings.nullToEmpty(languageName).toLowerCase() + "\n" //$NON-NLS-1$ //$NON-NLS-2$
				+ content
				+ "```\n"; //$NON-NLS-1$
	};
}
 
Example #23
Source File: AbstractExternalHighlightingFragment2.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Write the given lines into the file.
 *
 * @param basename the basename of the file.
 * @param content the content of the style file.
 * @param outputDirectoryFilter the output directory.
 */
protected void writeFile(String basename, T content,
		Function2<? super File, ? super String, ? extends File> outputDirectoryFilter) {
	// Create the file.
	// Encode
	final byte[] bytes = content.toString().getBytes(Charset.forName(getCodeConfig().getEncoding()));
	writeFile(basename, bytes, outputDirectoryFilter);
}
 
Example #24
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void attachPureAnnotationAdapter(JvmOperation operation,
		Function2<? super JvmOperation, ? super IOperationHelper, ? extends Boolean> dynamicCallback) {
	if (operation != null && dynamicCallback != null) {
		AnnotationJavaGenerationAdapter adapter = (AnnotationJavaGenerationAdapter) EcoreUtil.getAdapter(
				operation.eAdapters(), AnnotationJavaGenerationAdapter.class);
		if (adapter == null) {
			adapter = new AnnotationJavaGenerationAdapter();
			operation.eAdapters().add(adapter);
		}
		adapter.addPredicate(dynamicCallback);
	}
}
 
Example #25
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Add a predicate.
 *
 * @param predicate the predicate.
 */
public void addPredicate(Function2<? super JvmOperation, ? super IOperationHelper, ? extends Boolean> predicate) {
	if (predicate != null) {
		synchronized (this) {
			if (this.predicates == null) {
				this.predicates = new ArrayList<>();
			}
			this.predicates.add(predicate);
		}
	}
}
 
Example #26
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the feature call could be translated to the extra-language.
 *
 * @param featureCall the feature call.
 * @param typeErrorHandler the error handler for the type conversion.
 * @param featureErrorHandler the error handler for the feature call conversion.
 */
protected void doCheckMemberFeatureCallMapping(XAbstractFeatureCall featureCall,
		Procedure3<? super EObject, ? super JvmType, ? super String> typeErrorHandler,
		Function2<? super EObject, ? super JvmIdentifiableElement, ? extends Boolean> featureErrorHandler) {
	final XAbstractFeatureCall rootFeatureCall = Utils.getRootFeatureCall(featureCall);
	final Map<Object, Object> context = getContext().getContext();
	if (isCheckedFeatureCall(context, rootFeatureCall)) {
		// One of the containing expressions was already checked.
		return;
	}
	// Mark the root container as validated.
	setCheckedFeatureCall(context, rootFeatureCall);
	// Validate the current call.
	internalCheckMemberFeaturCallMapping(rootFeatureCall, typeErrorHandler, featureErrorHandler);
}
 
Example #27
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean internalCheckMemberFeaturCallMapping(XAbstractFeatureCall featureCall,
		Procedure3<? super EObject, ? super JvmType, ? super String> typeErrorHandler,
		Function2<? super EObject, ? super JvmIdentifiableElement, ? extends Boolean> featureErrorHandler) {
	final ExtraLanguageFeatureNameConverter converter = getFeatureNameConverter();
	if (converter != null) {
		final ConversionType conversionType = converter.getConversionTypeFor(featureCall);
		switch (conversionType) {
		case EXPLICIT:
			return true;
		case IMPLICIT:
			final JvmIdentifiableElement element = featureCall.getFeature();
			if (element instanceof JvmType) {
				return doTypeMappingCheck(featureCall, (JvmType) element, typeErrorHandler);
			}
			if (featureCall instanceof XMemberFeatureCall) {
				final XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) featureCall;
				final XExpression receiver = memberFeatureCall.getMemberCallTarget();
				if (receiver instanceof XMemberFeatureCall || receiver instanceof XFeatureCall) {
					internalCheckMemberFeaturCallMapping(
							(XAbstractFeatureCall) receiver,
							typeErrorHandler,
							featureErrorHandler);
				}
			}
			break;
		case FORBIDDEN_CONVERSION:
		default:
			if (featureErrorHandler != null) {
				return !featureErrorHandler.apply(featureCall, featureCall.getFeature());
			}
			return false;
		}
	}
	return true;
}
 
Example #28
Source File: Solution_022.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
  try {
    InputStream _resourceAsStream = Solution_022.class.getResourceAsStream("names.txt");
    InputStreamReader _inputStreamReader = new InputStreamReader(_resourceAsStream);
    final BufferedReader reader = new BufferedReader(_inputStreamReader);
    try {
      final String line = reader.readLine();
      final Matcher matcher = Pattern.compile("\"(\\w+)\"").matcher(line);
      final ArrayList<String> names = CollectionLiterals.<String>newArrayList();
      while (matcher.find()) {
        names.add(matcher.group(1));
      }
      final AtomicLong result = new AtomicLong();
      final Procedure2<String, Integer> _function = (String name, Integer i) -> {
        final Function1<Character, Integer> _function_1 = (Character it) -> {
          int _numericValue = Character.getNumericValue((it).charValue());
          return Integer.valueOf((_numericValue - 9));
        };
        final Function2<Integer, Integer, Integer> _function_2 = (Integer i1, Integer i2) -> {
          return Integer.valueOf(((i1).intValue() + (i2).intValue()));
        };
        Integer _reduce = IterableExtensions.<Integer>reduce(ListExtensions.<Character, Integer>map(((List<Character>)Conversions.doWrapArray(name.toCharArray())), _function_1), _function_2);
        int _multiply = ((_reduce).intValue() * ((i).intValue() + 1));
        result.addAndGet(_multiply);
      };
      IterableExtensions.<String>forEach(IterableExtensions.<String>sort(names), _function);
      InputOutput.<AtomicLong>println(result);
    } finally {
      reader.close();
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #29
Source File: Solution_017.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Integer solve() {
  final Function1<Integer, Integer> _function = (Integer it) -> {
    return Integer.valueOf(this.word((it).intValue()).replace(" ", "").length());
  };
  final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
    return Integer.valueOf(((i1).intValue() + (i2).intValue()));
  };
  return IterableExtensions.<Integer>reduce(IterableExtensions.<Integer, Integer>map(new IntegerRange(1, this.upper), _function), _function_1);
}
 
Example #30
Source File: RichStringToLineModel.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void acceptSemanticText(final CharSequence text, final RichStringLiteral origin) {
  super.acceptSemanticText(text, origin);
  if ((!this.content)) {
    if (((text.length() > 0) && (IterableExtensions.<Integer, Boolean>fold(new IntegerRange(0, (text.length() - 1)), Boolean.valueOf(false), ((Function2<Boolean, Integer, Boolean>) (Boolean v, Integer i) -> {
      return Boolean.valueOf(((v).booleanValue() || (!Character.isWhitespace(text.charAt((i).intValue())))));
    }))).booleanValue())) {
      this.startContent();
    }
  }
  int _length = text.length();
  int _plus = (this.offset + _length);
  this.offset = _plus;
}