org.eclipse.xtext.xbase.lib.IterableExtensions Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.lib.IterableExtensions.
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: QuickfixTestBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public QuickfixTestBuilder assertModelAfterQuickfix(final CharSequence expectedModel) { QuickfixTestBuilder _xblockexpression = null; { final Function1<Issue, List<IssueResolution>> _function = (Issue it) -> { return this._issueResolutionProvider.getResolutions(it); }; final List<IssueResolution> resolutions = IterableExtensions.<IssueResolution>toList(Iterables.<IssueResolution>concat(IterableExtensions.<Issue, List<IssueResolution>>map(this.getIssuesAtCaret(), _function))); final String originalModel = this.editor.getDocument().get(); final IssueResolution resolution = IterableExtensions.<IssueResolution>head(resolutions); Assert.assertNotNull(resolution); resolution.apply(); Assert.assertEquals(expectedModel.toString(), this.editor.getDocument().get()); this.editor.getDocument().set(originalModel); this._syncUtil.waitForReconciler(this.editor); _xblockexpression = this; } return _xblockexpression; }
Example #2
Source File: IndentationAwareLanguageTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testParentChild() { StringConcatenation _builder = new StringConcatenation(); _builder.append("parent"); _builder.newLine(); _builder.append("\t"); _builder.append("child"); _builder.newLine(); final Tree tree = this.parse(_builder); Assert.assertNotNull(tree); Assert.assertEquals(1, tree.getNodes().size()); Assert.assertEquals("parent", IterableExtensions.<TreeNode>head(tree.getNodes()).getName()); Assert.assertEquals("child", IterableExtensions.<TreeNode>head(IterableExtensions.<TreeNode>head(tree.getNodes()).getChildren()).getName()); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("parent"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("child"); _builder_1.newLine(); Assert.assertEquals(_builder_1.toString(), this.asText(tree)); }
Example #3
Source File: ValidatorTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testDiagnosticAtEndOfLineIncludingNewline() { StringConcatenation _builder = new StringConcatenation(); _builder.append("type"); _builder.newLine(); this.writeFile("MyType1.testlang", Strings.toUnixLineSeparator(_builder)); this.initialize(); final List<Diagnostic> problems = IterableExtensions.<Map.Entry<String, List<Diagnostic>>>head(this.getDiagnostics().entrySet()).getValue(); String _join = IterableExtensions.join(problems, "\n"); String _plus = ("problems found:\n" + _join); Assert.assertEquals(_plus, 1, problems.size()); final Diagnostic problem = IterableExtensions.<Diagnostic>head(problems); this.assertEquals("mismatched input \'<EOF>\' expecting RULE_ID", problem.getMessage()); Assert.assertEquals(org.eclipse.xtext.diagnostics.Diagnostic.SYNTAX_DIAGNOSTIC, problem.getCode().get()); final Range range = problem.getRange(); Assert.assertEquals(0, range.getStart().getLine()); Assert.assertEquals(4, range.getStart().getCharacter()); Assert.assertEquals(1, range.getEnd().getLine()); Assert.assertEquals(0, range.getEnd().getCharacter()); }
Example #4
Source File: Solution_005.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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 #5
Source File: DirtyStateEditorValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private void assertNumberOfErrorAnnotations(final XtextEditor editor, final int expectedNumber) { final Function0<Boolean> _function = () -> { int _size = this.getErrorAnnotations(editor).size(); return Boolean.valueOf((_size == expectedNumber)); }; this.helper.awaitUIUpdate(_function, DirtyStateEditorValidationTest.VALIDATION_TIMEOUT); final List<Annotation> errors = this.getErrorAnnotations(editor); final Function1<Annotation, String> _function_1 = (Annotation it) -> { String _text = it.getText(); String _plus = (_text + "("); boolean _isPersistent = it.isPersistent(); String _plus_1 = (_plus + Boolean.valueOf(_isPersistent)); return (_plus_1 + ")"); }; Assert.assertEquals(IterableExtensions.join(ListExtensions.<Annotation, String>map(errors, _function_1), ", "), expectedNumber, errors.size()); }
Example #6
Source File: OperatorDeclarationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOperatorDeclaration_typeParam() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class A {"); _builder.newLine(); { Set<QualifiedName> _operators = this.operatorMapping.getOperators(); for(final QualifiedName op : _operators) { _builder.append("\t"); _builder.append("def <T> "); _builder.append(op, "\t"); _builder.append("() { return null }"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); final XtendFile file = this._parseHelper.parse(_builder); Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #7
Source File: XtendHoverSignatureProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInterfaceReference() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package testPackage"); _builder.newLine(); _builder.append("class Bar implements Foo {"); _builder.newLine(); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("interface Foo { }"); _builder.newLine(); final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet()); XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()); final JvmType in = IterableExtensions.<JvmTypeReference>head(((XtendClass) _head).getImplements()).getType(); Assert.assertEquals("Foo", this.signatureProvider.getSignature(in)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #8
Source File: EMFGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private Map<String, EPackage> findEPackagesInGenPackages(final Collection<String> packageNsURIs, final ResourceSet resourceSet) { final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap(); for (final String nsURI : packageNsURIs) { { final Resource resource = GenModelUtil2.getGenModelResource(null, nsURI, resourceSet); if ((resource != null)) { final GenModel loadedGenModel = IterableExtensions.<GenModel>head(Iterables.<GenModel>filter(resource.getContents(), GenModel.class)); if ((loadedGenModel != null)) { final GenPackage genPackage = this.findGenPackageByNsURI(loadedGenModel, nsURI); result.put(nsURI, genPackage.getEcorePackage()); } } } } return result; }
Example #9
Source File: XtendUIValidationTests.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDiscouragedTypeUsageInnernClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("def bar(org.eclipse.xtend.core.tests.internal.InternalClass$InnerInternalClass x){}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString()); XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers()); final XtendFunction function = ((XtendFunction) _head); this.helper.assertWarning(function.getParameters().get(0), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #10
Source File: JavaFileConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public JavaConverter.ConversionResult converToXtend(final String unitName, final String javaCode) { try { final JavaConverter j2x = this.javaConverter.get(); JavaConverter.ConversionResult result = j2x.toXtend(unitName, javaCode); int _size = IterableExtensions.size(result.getProblems()); boolean _equals = (_size == 0); if (_equals) { try { this.file(result.getXtendCode(), true); } catch (final Throwable _t) { if (_t instanceof AssertionError) { result = j2x.useRobustSyntax().toXtend(unitName, javaCode); } else { throw Exceptions.sneakyThrow(_t); } } } return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #11
Source File: BuildManager.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.18 */ protected void mergeWithUnreportedDeltas(List<IResourceDescription.Delta> newDeltas) { if (unreportedDeltas.isEmpty()) { unreportedDeltas.addAll(newDeltas); } else { Map<URI, IResourceDescription.Delta> unreportedByUri = IterableExtensions.toMap(unreportedDeltas, IResourceDescription.Delta::getUri); for(IResourceDescription.Delta newDelta: newDeltas) { IResourceDescription.Delta unreportedDelta = unreportedByUri.get(newDelta.getUri()); if (unreportedDelta == null) { unreportedDeltas.add(newDelta); } else { unreportedDeltas.remove(unreportedDelta); IResourceDescription oldDescription = unreportedDelta.getOld(); IResourceDescription newDescription = newDelta.getNew(); unreportedDeltas.add(new DefaultResourceDescriptionDelta(oldDescription, newDescription)); } } } }
Example #12
Source File: XbaseFormatter2.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected Iterable<XExpression> explicitParams(final List<XExpression> params) { Iterable<XExpression> _xblockexpression = null; { final XClosure builder = this.builder(params); Iterable<XExpression> _xifexpression = null; if ((builder != null)) { int _size = params.size(); int _minus = (_size - 1); _xifexpression = IterableExtensions.<XExpression>take(params, _minus); } else { _xifexpression = params; } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example #13
Source File: XtendOutlineSourceTreeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void buildDispatchers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, final IXtendOutlineContext context) { final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> { return Boolean.valueOf(this.dispatchHelper.isDispatcherFunction(it)); }; Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(inferredType.getDeclaredOperations(), _function); for (final JvmOperation dispatcher : _filter) { { final List<JvmOperation> dispatchCases = this.getDispatchCases(dispatcher, baseType, context); final IXtendOutlineContext dispatcherContext = this.xtendOutlineNodeBuilder.buildDispatcherNode(baseType, dispatcher, dispatchCases, context).markAsProcessed(dispatcher); for (final JvmOperation dispatchCase : dispatchCases) { EObject _elvis = null; XtendFunction _xtendFunction = this._iXtendJvmAssociations.getXtendFunction(dispatchCase); if (_xtendFunction != null) { _elvis = _xtendFunction; } else { _elvis = dispatchCase; } this.buildFeature(baseType, dispatchCase, _elvis, dispatcherContext).markAsProcessed(dispatchCase); } } } }
Example #14
Source File: CodeLensTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testCodeLens() { final Procedure1<AbstractLanguageServerTest.TestCodeLensConfiguration> _function = (AbstractLanguageServerTest.TestCodeLensConfiguration it) -> { StringConcatenation _builder = new StringConcatenation(); _builder.append("type Foo {}"); _builder.newLine(); _builder.append("type Bar {"); _builder.newLine(); _builder.append("\t"); _builder.append("Foo foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); it.setModel(_builder.toString()); final Procedure1<List<? extends CodeLens>> _function_1 = (List<? extends CodeLens> it_1) -> { this.assertEquals("Do Awesome Stuff(RESOLVED)", IterableExtensions.head(it_1).getCommand().getTitle()); Object _data = IterableExtensions.head(it_1).getData(); Assert.assertEquals(1, ((Position) _data).getLine()); }; it.setAssertCodeLenses(_function_1); }; this.testCodeLens(_function); }
Example #15
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_340611_02() throws Exception { XtendFile xtendFile = file( "class Bug340611 {\n" + " def dispatch foo(String string) {\n" + " string\n" + " }\n" + " def dispatch foo(CharSequence charSeq) {\n" + " charSeq\n" + " }\n" + "}", false); JvmGenericType inferredType = getInferredType(xtendFile); assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations())); // one main dispatch Iterable<JvmOperation> operations = inferredType.getDeclaredOperations(); JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", CharSequence.class); assertEquals("java.lang.CharSequence", dispatch.getReturnType().getIdentifier()); // two internal case methods JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_foo", String.class); assertEquals("java.lang.CharSequence", stringParam.getReturnType().getIdentifier()); JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_foo", CharSequence.class); assertEquals("java.lang.CharSequence", objectParam.getReturnType().getIdentifier()); }
Example #16
Source File: GrammarAccessExtensions.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public List<String> initialHiddenTokens(final Grammar it) { List<String> _xblockexpression = null; { boolean _isDefinesHiddenTokens = it.isDefinesHiddenTokens(); if (_isDefinesHiddenTokens) { final Function1<AbstractRule, String> _function = (AbstractRule it_1) -> { return this.ruleName(it_1); }; return IterableExtensions.<String>toList(ListExtensions.<AbstractRule, String>map(it.getHiddenTokens(), _function)); } int _size = it.getUsedGrammars().size(); boolean _equals = (_size == 1); if (_equals) { return this.initialHiddenTokens(IterableExtensions.<Grammar>head(it.getUsedGrammars())); } _xblockexpression = CollectionLiterals.<String>emptyList(); } return _xblockexpression; }
Example #17
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected String _toExpectation(final Command it) { StringConcatenation _builder = new StringConcatenation(); _builder.append("command : "); String _command = it.getCommand(); _builder.append(_command); _builder.newLineIfNotEmpty(); _builder.append("title : "); String _title = it.getTitle(); _builder.append(_title); _builder.newLineIfNotEmpty(); _builder.append("args : "); _builder.newLine(); _builder.append("\t"); final Function1<Object, CharSequence> _function = (Object it_1) -> { return this.toExpectation(it_1); }; String _join = IterableExtensions.<Object>join(it.getArguments(), ",", _function); _builder.append(_join, "\t"); _builder.newLineIfNotEmpty(); return _builder.toString(); }
Example #18
Source File: Solution_023.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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 #19
Source File: ResourceDescriptionProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testStubGeneration_02() { StringConcatenation _builder = new StringConcatenation(); _builder.append("public interface MyTest {"); _builder.newLine(); _builder.append("\t"); _builder.append("public String helloWorld();"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> { Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString()); EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy(); Assert.assertTrue(((JvmGenericType) _eObjectOrProxy).isInterface()); Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects())); }; this.resultsIn(_builder, _function); }
Example #20
Source File: EntitiesValidator.java From xtext-web with Eclipse Public License 2.0 | 6 votes |
@Check public void checkOperationNamesAreUnique(Entity entity) { JvmGenericType inferredJavaClass = IterableExtensions .head(Iterables.filter(jvmModelAssociations.getJvmElements(entity), JvmGenericType.class)); Multimap<String, JvmOperation> signature2Declarations = HashMultimap.create(); overrideHelper.getResolvedFeatures(inferredJavaClass).getDeclaredOperations().forEach((it) -> { signature2Declarations.put(it.getResolvedErasureSignature(), it.getDeclaration()); }); signature2Declarations.asMap().values().forEach((jvmOperations) -> { if (jvmOperations.size() > 1) { Iterables .filter(IterableExtensions.map(jvmOperations, (op) -> jvmModelAssociations.getPrimarySourceElement(op)), Operation.class) .forEach((op) -> { error("Duplicate operation " + op.getName(), op, DomainmodelPackage.Literals.FEATURE__NAME, IssueCodes.DUPLICATE_OPERATION); }); } }); }
Example #21
Source File: DelegateProcessor.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
public boolean hasValidSignature(final MethodDeclaration it) { boolean _switchResult = false; final Function1<ParameterDeclaration, TypeReference> _function = (ParameterDeclaration it_1) -> { return it_1.getType(); }; List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(it.getParameters(), _function)); boolean _matched = false; if (Objects.equal(_list, Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList()))) { _matched=true; } if (!_matched) { TypeReference _string = this.context.getString(); if (Objects.equal(_list, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_string)))) { _matched=true; } } if (!_matched) { TypeReference _string_1 = this.context.getString(); TypeReference _newArrayTypeReference = this.context.newArrayTypeReference(this.context.newTypeReference(Class.class, this.context.newWildcardTypeReference())); TypeReference _newArrayTypeReference_1 = this.context.newArrayTypeReference(this.context.getObject()); if (Objects.equal(_list, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_string_1, _newArrayTypeReference, _newArrayTypeReference_1)))) { _matched=true; } } if (_matched) { _switchResult = true; } if (!_matched) { boolean _xblockexpression = false; { this.context.addError(it, "Not a valid delegate signature, use () or (String methodName) or (String methodName, Class<?>[] argumentTypes, Object[] arguments)"); _xblockexpression = false; } _switchResult = _xblockexpression; } return _switchResult; }
Example #22
Source File: JvmTypeDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public FieldDeclaration findDeclaredField(final String name) { final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration field) -> { String _simpleName = field.getSimpleName(); return Boolean.valueOf(Objects.equal(_simpleName, name)); }; return IterableExtensions.findFirst(this.getDeclaredFields(), _function); }
Example #23
Source File: ValidatorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.14 */ protected List<AbstractRule> getDeprecatedRulesFromGrammar() { final HashSet<EClassifier> alreadyCollected = CollectionLiterals.<EClassifier>newHashSet(); final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> { return Boolean.valueOf((this.isDeprecated(it) && alreadyCollected.add(it.getType().getClassifier()))); }; return IterableExtensions.<AbstractRule>toList(IterableExtensions.<AbstractRule>filter(this.getGrammar().getRules(), _function)); }
Example #24
Source File: EclipseJavaCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public CompilationResult compile(Iterable<String> sourceRoots, File outputClassDirectory) { Iterable<String> validSourceRoots = IterableExtensions.filter(sourceRoots, new EmptyOrMissingFilter()); if (!containsJavaFiles(validSourceRoots)) { return CompilationResult.SKIPPED; } List<String> commandLine = Lists.newArrayList(); if (configuration.isVerbose()) { commandLine.add("-verbose"); } if (configuration.isSkipAnnotationProcessing()) { commandLine.add("-proc:none"); } if (configuration.isPreserveInformationAboutFormalParameters()) { commandLine.add("-parameters"); } if (classPath != null) { Iterable<String> validClasspath = IterableExtensions.filter(classPath, new EmptyOrMissingFilter()); if (validClasspath.iterator().hasNext()) { commandLine.add("-cp \"" + concat(File.pathSeparator, Lists.newArrayList(validClasspath)) + "\""); } } commandLine.add("-d \"" + outputClassDirectory.toString() + "\""); commandLine.add("-source " + configuration.getSourceLevel()); commandLine.add("-target " + configuration.getTargetLevel()); commandLine.add("-proceedOnError"); for (String src : validSourceRoots) { commandLine.add("\"" + src + "\""); } String cmdLine = concat(" ", commandLine); debugLog("invoke batch compiler with '" + cmdLine + "'"); boolean result = BatchCompiler.compile(cmdLine, new PrintWriter(getOutputWriter()), new PrintWriter( getErrorWriter()), null); return result ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; }
Example #25
Source File: EMFGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Create a clone of the original grammar. The clone will not refer to a node model. */ private Grammar cloneGrammarIntoNewResourceSet(final Grammar original) { final Resource originalResource = original.eResource(); XtextResourceSet _xtextResourceSet = new XtextResourceSet(); final XtextResourceSet clonedResourceSet = EcoreUtil2.<XtextResourceSet>clone(_xtextResourceSet, originalResource.getResourceSet()); final Resource clonedResource = clonedResourceSet.getResource(originalResource.getURI(), false); EObject _head = IterableExtensions.<EObject>head(clonedResource.getContents()); return ((Grammar) _head); }
Example #26
Source File: TestBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testActiveAnnotatons2() { this.batchCompiler.setSourcePath("./batch-compiler-data/activeAnnotations2"); Assert.assertTrue(this.batchCompiler.compile()); final FilenameFilter _function = (File dir, String name) -> { return name.endsWith(".java"); }; final String javaFiles = IterableExtensions.join(((Iterable<?>)Conversions.doWrapArray(new File((TestBatchCompiler.OUTPUT_DIRECTORY + "/mypackage")).list(_function))), ","); Assert.assertEquals("Client.java", javaFiles); final File txtFile = new File((TestBatchCompiler.OUTPUT_DIRECTORY + "/Test.txt")); Assert.assertTrue(txtFile.exists()); }
Example #27
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void addTypeCastToExplicitReceiver(XAbstractFeatureCall featureCall, IModificationContext context, JvmType declaringType, EReference structuralFeature) throws BadLocationException { List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, structuralFeature); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); INode lastNode = IterableExtensions.last(nodes); int offset = firstNode.getOffset(); int length = lastNode.getEndOffset() - offset; ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, length); appendable.append("("); ListIterator<INode> nodeIter = nodes.listIterator(); while (nodeIter.hasNext()) { String text = nodeIter.next().getText(); if (nodeIter.previousIndex() == 0) appendable.append(Strings.removeLeadingWhitespace(text)); else if (nodeIter.nextIndex() == nodes.size()) appendable.append(Strings.trimTrailingLineBreak(text)); else appendable.append(text); } appendable.append(" as "); appendable.append(declaringType); appendable.append(")"); appendable.commitChanges(); }
Example #28
Source File: AbstractIdeTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
private String issuesToSortedString(Iterable<String> issues, String indent) { if (Iterables.isEmpty(issues)) { return indent + "<none>"; } return IterableExtensions.sort(issues).stream() .map(issue -> issue.replace("\n", "\n" + indent)) .collect(Collectors.joining("\n" + indent)); }
Example #29
Source File: SemanticSequencerExtensions.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public List<ISemanticSequencerNfaProvider.ISemState> getLinearListOfMandatoryAssignments(final IGrammarConstraintProvider.IConstraint constraint) { final Nfa<ISemanticSequencerNfaProvider.ISemState> nfa = constraint.getNfa(); ISemanticSequencerNfaProvider.ISemState state = nfa.getStart(); final List<ISemanticSequencerNfaProvider.ISemState> result = CollectionLiterals.<ISemanticSequencerNfaProvider.ISemState>newArrayList(); final Set<EStructuralFeature> features = CollectionLiterals.<EStructuralFeature>newHashSet(); while ((state != null)) { { ISemanticSequencerNfaProvider.ISemState _stop = nfa.getStop(); boolean _tripleEquals = (state == _stop); if (_tripleEquals) { List<ISemanticSequencerNfaProvider.ISemState> _xifexpression = null; boolean _isEmpty = result.isEmpty(); if (_isEmpty) { _xifexpression = null; } else { _xifexpression = result; } return _xifexpression; } int _size = state.getFollowers().size(); boolean _tripleNotEquals = (_size != 1); if (_tripleNotEquals) { return null; } ISemanticSequencerNfaProvider.ISemState _start = nfa.getStart(); boolean _tripleNotEquals_1 = (state != _start); if (_tripleNotEquals_1) { final EStructuralFeature feature = state.getFeature(); if ((((feature == null) || feature.isMany()) || (!features.add(feature)))) { return null; } result.add(state); } state = IterableExtensions.<ISemanticSequencerNfaProvider.ISemState>head(state.getFollowers()); } } return null; }
Example #30
Source File: LiveShadowedChunkedContainerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { try { WorkspaceConfig _workspaceConfig = new WorkspaceConfig(); this.workspaceConfig = _workspaceConfig; ProjectConfig _projectConfig = new ProjectConfig("foo", this.workspaceConfig); this.fooProject = _projectConfig; ProjectConfig _projectConfig_1 = new ProjectConfig("bar", this.workspaceConfig); this.barProject = _projectConfig_1; final XtextResourceSet rs0 = this.resourceSetProvider.get(); this.fooURI = IterableExtensions.<SourceFolder>head(this.fooProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("foo.livecontainertestlanguage"); this.barURI = IterableExtensions.<SourceFolder>head(this.barProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("bar.livecontainertestlanguage"); ResourceDescriptionsData _createResourceDescriptionData = this.createResourceDescriptionData(this._parseHelper.parse("foo", this.fooURI, rs0).eResource()); Pair<String, ResourceDescriptionsData> _mappedTo = Pair.<String, ResourceDescriptionsData>of("foo", _createResourceDescriptionData); ResourceDescriptionsData _createResourceDescriptionData_1 = this.createResourceDescriptionData(this._parseHelper.parse("bar", this.barURI, rs0).eResource()); Pair<String, ResourceDescriptionsData> _mappedTo_1 = Pair.<String, ResourceDescriptionsData>of("bar", _createResourceDescriptionData_1); final Map<String, ResourceDescriptionsData> chunks = Collections.<String, ResourceDescriptionsData>unmodifiableMap(CollectionLiterals.<String, ResourceDescriptionsData>newHashMap(_mappedTo, _mappedTo_1)); this.rs1 = this.resourceSetProvider.get(); new ChunkedResourceDescriptions(chunks, this.rs1); ProjectConfigAdapter.install(this.rs1, this.fooProject); this.liveShadowedChunkedResourceDescriptions = this.provider.get(); this.liveShadowedChunkedResourceDescriptions.setContext(this.rs1); LiveShadowedChunkedContainer _liveShadowedChunkedContainer = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "foo"); this.fooContainer = _liveShadowedChunkedContainer; LiveShadowedChunkedContainer _liveShadowedChunkedContainer_1 = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "bar"); this.barContainer = _liveShadowedChunkedContainer_1; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }