Java Code Examples for org.eclipse.xtext.xbase.lib.Procedures.Procedure1#apply()

The following examples show how to use org.eclipse.xtext.xbase.lib.Procedures.Procedure1#apply() . 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: ActiveAnnotationsRuntimeTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void assertProcessing(final Pair<String, String> macroFile, final Pair<String, String> clientFile, final Procedure1<? super CompilationUnitImpl> expectations) {
  try {
    final XtextResourceSet resourceSet = this.compileMacroResourceSet(macroFile, clientFile);
    final Resource singleResource = IterableExtensions.<Resource>head(resourceSet.getResources());
    singleResource.load(CollectionLiterals.<Object, Object>emptyMap());
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      it.getGeneratedCode();
      final CompilationUnitImpl unit = this.compilationUnitProvider.get();
      final XtendFile xtendFile = IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(singleResource.getContents(), XtendFile.class));
      unit.setXtendFile(xtendFile);
      expectations.apply(unit);
    };
    this.compiler.compile(resourceSet, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
  try {
    @Extension
    final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
    final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      it.setRange(configuration.getRange());
      if ((paramsConfigurator != null)) {
        paramsConfigurator.apply(it);
      }
    };
    DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(Integer.valueOf(1), _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[])Conversions.unwrapArray(changes.get(), TextEdit.class)))));
    this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: ConstantExpressionsInterpreterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void evaluatesWithException(final String expression, final Procedure1<? super ConstantExpressionEvaluationException> exceptionAssertions) {
  try {
    final XtendFunction function = this.function((("def void testFoo() { " + expression) + " }"));
    XExpression _expression = function.getExpression();
    final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
    try {
      this.interpreter.evaluate(expr, null);
      Assert.fail("exception expected");
    } catch (final Throwable _t) {
      if (_t instanceof ConstantExpressionEvaluationException) {
        final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException)_t;
        exceptionAssertions.apply(e);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: AbstractIncrementalBuilderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected BuildRequest newBuildRequest(Procedure1<? super BuildRequest> init) {
	BuildRequest result = new BuildRequest();
	ResourceDescriptionsData newIndex = indexState.getResourceDescriptions().copy();
	result.setBaseDir(uri(""));
	XtextResourceSet rs = resourceSetProvider.get();
	rs.getURIConverter().getURIHandlers().clear();
	rs.getURIConverter().getURIHandlers().add(inMemoryURIHandler);
	rs.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
	ProjectDescription projectDescription = new ProjectDescription();
	projectDescription.setName("test-project");
	projectDescription.attachToEmfObject(rs);
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), rs);
	index.setContainer(projectDescription.getName(), newIndex);
	result.setResourceSet(rs);
	result.setDirtyFiles(new ArrayList<>());
	result.setDeletedFiles(new ArrayList<>());
	result.setAfterValidate((uri, issues) -> {
		Iterables.addAll(this.issues, issues);
		return Iterables.isEmpty(issues);
	});
	result.setAfterDeleteFile(f -> deleted.add(f));
	result.setAfterGenerateFile((source, target) -> generated.put(source, target));
	result.setState(new IndexState(newIndex, indexState.getFileMappings().copy()));
	init.apply(result);
	return result;
}
 
Example 5
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void sendAsync(Procedure1<? super IFileSystemAccess2> procedure) {
	Runnable runnable = () -> {
		if (delegate instanceof EclipseResourceFileSystemAccess2) {
			((EclipseResourceFileSystemAccess2) delegate).setPostProcessor(fileCallback);
		}
		if (sourceFolder != null) {
			if (delegate instanceof AbstractFileSystemAccess) {
				((AbstractFileSystemAccess) delegate).setCurrentSource(sourceFolder);
			}
		}
		procedure.apply(delegate);
	};
	fileSystemAccessQueue.sendAsync(delta.getUri(), runnable);
}
 
Example 6
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public AbstractTraceRegion region(final int offset, final int length, final int startLine, final int endLine, final Procedure1<? super TraceRegionMergerTest.TraceBuilder> init) {
  TraceRegion _xblockexpression = null;
  {
    final TraceRegion root = new TraceRegion(offset, length, startLine, endLine, true, 0, 0, 0, 0, this.root, this.uri);
    if ((init != null)) {
      final TraceRegionMergerTest.TraceBuilder child = new TraceRegionMergerTest.TraceBuilder(this.testBuilder, this.uri, root);
      init.apply(child);
    }
    _xblockexpression = root;
  }
  return _xblockexpression;
}
 
Example 7
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IHiddenRegion set(IHiddenRegion hiddenRegion, Procedure1<? super IHiddenRegionFormatter> init) {
	if (hiddenRegion != null) {
		AbstractFormatter2 formatter = getFormatter();
		IHiddenRegionFormatting formatting = formatter.createHiddenRegionFormatting();
		init.apply(formatter.createHiddenRegionFormatter(formatting));
		ITextReplacer replacer = formatter.createHiddenRegionReplacer(hiddenRegion, formatting);
		addReplacer(replacer);
	}
	return hiddenRegion;
}
 
Example 8
Source File: XtextCallHierarchyBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void testBuildCalleeHierarchy(final Procedure1<? super AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> configurator) {
  final Procedure1<AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> _function = (AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration it) -> {
    final Function1<ResourceSet, IHierarchyBuilder> _function_1 = (ResourceSet resourceSet) -> {
      final XtextCallHierarchyBuilder callHierarchyBuilder = this.<XtextCallHierarchyBuilder>configureBuilderWith(this.callHierarchyBuilderProvider.get(), resourceSet);
      callHierarchyBuilder.setHierarchyType(ICallHierarchyBuilder.CallHierarchyType.CALLEE);
      return callHierarchyBuilder;
    };
    it.setHierarchyBuilderProvider(_function_1);
    configurator.apply(it);
  };
  super.testBuildHierarchy(_function);
}
 
Example 9
Source File: AdvancedNewProjectPage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Group Group(Composite parent, Procedure1<? super Group> config) {
	Group group = new Group(parent, SWT.NONE);
	group.setFont(parent.getFont());
	group.setLayout(new GridLayout(1, false));
	group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
	config.apply(group);
	return group;
}
 
Example 10
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public MutableMethodDeclaration addMethod(final String name, final Procedure1<MutableMethodDeclaration> initializer) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final JvmOperation newMethod = TypesFactory.eINSTANCE.createJvmOperation();
  newMethod.setVisibility(JvmVisibility.PUBLIC);
  newMethod.setSimpleName(name);
  newMethod.setReturnType(this.getCompilationUnit().toJvmTypeReference(this.getCompilationUnit().getTypeReferenceProvider().getPrimitiveVoid()));
  this.getDelegate().getMembers().add(newMethod);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newMethod);
  final MutableMethodDeclaration mutableMethodDeclaration = ((MutableMethodDeclaration) _memberDeclaration);
  initializer.apply(mutableMethodDeclaration);
  return mutableMethodDeclaration;
}
 
