Java Code Examples for org.eclipse.xtext.xbase.lib.Pair#getKey()
The following examples show how to use
org.eclipse.xtext.xbase.lib.Pair#getKey() .
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: IteratorExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 6 votes |
@Test public void testGroupBy() { List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>(); pairs.add(new Pair<Integer, String>(1, "A")); pairs.add(new Pair<Integer, String>(1, "a")); pairs.add(new Pair<Integer, String>(2, "B")); pairs.add(new Pair<Integer, String>(2, "b")); Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() { @Override public Integer apply(Pair<Integer, String> p) { return p.getKey(); } }; Map<Integer, List<Pair<Integer, String>>> map = IteratorExtensions.groupBy(pairs.iterator(), computeKeys); Assert.assertEquals("Expected grouped map size", 2, map.size()); Assert.assertTrue("Contains 1 as key", map.keySet().contains(1)); Assert.assertEquals("Contains 2 entries for key 1", 2, map.get(1).size()); Assert.assertEquals("Contains entry 1->A for key 1", new Pair<Integer, String>(1, "A"), map.get(1).get(0)); Assert.assertEquals("Contains entry 1->a for key 1", new Pair<Integer, String>(1, "a"), map.get(1).get(1)); Assert.assertTrue("Contains 2 as key", map.keySet().contains(2)); Assert.assertEquals("Contains 2 entries for key 2", 2, map.get(2).size()); Assert.assertEquals("Contains entry 2->B for key 2", new Pair<Integer, String>(2, "B"), map.get(2).get(0)); Assert.assertEquals("Contains entry 2->b for key 2", new Pair<Integer, String>(2, "b"), map.get(2).get(1)); }
Example 2
Source File: AbstractIdeTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
@SafeVarargs private List<TextDocumentContentChangeEvent> replacementsToChangeEvents(XDocument document, Pair<String, String>... replacements) { List<TextDocumentContentChangeEvent> result = new ArrayList<>(replacements.length); for (Pair<String, String> replacement : replacements) { int offset = document.getContents().indexOf(replacement.getKey()); if (offset < 0) { throw new IllegalArgumentException( "string \"" + replacement.getKey() + "\" not found in content of document"); } int len = replacement.getKey().length(); Range range = new Range(document.getPosition(offset), document.getPosition(offset + len)); result.add(new TextDocumentContentChangeEvent(range, len, replacement.getValue())); } return result; }
Example 3
Source File: ComposedMemberInfo.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void initFParAggregate(ComposedFParInfo fpAggr) { for (Pair<TFormalParameter, RuleEnvironment> fpPair : fpAggr.fpSiblings) { TFormalParameter tFpar = fpPair.getKey(); RuleEnvironment G = fpPair.getValue(); // handle: name final String nextName = tFpar.getName(); if (nextName != null && !fpAggr.names.contains(nextName)) { fpAggr.names.add(nextName); } // handle: typeRef lists TypeRef typeRefSubst = ts.substTypeVariables(G, tFpar.getTypeRef()); if (typeRefSubst != null && !(typeRefSubst instanceof UnknownTypeRef)) { TypeRef typeRefCopy = TypeUtils.copyIfContained(typeRefSubst); fpAggr.typeRefs.add(typeRefCopy); if (tFpar.isVariadic()) { fpAggr.typeRefsVariadic.add(typeRefCopy); } } // handle: optional fpAggr.allOptional &= tFpar.isOptional(); fpAggr.allNonOptional &= !tFpar.isOptional(); } }
Example 4
Source File: IteratorExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 6 votes |
@Test public void testToMap() { List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>(); pairs.add(new Pair<Integer, String>(1, "A")); pairs.add(new Pair<Integer, String>(1, "a")); pairs.add(new Pair<Integer, String>(2, "B")); pairs.add(new Pair<Integer, String>(2, "b")); Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() { @Override public Integer apply(Pair<Integer, String> p) { return p.getKey(); } }; Map<Integer, Pair<Integer, String>> map = IteratorExtensions.toMap(pairs.iterator(), computeKeys); Assert.assertEquals("Expected grouped map size", 2, map.size()); Assert.assertTrue("Contains 1 as key", map.keySet().contains(1)); Assert.assertEquals("Contains entry 1->a for key 1", map.get(1), new Pair<Integer, String>(1, "a")); Assert.assertTrue("Contains 2 as key", map.keySet().contains(2)); Assert.assertEquals("Contains entry 2->b for key 2", map.get(2), new Pair<Integer, String>(2, "b")); }
Example 5
Source File: IteratorExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
@Test public void testGroupBy__WhenEmptyList() { List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>(); Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() { @Override public Integer apply(Pair<Integer, String> p) { return p.getKey(); } }; Map<Integer, List<Pair<Integer, String>>> map = IteratorExtensions.groupBy(pairs.iterator(), computeKeys); Assert.assertEquals("Expected grouped map size", 0, map.size()); }
Example 6
Source File: AbstractStructuredIdeTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Same as {@link #test(LinkedHashMap, String, String, Object)}, but name and content of the modules can be provided * as {@link Pair pairs}. * <p> * Finds the selected project and module using the {@link TestWorkspaceManager#MODULE_SELECTOR} and removes the * selector. */ protected Project testWS(List<Pair<String, List<Pair<String, String>>>> projectsModulesContents, T t) { LinkedHashMap<String, Map<String, String>> projectsModulesContentsAsMap = new LinkedHashMap<>(); Pair<String, String> selection = TestWorkspaceManager .convertProjectsModulesContentsToMap(projectsModulesContents, projectsModulesContentsAsMap, true); String selectedProject = selection.getKey(); String selectedModule = selection.getValue(); return test(projectsModulesContentsAsMap, selectedProject, selectedModule, t); }
Example 7
Source File: TestWorkspaceManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Converts from pairs to a corresponding map. This method has two return values: * <ol> * <li>the resulting map, which is returned by changing the given argument <code>addHere</code>, and * <li>iff a module in the given pairs is marked as selected module (see {@link #MODULE_SELECTOR}), then this method * returns a pair "selected project path" -> "selected module"; otherwise it returns <code>null</code>. * </ol> */ /* package */ static Pair<String, String> convertProjectsModulesContentsToMap( Iterable<Pair<String, List<Pair<String, String>>>> projectsModulesContentsAsPairs, Map<String, Map<String, String>> addHere, boolean requireSelectedModule) { String selectedProjectPath = null; String selectedModule = null; addHere.clear(); for (Pair<String, ? extends Iterable<Pair<String, String>>> project : projectsModulesContentsAsPairs) { String projectPath = project.getKey(); Iterable<? extends Pair<String, String>> modules = project.getValue(); Map<String, String> modulesMap = null; if (modules != null) { modulesMap = new HashMap<>(); for (Pair<String, String> moduleContent : modules) { String moduleName = moduleContent.getKey(); if (moduleName.endsWith(MODULE_SELECTOR)) { moduleName = moduleName.substring(0, moduleName.length() - 1); selectedProjectPath = projectPath; selectedModule = moduleName; } modulesMap.put(moduleName, moduleContent.getValue()); } } addHere.put(projectPath, modulesMap); } if (requireSelectedModule && selectedModule == null) { throw new IllegalArgumentException( "No module selected. Fix by appending '" + MODULE_SELECTOR + "' to one of the project modules."); } return selectedModule != null ? Pair.of(selectedProjectPath, selectedModule) : null; }
Example 8
Source File: IteratorExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
@Test public void testToMap__WhenEmptyList() { List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>(); Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() { @Override public Integer apply(Pair<Integer, String> p) { return p.getKey(); } }; Map<Integer, Pair<Integer, String>> map = IteratorExtensions.toMap(pairs.iterator(), computeKeys); Assert.assertEquals("Expected grouped map size", 0, map.size()); }
Example 9
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static InputStream jarInputStream(@SuppressWarnings("unchecked") Pair<String, InputStream> ...entries) { try (ByteArrayOutputStream out2 = new ByteArrayOutputStream(); JarOutputStream jo = new JarOutputStream(new BufferedOutputStream(out2))) { for (Pair<String, InputStream> entry : entries) { JarEntry je = new JarEntry(entry.getKey()); jo.putNextEntry(je); ByteStreams.copy(entry.getValue(), jo); } jo.close(); return new ByteArrayInputStream(out2.toByteArray()); } catch (IOException e) { throw new WrappedException(e); } }
Example 10
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 11
Source File: DestructureUtilsForSymbols.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return the {@link EObject} that is assigned to the given lhs element in the pattern. Defaults are respected. */ public static EObject getValueFromDestructuring(EObject nodeElem) { Pair<EObject, EObject> values = DestructNode.getValueFromDestructuring(nodeElem); if (values == null) { return null; } EObject assignedValue = values.getKey(); EObject defaultValue = values.getValue(); return respectDefaultValue(assignedValue, defaultValue); }
Example 12
Source File: ControlFlowGraphFactory.java From n4js with Eclipse Public License 1.0 | 5 votes |
private static void connectToJumpTarget(ComplexNodeMapper cnMapper, Node jumpNode, JumpToken jumpToken) { Pair<Node, ControlFlowType> catcher = CatchNodeFinder.find(jumpToken, jumpNode, cnMapper); if (catcher == null) { String jumpTokenStr = getJumpTokenDetailString(jumpToken, jumpNode); System.err.println("Could not find catching node for jump token '" + jumpTokenStr + "'"); return; } Node catchNode = catcher.getKey(); ControlFlowType newEdgeType = catcher.getValue(); FinallyBlock enteringFinallyBlock = getEnteringFinallyBlock(catchNode); boolean isExitingFinallyBlock = isExitingFinallyBlock(cnMapper, jumpNode); if (enteringFinallyBlock != null || isExitingFinallyBlock) { boolean equalEdgeExistsAlready = equalEdgeExistsAlready(jumpNode, jumpToken, catchNode); if (!equalEdgeExistsAlready) { EdgeUtils.connectCF(jumpNode, catchNode, jumpToken); } } else { try { EdgeUtils.connectCF(jumpNode, catchNode, newEdgeType); } catch (Exception e) { printInfo(cnMapper, jumpNode, catchNode, newEdgeType); throw e; } } if (enteringFinallyBlock != null) { // Iff finally block was entered abruptly, jump on from exit of finally block Block block = enteringFinallyBlock.getBlock(); ComplexNode cnBlock = cnMapper.get(block); Node exitFinallyBlock = cnBlock.getExit(); connectToJumpTarget(cnMapper, exitFinallyBlock, jumpToken); } }
Example 13
Source File: XIdeContentProposalAcceptor.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void accept(ContentAssistEntry entry, int priority) { if (entry != null) { if (entry.getProposal() == null) { throw new IllegalArgumentException("proposal must not be null."); } String entryString = entry.toString(); if (entries.containsKey(entryString)) { Pair<Integer, ContentAssistEntry> existingProposal = entries.get(entryString); priority = existingProposal.getKey(); } entries.put(entryString, Pair.of(priority, entry)); } }
Example 14
Source File: ActiveAnnotationsRuntimeTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected URI copyToDisk(final String projectName, final Pair<String, String> fileRepresentation) { try { String _key = fileRepresentation.getKey(); String _plus = ((projectName + "/src/") + _key); final File file = new File(this.workspaceRoot, _plus); file.getParentFile().mkdirs(); Files.asCharSink(file, Charset.defaultCharset()).write(fileRepresentation.getValue()); return URI.createFileURI(file.getPath()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 15
Source File: RegisterGlobalsContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void setNameAndAccept(final JvmDeclaredType newType, final String qualifiedName) { ConditionUtils.checkQualifiedName(qualifiedName, "qualifiedName"); JvmDeclaredType _findType = this.findType(qualifiedName); boolean _tripleEquals = (_findType == null); StringConcatenation _builder = new StringConcatenation(); _builder.append("The type \'"); _builder.append(qualifiedName); _builder.append("\' has already been registered."); Preconditions.checkArgument(_tripleEquals, _builder); this.compilationUnit.checkCanceled(); final Pair<String, String> namespaceAndName = this.getNameParts(qualifiedName); final String headerText = this.compilationUnit.getFileHeaderProvider().getFileHeader(this.compilationUnit.getXtendFile().eResource()); this.compilationUnit.getJvmTypesBuilder().setFileHeader(newType, headerText); String _key = namespaceAndName.getKey(); boolean _tripleNotEquals = (_key != null); if (_tripleNotEquals) { final JvmDeclaredType parentType = this.findType(namespaceAndName.getKey()); if ((parentType != null)) { EList<JvmMember> _members = parentType.getMembers(); _members.add(newType); newType.setStatic(true); } else { newType.setPackageName(namespaceAndName.getKey()); this.acceptor.<JvmDeclaredType>accept(newType); } } else { this.acceptor.<JvmDeclaredType>accept(newType); } newType.setSimpleName(namespaceAndName.getValue()); }
Example 16
Source File: Html2ADocConverter.java From n4js with Eclipse Public License 1.0 | 4 votes |
private int transformHTML(CharSequence html, int startRegionIdx, StringBuilder strb, List<String> tagStack, String myTagRegion) { int length = html.length(); int i = startRegionIdx; /** * Terminology: * * <pre> * Tag open: <XY> * Tag close: </XY> * Tag start: <... * Tag end: ...> * </pre> */ while (i < length) { char c = html.charAt(i); switch (c) { case ENTITY_START: { // note: Xtend has problems detecting chars, cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=408764 i = replaceEntities(html, strb, i, c); break; } case TAG_START: { boolean isCloseTag = false; int tagStart = i; // skip empty elements while (i + 1 < length && Character.isWhitespace(html.charAt(i + 1))) { i++; } // is end tag? if (i + 1 < length && html.charAt(i + 1) == TAG_END_MARK) { isCloseTag = true; i++; } // get element and its end position Pair<Element, Integer> elementWithOffset = parseHTMLElement(html, i); int tagEnd = elementWithOffset.getValue(); i = tagEnd - 1; Element element = elementWithOffset.getKey(); // get html tag name and corresponding adoc string String adocString = null; String elementName = null; if (element != null) { elementName = element.getNodeName(); String tagName = elementName; if (isCloseTag) tagName = "/" + tagName; adocString = htmlElementsToADoc.get(tagName); } // check if closing this region if (isCloseTag && elementName != null) { boolean isClosingMyRegion = myTagRegion.equals(elementName); if (isClosingMyRegion) { return i; } } // append text representing the html tag (and region) if (adocString == null) { strb.append(html.subSequence(tagStart, tagEnd)); } else if (adocString == VISIT_REGION) { String[] tags = getADocTags(element, html, tagEnd); strb.append(tags[0]); tagStack.add(0, getADocTagName(tags[0])); i = transformHTML(html, tagEnd, strb, tagStack, elementName); tagStack.remove(0); strb.append(tags[1]); } else { strb.append(adocString); } break; } default: strb.append(c); } i++; } return i; }
Example 17
Source File: ConstantExpressionsInterpreterTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void assertEvaluatesTo(final Object expectation, final Pair<String, String> left, final Pair<String, String> right, final String op) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import static MyConstants.*"); _builder.newLine(); _builder.newLine(); _builder.append("class C { "); _builder.newLine(); _builder.append("\t"); _builder.append("static val result = A "); _builder.append(op, "\t"); _builder.append(" B"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); _builder.append("class MyConstants {"); _builder.newLine(); _builder.append("\t"); _builder.append("static val "); String _value = left.getValue(); _builder.append(_value, "\t"); _builder.append(" A = "); String _key = left.getKey(); _builder.append(_key, "\t"); _builder.append(" as "); String _value_1 = left.getValue(); _builder.append(_value_1, "\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("static val "); String _value_2 = right.getValue(); _builder.append(_value_2, "\t"); _builder.append(" B = "); String _key_1 = right.getKey(); _builder.append(_key_1, "\t"); _builder.append(" as "); String _value_3 = right.getValue(); _builder.append(_value_3, "\t"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class)); Assert.assertEquals(expectation, this.interpreter.evaluate(stringField.getInitialValue(), null)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 18
Source File: SynonmyTypesTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public void hasSynonyms(final Pair<String, String> typeAndTypeParams, final String... expectedSynonyms) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def "); { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeAndTypeParams.getValue()); boolean _not = (!_isNullOrEmpty); if (_not) { _builder.append("<"); String _value = typeAndTypeParams.getValue(); _builder.append(_value); _builder.append("> "); } } _builder.append("void method("); String _key = typeAndTypeParams.getKey(); _builder.append(_key); _builder.append(" p) {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); LightweightTypeReference _xifexpression = null; String _key_1 = typeAndTypeParams.getKey(); boolean _tripleNotEquals = (_key_1 != null); if (_tripleNotEquals) { _xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()); } else { _xifexpression = this.getOwner().newAnyTypeReference(); } final LightweightTypeReference primary = _xifexpression; final HashSet<String> actualSynonyms = CollectionLiterals.<String>newHashSet(); final SynonymTypesProvider.Acceptor _function = new SynonymTypesProvider.Acceptor() { @Override protected boolean accept(final LightweightTypeReference type, final int conformance) { return actualSynonyms.add(type.getSimpleName()); } }; this._synonymTypesProvider.collectSynonymTypes(primary, _function); Assert.assertEquals(actualSynonyms.toString(), expectedSynonyms.length, actualSynonyms.size()); Assert.assertTrue(actualSynonyms.toString(), actualSynonyms.containsAll(((Collection<?>)Conversions.doWrapArray(expectedSynonyms)))); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 19
Source File: SerializerFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private StringConcatenationClient genEmitUnassignedTokens() { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("@Override"); _builder.newLine(); _builder.append("protected void emitUnassignedTokens("); _builder.append(EObject.class); _builder.append(" semanticObject, "); _builder.append(ISyntacticSequencerPDAProvider.ISynTransition.class); _builder.append(" transition, "); _builder.append(INode.class); _builder.append(" fromNode, "); _builder.append(INode.class); _builder.append(" toNode) {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("if (transition.getAmbiguousSyntaxes().isEmpty()) return;"); _builder.newLine(); _builder.append("\t"); _builder.append(List.class, "\t"); _builder.append("<"); _builder.append(INode.class, "\t"); _builder.append("> transitionNodes = collectNodes(fromNode, toNode);"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("for ("); _builder.append(GrammarAlias.AbstractElementAlias.class, "\t"); _builder.append(" syntax : transition.getAmbiguousSyntaxes()) {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append(List.class, "\t\t"); _builder.append("<"); _builder.append(INode.class, "\t\t"); _builder.append("> syntaxNodes = getNodesFor(transitionNodes, syntax);"); _builder.newLineIfNotEmpty(); { Iterable<Pair<Integer, EqualAmbiguousTransitions>> _indexed = IterableExtensions.<EqualAmbiguousTransitions>indexed(SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax()); for(final Pair<Integer, EqualAmbiguousTransitions> group : _indexed) { _builder.append("\t\t"); { Integer _key = group.getKey(); boolean _greaterThan = ((_key).intValue() > 0); if (_greaterThan) { _builder.append("else "); } } _builder.append("if (match_"); String _identifier = group.getValue().getIdentifier(); _builder.append(_identifier, "\t\t"); _builder.append(".equals(syntax))"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("\t"); _builder.append("emit_"); String _identifier_1 = group.getValue().getIdentifier(); _builder.append(_identifier_1, "\t\t\t"); _builder.append("(semanticObject, getLastNavigableState(), syntaxNodes);"); _builder.newLineIfNotEmpty(); } } _builder.append("\t\t"); { boolean _isEmpty = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax().isEmpty(); boolean _not = (!_isEmpty); if (_not) { _builder.append("else "); } } _builder.append("acceptNodes(getLastNavigableState(), syntaxNodes);"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; return _client; }
Example 20
Source File: TypeReferenceAssignabilityTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def "); { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue()); boolean _not = (!_isNullOrEmpty); if (_not) { _builder.append("<"); String _value = lhsAndParams.getValue(); _builder.append(_value); _builder.append("> "); } } _builder.append("void method("); String _fixup = this.fixup(lhsAndParams.getKey()); _builder.append(_fixup); _builder.append(" lhs, "); String _fixup_1 = this.fixup(rhs); _builder.append(_fixup_1); _builder.append(" rhs) {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); EObject _rootContainer = EcoreUtil.getRootContainer(function); final XtendFile xtendFile = ((XtendFile) _rootContainer); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { TypeReference _xifexpression = null; String _key = lhsAndParams.getKey(); boolean _tripleNotEquals = (_key != null); if (_tripleNotEquals) { _xifexpression = it.toTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()); } else { _xifexpression = it.toTypeReference(this.getOwner().newAnyTypeReference()); } final TypeReference lhsType = _xifexpression; TypeReference _xifexpression_1 = null; if ((rhs != null)) { _xifexpression_1 = it.toTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType()); } else { _xifexpression_1 = it.toTypeReference(this.getOwner().newAnyTypeReference()); } final TypeReference rhsType = _xifexpression_1; String _simpleName = lhsType.getSimpleName(); String _plus = (_simpleName + " := "); String _simpleName_1 = rhsType.getSimpleName(); String _plus_1 = (_plus + _simpleName_1); Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(it, lhsType, rhsType))); if (expectation) { Iterable<? extends TypeReference> _declaredSuperTypes = lhsType.getDeclaredSuperTypes(); for (final TypeReference superType : _declaredSuperTypes) { if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) { Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(it, superType, rhsType))); } } } }; this.asCompilationUnit(xtendFile, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }