org.eclipse.xtext.xbase.lib.Conversions Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.lib.Conversions.
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: SyntacticSequencerExtensions.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public List<EqualAmbiguousTransitions> getAllAmbiguousTransitionsBySyntax() { if ((this.ambiguousTransitions != null)) { return this.ambiguousTransitions; } final Map<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions> result = CollectionLiterals.<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions>newHashMap(); Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.getAllAmbiguousTransitions(); for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) { List<GrammarAlias.AbstractElementAlias> _ambiguousSyntaxes = transition.getAmbiguousSyntaxes(); for (final GrammarAlias.AbstractElementAlias syntax : _ambiguousSyntaxes) { { EqualAmbiguousTransitions list = result.get(syntax); if ((list == null)) { String _elementAliasToIdentifier = this.elementAliasToIdentifier(syntax); EqualAmbiguousTransitions _equalAmbiguousTransitions = new EqualAmbiguousTransitions(_elementAliasToIdentifier, syntax); list = _equalAmbiguousTransitions; result.put(syntax, list); } list.getTransitions().add(transition); } } } this.ambiguousTransitions = CollectionLiterals.<EqualAmbiguousTransitions>newArrayList(((EqualAmbiguousTransitions[])Conversions.unwrapArray(result.values(), EqualAmbiguousTransitions.class))); ListExtensions.<EqualAmbiguousTransitions>sortInplace(this.ambiguousTransitions); return this.ambiguousTransitions; }
Example #2
Source File: SameClassNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDuplicateNames_04() { try { final IJavaProject javaProject = JavaCore.create(this.second); final IClasspathEntry[] cp = javaProject.getRawClasspath(); final List<IClasspathEntry> reversed = ListExtensions.<IClasspathEntry>reverse(((List<IClasspathEntry>)Conversions.doWrapArray(cp))); javaProject.setRawClasspath(((IClasspathEntry[])Conversions.unwrapArray(reversed, IClasspathEntry.class)), null); IResourcesSetupUtil.reallyWaitForAutoBuild(); this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(String s) {} }"); this.testHelper.createFileImpl("second/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }"); this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }"); this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}"); IResourcesSetupUtil.waitForBuild(); IResourcesSetupUtil.assertNoErrorsInWorkspace(); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #3
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testAnnotation_1() { try { final XExpression expression = this.expression("42", false); final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmAnnotationType clazz = this.builder.toAnnotationType(expression, "my.test.Foo", _function); final Class<?> compiledClass = this.compile(expression.eResource(), clazz); Assert.assertTrue(compiledClass.isAnnotation()); final Method method = IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiledClass.getMethods()))); Assert.assertEquals("theTruth", method.getName()); Assert.assertEquals(Integer.valueOf(42), method.getDefaultValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #4
Source File: WorkspaceScenariosTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testJarWithEverything() { try { final Function1<String, Boolean> _function = (String it) -> { return Boolean.valueOf(false); }; final IProject project = this.createProjectWithJarDependency(_function); try { IResourcesSetupUtil.assertNoErrorsInWorkspace(); Assert.assertEquals(1, ((Object[])Conversions.unwrapArray(this.persistedResourceDescriptions.get().getAllResourceDescriptions(), Object.class)).length); } finally { project.delete(true, true, null); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #5
Source File: RebuildAffectedResourcesTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void assertHasErrors(final IFile file, final String msgPart) { try { final IMarker[] findMarkers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); for (final IMarker iMarker : findMarkers) { if (((MarkerUtilities.getSeverity(iMarker) == IMarker.SEVERITY_ERROR) && MarkerUtilities.getMessage(iMarker).contains(msgPart))) { return; } } IPath _fullPath = file.getFullPath(); String _plus = ((("Expected an error marker containing \'" + msgPart) + "\' on ") + _fullPath); String _plus_1 = (_plus + " but found "); final Function1<IMarker, String> _function = (IMarker it) -> { return MarkerUtilities.getMessage(it); }; String _join = IterableExtensions.join(ListExtensions.<IMarker, String>map(((List<IMarker>)Conversions.doWrapArray(findMarkers)), _function), ","); String _plus_2 = (_plus_1 + _join); Assert.fail(_plus_2); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #6
Source File: Solution_004.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public static void main(final String[] args) { int result = 0; IntegerRange _upTo = new IntegerRange(100, 999); for (final Integer left : _upTo) { IntegerRange _upTo_1 = new IntegerRange((left).intValue(), 999); for (final Integer right : _upTo_1) { { int candidate = ((left).intValue() * (right).intValue()); if ((candidate > result)) { List<Character> charList = (List<Character>)Conversions.doWrapArray(Integer.valueOf(candidate).toString().toCharArray()); List<Character> _reverseView = ListExtensions.<Character>reverseView(charList); boolean _equals = Objects.equal(_reverseView, charList); if (_equals) { result = candidate; } } } } } InputOutput.<Integer>println(Integer.valueOf(result)); }
Example #7
Source File: ASTFlattenerUtils.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private IMethodBinding internalFindOverride(final IMethodBinding method, final ITypeBinding superType, final boolean onlyPrimarylevel) { final Function1<IMethodBinding, Boolean> _function = (IMethodBinding it) -> { return Boolean.valueOf(method.overrides(it)); }; final Iterable<IMethodBinding> superClassOverride = IterableExtensions.<IMethodBinding>filter(((Iterable<IMethodBinding>)Conversions.doWrapArray(superType.getDeclaredMethods())), _function); int _size = IterableExtensions.size(superClassOverride); boolean _equals = (_size == 1); if (_equals) { return ((IMethodBinding[])Conversions.unwrapArray(superClassOverride, IMethodBinding.class))[0]; } else { if ((!onlyPrimarylevel)) { return this.findOverride(method, superType); } else { return null; } } }
Example #8
Source File: ResourceMoveTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void performMove(final IContainer theDestination, final IResource... theResources) { try { MoveResourcesDescriptor _moveResourcesDescriptor = new MoveResourcesDescriptor(); final Procedure1<MoveResourcesDescriptor> _function = (MoveResourcesDescriptor it) -> { final Function1<IResource, IPath> _function_1 = (IResource it_1) -> { return it_1.getFullPath(); }; it.setResourcePathsToMove(((IPath[])Conversions.unwrapArray(ListExtensions.<IResource, IPath>map(((List<IResource>)Conversions.doWrapArray(theResources)), _function_1), IPath.class))); it.setDestinationPath(theDestination.getFullPath()); }; MoveResourcesDescriptor _doubleArrow = ObjectExtensions.<MoveResourcesDescriptor>operator_doubleArrow(_moveResourcesDescriptor, _function); this.performRefactoring(_doubleArrow); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #9
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected Object _doEvaluate(XForLoopExpression forLoop, IEvaluationContext context, CancelIndicator indicator) { Object iterableOrIterator = internalEvaluate(forLoop.getForExpression(), context, indicator); if (iterableOrIterator == null) return throwNullPointerException(forLoop.getForExpression(), "iterable evaluated to 'null'"); Iterator<?> iter = null; if (iterableOrIterator instanceof Iterable<?>) { iter = ((Iterable<?>) iterableOrIterator).iterator(); } else if (iterableOrIterator.getClass().isArray()) { iter = ((Iterable<?>) Conversions.doWrapArray(iterableOrIterator)).iterator(); } else { return throwClassCastException(forLoop.getForExpression(), iterableOrIterator, java.lang.Iterable.class); } IEvaluationContext forkedContext = context.fork(); QualifiedName paramName = QualifiedName.create(forLoop.getDeclaredParam().getName()); forkedContext.newValue(paramName, null); while (iter.hasNext()) { Object next = iter.next(); forkedContext.assignValue(paramName, next); internalEvaluate(forLoop.getEachExpression(), forkedContext, indicator); } return null; }
Example #10
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected Object _doEvaluate(XListLiteral literal, IEvaluationContext context, CancelIndicator indicator) { IResolvedTypes resolveTypes = typeResolver.resolveTypes(literal); LightweightTypeReference type = resolveTypes.getActualType(literal); List<Object> list = newArrayList(); for(XExpression element: literal.getElements()) { if (indicator.isCanceled()) throw new InterpreterCanceledException(); list.add(internalEvaluate(element, context, indicator)); } if(type != null && type.isArray()) { try { LightweightTypeReference componentType = type.getComponentType(); return Conversions.unwrapArray(list, getJavaType(componentType.getType())); } catch (ClassNotFoundException e) { } } return Collections.unmodifiableList(list); }
Example #11
Source File: EclipseFileSystemSupportImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Iterable<? extends Path> getChildren(final URI uri, final Path path) { final IResource resource = this.findMember(uri); if ((resource instanceof IContainer)) { try { final Function1<IResource, Path> _function = (IResource it) -> { String _string = it.getFullPath().toString(); return new Path(_string); }; return ListExtensions.<IResource, Path>map(((List<IResource>)Conversions.doWrapArray(((IContainer)resource).members())), _function); } catch (final Throwable _t) { if (_t instanceof CoreException) { final CoreException exc = (CoreException)_t; String _message = exc.getMessage(); throw new IllegalArgumentException(_message, exc); } else { throw Exceptions.sneakyThrow(_t); } } } return CollectionLiterals.<Path>emptyList(); }
Example #12
Source File: CompilationUnitImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected String getMessageWithReducedStackTrace(final Throwable t, final Function1<? super Throwable, ? extends String> getMessage) { final StackTraceElement[] stackTrace = t.getStackTrace(); final ArrayList<StackTraceElement> reducedStackTrace = CollectionLiterals.<StackTraceElement>newArrayList(); for (final StackTraceElement it : stackTrace) { { if ((it.getClassName().contains(AnnotationProcessor.class.getName()) || it.getClassName().contains(ProblemSupportImpl.class.getName()))) { try { t.setStackTrace(((StackTraceElement[])Conversions.unwrapArray(reducedStackTrace, StackTraceElement.class))); return getMessage.apply(t); } finally { t.setStackTrace(stackTrace); } } reducedStackTrace.add(it); } } return getMessage.apply(t); }
Example #13
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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 #14
Source File: InMemoryJavaCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public NameEnvironmentAnswer findType(final char[][] compoundTypeName) { try { final Function1<char[], String> _function = (char[] it) -> { return String.valueOf(it); }; String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(compoundTypeName)), _function), "/"); final String fileName = (_join + ".class"); boolean _containsKey = this.cache.containsKey(fileName); if (_containsKey) { return this.cache.get(fileName); } final URL url = this.classLoader.getResource(fileName); if ((url == null)) { this.cache.put(fileName, null); return null; } final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null); this.cache.put(fileName, result); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #15
Source File: JavaIOFileSystemSupport.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<? extends Path> getChildren(final URI uri, final Path path) { java.net.URI _uRI = this.toURI(uri); final Function1<String, Path> _function = (String it) -> { return path.getAbsolutePath(it); }; return ListExtensions.<String, Path>map(((List<String>)Conversions.doWrapArray(new File(_uRI).list())), _function); }
Example #16
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testParametrizedSuperConstructor() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("int foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("String bar"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Class<?> _compiledClass = it.getCompiledClass("Bar"); final Procedure1<Class<?>> _function_1 = (Class<?> it_1) -> { final Function1<Constructor<?>, Boolean> _function_2 = (Constructor<?> it_2) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_2.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue(IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it_1.getDeclaredConstructors())), _function_2)); }; ObjectExtensions.<Class<?>>operator_doubleArrow(_compiledClass, _function_1); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #17
Source File: Solution_022.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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 #18
Source File: UIResourceChangeRegistry.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void forgetBuildState() { final Function1<IProject, Boolean> _function = (IProject it) -> { try { return Boolean.valueOf(((it.isAccessible() && it.hasNature(XtextProjectHelper.NATURE_ID)) && it.hasNature(JavaCore.NATURE_ID))); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; final Iterable<IProject> projects = IterableExtensions.<IProject>filter(((Iterable<IProject>)Conversions.doWrapArray(this.workspace.getRoot().getProjects())), _function); this.scheduler.scheduleBuildIfNecessary(projects, IBuildFlag.FORGET_BUILD_STATE_ONLY); }
Example #19
Source File: ContentAssistContextTestHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) { final int offset = this.document.indexOf(this.cursor); Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor"); final String doc = this.document.replace(this.cursor, ""); final XtextResource res = this.parse(doc); factory.setPool(Executors.newCachedThreadPool()); TextRegion _textRegion = new TextRegion(0, 0); final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res); final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule(); StringConcatenation _builder = new StringConcatenation(); { Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs))); for(final Pair<Integer, ContentAssistContext> ctx : _indexed) { _builder.append("context"); Integer _key = ctx.getKey(); _builder.append(_key); _builder.append(" {"); _builder.newLineIfNotEmpty(); { ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements(); for(final AbstractElement ele : _firstSetGrammarElements) { _builder.append("\t"); String _name = ele.eClass().getName(); _builder.append(_name, "\t"); _builder.append(": "); String _apply = f.apply(ele); _builder.append(_apply, "\t"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); } } return _builder.toString(); }
Example #20
Source File: ReorderedVarArgFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void withIndizes(final IFeatureCallArguments arguments, final int... indexes) { final Consumer<Integer> _function = (Integer it) -> { Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot slot = arguments.getNextUnprocessedArgumentSlot(); final XExpression expression = IterableExtensions.<XExpression>head(slot.getArgumentExpressions()); EObject _eContainer = expression.eContainer(); final XFeatureCall featureCall = ((XFeatureCall) _eContainer); Assert.assertEquals((it).intValue(), featureCall.getFeatureCallArguments().indexOf(expression)); slot.markProcessed(); }; ((List<Integer>)Conversions.doWrapArray(indexes)).forEach(_function); Assert.assertFalse(arguments.hasUnprocessedArguments()); }
Example #21
Source File: Bug462915Test.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * make sure additional proposal infos can be calculated */ @Test public void testAdditionalProposalInfoWorks() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class A {"); _builder.newLine(); _builder.append("\t"); _builder.append("test"); _builder.newLine(); _builder.append("}"); final String model = _builder.toString(); ContentAssistProcessorTestBuilder _append = this.newBuilder().append(model); int _indexOf = model.indexOf("test"); int _plus = (_indexOf + 4); final ICompletionProposal[] proposals = _append.computeCompletionProposals(_plus); Assert.assertEquals("More than one proposal found", 1, ((List<ICompletionProposal>)Conversions.doWrapArray(proposals)).size()); final ICompletionProposal proposal = IterableExtensions.<ICompletionProposal>head(((Iterable<ICompletionProposal>)Conversions.doWrapArray(proposals))); Assert.assertEquals("test - JUnit test method", proposal.getDisplayString()); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("@Test"); _builder_1.newLine(); _builder_1.append("def void testName() {"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.newLine(); _builder_1.append("}"); Assert.assertEquals(Strings.toUnixLineSeparator(_builder_1).toString(), proposal.getAdditionalProposalInfo()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #22
Source File: CompilationTestHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Parses, validates and compiles the given sources. Calls the given acceptor for each * resource which is generated from the source. * * @param sources some inputs written in the language under test. * @param acceptor gets called once for each file generated in {@link IGenerator} * @throws IOException if the resource loading fails * * @since 2.8 */ @SuppressWarnings("unchecked") public void compile(Iterable<? extends CharSequence> sources, IAcceptor<Result> acceptor) throws IOException { int index = 0; List<Pair<String, ? extends CharSequence>> pairs = newArrayList(); for (CharSequence source : sources) { String fileName = "MyFile" + (++index) + "." + extensionProvider.getPrimaryFileExtension(); pairs.add(new Pair<String, CharSequence>(fileName, source)); } compile(resourceSet(((Pair<String, ? extends CharSequence>[])Conversions.unwrapArray(pairs, Pair.class))), acceptor); }
Example #23
Source File: JavaDocContentAssistTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void testContentAssistant(final CharSequence text, final List<String> expectedProposals, final String proposalToApply, final String expectedContent) { try { final int cursorPosition = text.toString().indexOf(this.c); if ((cursorPosition == (-1))) { Assert.fail((("Can\'t locate cursor position symbols \'" + this.c) + "\' in the input text.")); } final String content = text.toString().replace(this.c, ""); final ContentAssistProcessorTestBuilder builder = this.newBuilder().append(content).assertTextAtCursorPosition(cursorPosition, ((String[])Conversions.unwrapArray(expectedProposals, String.class))); if ((proposalToApply != null)) { builder.applyProposal(cursorPosition, proposalToApply).expectContent(expectedContent); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #24
Source File: UniqueClassNameValidatorUITest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Ignore("Since the name acme.A is considered to be derived, it is filtered from the Java delta") @Test public void testXtendAndJavaSameProjectXtendFirst() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package acme"); _builder.newLine(); _builder.append("class A {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder.toString()); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("package acme;"); _builder_1.newLine(); _builder_1.append("class A2 {"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); final IFile javaFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder_1.toString()); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); StringInputStream _stringInputStream = new StringInputStream("package acme; class A{}"); javaFile.setContents(_stringInputStream, false, false, null); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); final IMarker[] markers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); Assert.assertEquals(IResourcesSetupUtil.printMarker(markers), 1, markers.length); Assert.assertEquals("The type A is already defined in A.java.", IterableExtensions.<IMarker>head(((Iterable<IMarker>)Conversions.doWrapArray(markers))).getAttribute(IMarker.MESSAGE)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #25
Source File: UniqueClassNameValidatorUITest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testXtendAndJavaSameProject() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package acme;"); _builder.newLine(); _builder.append("public class A {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder.toString()); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("package acme"); _builder_1.newLine(); _builder_1.append("class A {"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); final IFile secondFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder_1.toString()); final IWorkspaceRunnable _function = (IProgressMonitor it) -> { this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); }; this.runInWorkspace(_function); final Iterable<IMarker> secondFileMarkers = this.onlyErrors(((Iterable<IMarker>)Conversions.doWrapArray(secondFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)))); Assert.assertEquals(IResourcesSetupUtil.printMarker(((IMarker[])Conversions.unwrapArray(secondFileMarkers, IMarker.class))), 1, ((Object[])Conversions.unwrapArray(secondFileMarkers, Object.class)).length); Assert.assertEquals("The type A is already defined in A.java.", IterableExtensions.<IMarker>head(secondFileMarkers).getAttribute(IMarker.MESSAGE)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #26
Source File: UniqueClassNameValidatorUITest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testTwoXtendFilesSameProject() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package acme"); _builder.newLine(); _builder.append("class A {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.xtend", _builder.toString()); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("package acme"); _builder_1.newLine(); _builder_1.append("class A {"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); final IFile secondFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder_1.toString()); final IWorkspaceRunnable _function = (IProgressMonitor it) -> { this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null); }; this.runInWorkspace(_function); final IMarker[] firstFileMarkers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); Assert.assertEquals(IResourcesSetupUtil.printMarker(firstFileMarkers), 1, firstFileMarkers.length); Assert.assertEquals("The type A is already defined in B.xtend.", IterableExtensions.<IMarker>head(((Iterable<IMarker>)Conversions.doWrapArray(firstFileMarkers))).getAttribute(IMarker.MESSAGE)); final Iterable<IMarker> secondFileMarkers = this.onlyErrors(((Iterable<IMarker>)Conversions.doWrapArray(secondFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)))); Assert.assertEquals(IResourcesSetupUtil.printMarker(((IMarker[])Conversions.unwrapArray(secondFileMarkers, IMarker.class))), 1, ((Object[])Conversions.unwrapArray(secondFileMarkers, Object.class)).length); Assert.assertEquals("The type A is already defined in A.xtend.", IterableExtensions.<IMarker>head(secondFileMarkers).getAttribute(IMarker.MESSAGE)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #27
Source File: NamedSerializationContextProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public NamedSerializationContextProvider(final Grammar grammar) { final Function1<Pair<Integer, ParserRule>, Pair<ParserRule, Integer>> _function = (Pair<Integer, ParserRule> it) -> { ParserRule _value = it.getValue(); Integer _key = it.getKey(); return Pair.<ParserRule, Integer>of(_value, _key); }; this.rules = CollectionLiterals.<ParserRule, Integer>newHashMap(((Pair<? extends ParserRule, ? extends Integer>[])Conversions.unwrapArray(IterableExtensions.<Pair<Integer, ParserRule>, Pair<ParserRule, Integer>>map(IterableExtensions.<ParserRule>indexed(GrammarUtil.allParserRules(grammar)), _function), Pair.class))); }
Example #28
Source File: XtendTypeDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public MethodDeclaration findDeclaredMethod(final String name, final TypeReference... parameterTypes) { final Function1<MethodDeclaration, Boolean> _function = (MethodDeclaration method) -> { return Boolean.valueOf((Objects.equal(method.getSimpleName(), name) && Objects.equal(IterableExtensions.<TypeReference>toList(IterableExtensions.map(method.getParameters(), ((Function1<ParameterDeclaration, TypeReference>) (ParameterDeclaration it) -> { return it.getType(); }))), IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes)))))); }; return IterableExtensions.findFirst(this.getDeclaredMethods(), _function); }
Example #29
Source File: CompilationTestHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Parses, validates and compiles the given sources. Calls the given acceptor for each * resource which is generated from the source. * * @param sources some inputs written in the language under test. * @param acceptor gets called once for each file generated in {@link IGenerator} * @throws IOException if the resource loading fails * * @since 2.8 */ @SuppressWarnings("unchecked") public void compile(Iterable<? extends CharSequence> sources, IAcceptor<Result> acceptor) throws IOException { int index = 0; List<Pair<String, ? extends CharSequence>> pairs = newArrayList(); for (CharSequence source : sources) { String fileName = "MyFile" + (++index) + "." + extensionProvider.getPrimaryFileExtension(); pairs.add(new Pair<String, CharSequence>(fileName, source)); } compile(resourceSet(((Pair<String, ? extends CharSequence>[])Conversions.unwrapArray(pairs, Pair.class))), acceptor); }
Example #30
Source File: ReorderedVarArgFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void withTypes(final IFeatureCallArguments arguments, final String... types) { final Consumer<String> _function = (String it) -> { Assert.assertTrue(arguments.hasUnprocessedArguments()); final IFeatureCallArgumentSlot slot = arguments.getNextUnprocessedArgumentSlot(); Assert.assertEquals(Boolean.valueOf((it == null)), Boolean.valueOf(slot.isSuperfluous())); if ((it != null)) { Assert.assertEquals(it, slot.getDeclaredType().getSimpleName()); } slot.markProcessed(); }; ((List<String>)Conversions.doWrapArray(types)).forEach(_function); Assert.assertFalse(arguments.hasUnprocessedArguments()); }