Example 11
Source File: FormattingDataFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> newFormattingData(final HiddenLeafs leafs, final Procedure1<? super FormattingDataInit> init) {
  Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _xblockexpression = null;
  {
    final FormattingDataInit data = new FormattingDataInit();
    init.apply(data);
    _xblockexpression = this.newFormattingData(leafs, data.key, data);
  }
  return _xblockexpression;
}
 
Example 12
Source File: LoopExtensions.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Uses curly braces and comma as delimiters. Doesn't use them for single
 * valued iterables.
 */
public <T> void forEachWithShortcut(ITreeAppendable appendable, Iterable<T> elements,
		Procedure1<? super T> procedure) {
	if (IterableExtensions.size(elements) == 1) {
		procedure.apply(Iterables.getFirst(elements, null));
	} else {
		appendable.append("{");
		forEach(appendable, elements, (LoopParams it) -> {
			it.setPrefix(" ");
			it.setSeparator(", ");
			it.setSuffix(" ");
		}, procedure);
		appendable.append("}");
	}
}
 
Example 13
Source File: JdtQueuedBuildData.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean doNeedRebuild(JavaBuilderState javaBuilderState, Procedure1<? super UnconfirmedStructuralChangesDelta> processor) {
	Iterator<UnconfirmedStructuralChangesDelta> ucDeltas = unconfirmedDeltas.iterator();
	while (ucDeltas.hasNext()) {
		UnconfirmedStructuralChangesDelta ucDelta = ucDeltas.next();
		if ((ucDelta.getBuildNumber() < javaBuilderState.getBuildNumber().intValue())
				&& ucDelta.getProject().equals(javaBuilderState.getProject())) {
			ucDeltas.remove();
			if (processor != null) {
				processor.apply(ucDelta);
			}
		}
	}
	return !unconfirmedDeltas.isEmpty();
}
 
Example 14
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void asCompilationUnit(final XtendFile file, final Procedure1<? super CompilationUnitImpl> block) {
  final CompilationUnitImpl compilationUnit = this.compilationUnitProvider.get();
  compilationUnit.setXtendFile(file);
  compilationUnit.before(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
  block.apply(compilationUnit);
}
 
Example 15
Source File: FormatterTestHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void assertFormatted(Procedure1<FormatterTestRequest> init) {
	FormatterTestRequest request = formatterRequestProvider.get();
	init.apply(request);
	assertFormatted(request);
}
 
Example 16
Source File: ExternalDependency.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void p2(Procedure1<? super ExternalDependency.P2Coordinates> config) {
	config.apply(this.p2);
}
 
Example 17
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
  Object _xblockexpression = null;
  {
    this.compilationUnit.checkCanceled();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotationTypeDelcaration cannot be null");
    Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("initializer cannot be null");
    Preconditions.checkArgument((initializer != null), _builder_1);
    JvmDeclaredType _switchResult = null;
    boolean _matched = false;
    if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
      _matched=true;
      _switchResult = ((JvmAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate();
    }
    if (!_matched) {
      if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
        _matched=true;
        _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate());
      }
    }
    if (!_matched) {
      throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
    }
    final JvmDeclaredType type = _switchResult;
    if ((type instanceof JvmAnnotationType)) {
      final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
      AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
      final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
        it.setDelegate(newJvmAnnotationReference);
        it.setCompilationUnit(this.compilationUnit);
      };
      final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
      initializer.apply(buildContext);
      return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
    }
    _xblockexpression = null;
  }
  return ((AnnotationReference)_xblockexpression);
}
 
Example 18
Source File: FormatterTester.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void assertFormatted(Procedure1<FormatterTestRequest> init) {
	FormatterTestRequest request = formatterRequestProvider.get();
	init.apply(request);
	assertFormatted(request);
}
 
Example 19
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void assertFormatted(Procedure1<FormatterTestRequest> init) {
	FormatterTestRequest request = formatterRequestProvider.get();
	init.apply(request);
	assertFormatted(request);
}
 
Example 20
Source File: ObjectExtensions.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The <code>doubleArrow</code> operator is used as a 'with'- or 'let'-operation.
 * It allows to bind an object to a local scope in order to do something on it.
 * 
 * Example:
 * <code>
 *   new Person =&gt; [
 *     firstName = 'Han'
 *     lastName = 'Solo'
 *   ]
 * </code>
 * 
 * @param object
 *            an object. Can be <code>null</code>.
 * @param block
 *            the block to execute with the given object. Must not be <code>null</code>.
 * @return the reference to object.
 * @since 2.3
 */
public static <T> T operator_doubleArrow(T object, Procedure1<? super T> block) {
	block.apply(object);
	return object;
}