Java Code Examples for org.eclipse.xtext.xbase.lib.Pair#getValue()
The following examples show how to use
org.eclipse.xtext.xbase.lib.Pair#getValue() .
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: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected Map<String, List<Diagnostic>> getDiagnostics() { try { final Function1<CancelIndicator, HashMap<String, List<Diagnostic>>> _function = (CancelIndicator it) -> { final HashMap<String, List<Diagnostic>> result = CollectionLiterals.<String, List<Diagnostic>>newHashMap(); final Function1<Pair<String, Object>, Object> _function_1 = (Pair<String, Object> it_1) -> { return it_1.getValue(); }; Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function_1), PublishDiagnosticsParams.class); for (final PublishDiagnosticsParams diagnostic : _filter) { result.put(diagnostic.getUri(), diagnostic.getDiagnostics()); } return result; }; return this.languageServer.getRequestManager().<HashMap<String, List<Diagnostic>>>runRead(_function).get(); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 2
Source File: SymbolContextUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * If possible, this function returns a {@link Pair} of two symbols. The key element is the one context * {@link Symbol} of the given symbols of {@code symbolsWithContexts} that matched with the given {@link Symbol} * {@code alias}. The value element is a newly created {@link Symbol} that has at least one context {@link Symbol}. * The base context symbol of the newly created symbol is the given {@code baseExpression}. * * @param symbolsWithContexts * a list of {@link Symbol} that have a context * @param alias * {@link Symbol} to search for * @param baseExpression * base expression that will be the base context of the synthesized symbol * @return a pair where the key is the matched alias {@link Symbol} and the value is the synthesized {@link Symbol} */ static public Pair<Symbol, Symbol> getContextChangedSymbol(SymbolFactory symbolFactory, Iterable<Symbol> symbolsWithContexts, Symbol alias, Expression baseExpression) { Pair<Symbol, List<Symbol>> symbolAndContexts = getSymbolAndContextsToAlias(symbolsWithContexts, alias); Symbol matchedAlias = symbolAndContexts.getKey(); List<Symbol> contextList = symbolAndContexts.getValue(); Symbol synthSymbol = null; if (!contextList.isEmpty()) { synthSymbol = symbolFactory.create(baseExpression, contextList); } Pair<Symbol, Symbol> cSymbols = Pair.of(matchedAlias, synthSymbol); return cSymbols; }
Example 3
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 4
Source File: FlowgraphsXpectMethod.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * This xpect method can evaluate all branches that are merged at the given node name. */ @ParameterParser(syntax = "('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg1=OFFSET)?") @Xpect public void allMergeBranches(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion referenceOffset) { N4JSFlowAnalyserDataRecorder.setEnabled(true); GraphVisitor dfv = new DummyForwardVisitor(); GraphVisitor dbv = new DummyBackwardVisitor(); ControlFlowElement referenceCFE = getCFE(referenceOffset); createFlowAnalyzer(referenceCFE).accept(dfv, dbv); N4JSFlowAnalyserDataRecorder.setEnabled(false); performBranchAnalysis(referenceOffset, null, referenceOffset); List<String> edgeStrings = new LinkedList<>(); int groupIdx = 0; List<Pair<Node, List<ControlFlowEdge>>> mergedEdges = N4JSFlowAnalyserDataRecorder.getMergedEdges(); for (Pair<Node, List<ControlFlowEdge>> pair : mergedEdges) { Node startNode = pair.getKey(); List<ControlFlowEdge> edges = pair.getValue(); for (ControlFlowEdge edge : edges) { String c = edge.start == startNode ? "B" : "F"; edgeStrings.add(c + groupIdx + ": " + edge.toString()); } groupIdx++; } Collections.sort(edgeStrings); expectation.assertEquals(edgeStrings); }
Example 5
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 6
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 7
Source File: AbstractStructuredIdeTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Executes the test with the given default setup. Depending on whether {@link #getDefaultTestWorkspace()} returns a * non-empty result, {@link #testWS(List, Object)} will be triggered. Otherwise {@link #test(List, Object)} will be * used and uses the default setup of {@link #getDefaultTestProject()}. * <p> * For further details mind the {@link Documentation documentation} of {@link #getDefaultTestWorkspace()} or * {@link #getDefaultTestProject()} respectively. */ protected void testInDefaultWorkspace(String content, T t) { String nameWithSelector = DEFAULT_MODULE_NAME + TestWorkspaceManager.MODULE_SELECTOR; Pair<String, String> moduleContents = Pair.of(nameWithSelector, content); boolean moduleAdded = false; if (!getDefaultTestWorkspace().isEmpty()) { List<Pair<String, List<Pair<String, String>>>> workspace = getDefaultTestWorkspace(); for (Pair<String, List<Pair<String, String>>> project : workspace) { String projectName = project.getKey(); if (projectName.endsWith(TestWorkspaceManager.MODULE_SELECTOR)) { List<Pair<String, String>> modulesPlusMyModule = new ArrayList<>(project.getValue()); modulesPlusMyModule.add(moduleContents); try { ReflectExtensions reflectExtensions = new ReflectExtensions(); reflectExtensions.set(project, "k", projectName.substring(0, projectName.length() - 1)); reflectExtensions.set(project, "v", modulesPlusMyModule); moduleAdded = true; } catch (Exception e) { e.printStackTrace(); } } } if (!moduleAdded) { throw new IllegalStateException("No project selected. Use " + TestWorkspaceManager.MODULE_SELECTOR); } testWS(workspace, t); return; } else { ArrayList<Pair<String, String>> allModules = Lists.newArrayList(moduleContents); allModules.addAll(getDefaultTestProject()); test(allModules, t); } }
Example 8
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 9
Source File: ConstantExpressionsInterpreterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void evaluatesTo(final Pair<String, String> typeAndExpression, final Procedure1<? super Object> assertions) { try { final String type = typeAndExpression.getKey(); final String expression = typeAndExpression.getValue(); String _elvis = null; if (type != null) { _elvis = type; } else { _elvis = "void"; } String _plus = ("def " + _elvis); String _plus_1 = (_plus + " testFoo() { "); String _plus_2 = (_plus_1 + expression); String _plus_3 = (_plus_2 + " }"); final XtendFunction function = this.function(_plus_3); XExpression _expression = function.getExpression(); final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions()); JvmTypeReference _xifexpression = null; if ((type != null)) { _xifexpression = function.getReturnType(); } final Object value = this.interpreter.evaluate(expr, _xifexpression); assertions.apply(value); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 10
Source File: AbstractXtendUITestCase.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void setJavaVersion(JavaVersion javaVersion) throws Exception { IJavaProject javaProject = JavaProjectSetupUtil.findJavaProject(WorkbenchTestHelper.TESTPROJECT_NAME); Pair<String,Boolean> result = WorkbenchTestHelper.changeBree(javaProject, javaVersion); IExecutionEnvironment execEnv = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(result.getKey()); Assume.assumeNotNull("Execution environment not found for: " + javaVersion.getLabel(), execEnv); Assume.assumeTrue("No compatible VM was found for: " + javaVersion.getLabel(), execEnv.getCompatibleVMs().length > 0); if(result.getValue()) { WorkbenchTestHelper.makeCompliantFor(javaProject, javaVersion); IResourcesSetupUtil.reallyWaitForAutoBuild(); } }
Example 11
Source File: ProblemSupportImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void addWarning(final Element element, final String message) { this.checkCanceled(); this.checkValidationAllowed(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); EList<Resource.Diagnostic> _warnings = resAndObj.getKey().getWarnings(); EObject _value = resAndObj.getValue(); EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue()); EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.WARNING, "user.issue", message, _value, _significantFeature, (-1), null); _warnings.add(_eObjectDiagnosticImpl); }
Example 12
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 13
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); } }
Example 14
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 15
Source File: AbstractAssignabilityTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
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); LightweightTypeReference _xifexpression = null; String _key = lhsAndParams.getKey(); boolean _tripleNotEquals = (_key != null); if (_tripleNotEquals) { _xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()); } else { _xifexpression = this.getOwner().newAnyTypeReference(); } final LightweightTypeReference lhsType = _xifexpression; LightweightTypeReference _xifexpression_1 = null; if ((rhs != null)) { _xifexpression_1 = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType()); } else { _xifexpression_1 = this.getOwner().newAnyTypeReference(); } final LightweightTypeReference 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(lhsType, rhsType))); if (expectation) { List<LightweightTypeReference> _allSuperTypes = lhsType.getAllSuperTypes(); for (final LightweightTypeReference superType : _allSuperTypes) { if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) { Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(superType, rhsType))); } } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 16
Source File: UIResourceChangeRegistryTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public static String toReadableString(final IResourceDelta delta) { StringConcatenation _builder = new StringConcatenation(); IPath _fullPath = delta.getFullPath(); _builder.append(_fullPath); _builder.append(" "); String _switchResult = null; int _kind = delta.getKind(); switch (_kind) { case IResourceDelta.ADDED: _switchResult = "ADDED"; break; case IResourceDelta.REMOVED: _switchResult = "REMOVED"; break; case IResourceDelta.CHANGED: _switchResult = "CHANGED"; break; } _builder.append(_switchResult); _builder.append(" "); Pair<Integer, String> _mappedTo = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.CONTENT), "CONTENT"); Pair<Integer, String> _mappedTo_1 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DERIVED_CHANGED), "DERIVED_CHANGED"); Pair<Integer, String> _mappedTo_2 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DESCRIPTION), "DESCRIPTION"); Pair<Integer, String> _mappedTo_3 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.ENCODING), "ENCODING"); Pair<Integer, String> _mappedTo_4 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.LOCAL_CHANGED), "LOCAL_CHANGED"); Pair<Integer, String> _mappedTo_5 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.OPEN), "OPEN"); Pair<Integer, String> _mappedTo_6 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_TO), "MOVED_TO"); Pair<Integer, String> _mappedTo_7 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_FROM), "MOVED_FROM"); Pair<Integer, String> _mappedTo_8 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.COPIED_FROM), "COPIED_FROM"); Pair<Integer, String> _mappedTo_9 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.TYPE), "TYPE"); Pair<Integer, String> _mappedTo_10 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.SYNC), "SYNC"); Pair<Integer, String> _mappedTo_11 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MARKERS), "MARKERS"); Pair<Integer, String> _mappedTo_12 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.REPLACED), "REPLACED"); final Function1<Pair<Integer, String>, String> _function = (Pair<Integer, String> it) -> { String _xifexpression = null; if (((delta.getFlags() & (it.getKey()).intValue()) != 0)) { _xifexpression = it.getValue(); } else { _xifexpression = null; } return _xifexpression; }; String _join = IterableExtensions.join(IterableExtensions.<String>filterNull(ListExtensions.<Pair<Integer, String>, String>map(Collections.<Pair<Integer, String>>unmodifiableList(CollectionLiterals.<Pair<Integer, String>>newArrayList(_mappedTo, _mappedTo_1, _mappedTo_2, _mappedTo_3, _mappedTo_4, _mappedTo_5, _mappedTo_6, _mappedTo_7, _mappedTo_8, _mappedTo_9, _mappedTo_10, _mappedTo_11, _mappedTo_12)), _function)), ","); _builder.append(_join); _builder.append(" {"); _builder.newLineIfNotEmpty(); { IResourceDelta[] _affectedChildren = delta.getAffectedChildren(); for(final IResourceDelta child : _affectedChildren) { _builder.append("\t"); String _readableString = UIResourceChangeRegistryTest.TestUiResourceChangeRegistry.toReadableString(child); _builder.append(_readableString, "\t"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); return _builder.toString(); }
Example 17
Source File: FormattableDocument.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void reportConflict(final FormattingData data1, final FormattingData data2) { final Pair<String, String> text = this.getTextAround(data1); int _size = ((List<StackTraceElement>)Conversions.doWrapArray(this.rootTrace.getStackTrace())).size(); final int traceStart = (_size - 1); final StackTraceElement[] fullTrace1 = data1.getTrace().getStackTrace(); int _size_1 = ((List<StackTraceElement>)Conversions.doWrapArray(fullTrace1)).size(); int _minus = (_size_1 - traceStart); final String shortTrace1 = IterableExtensions.join(((List<StackTraceElement>)Conversions.doWrapArray(fullTrace1)).subList(0, _minus), "\n"); final StackTraceElement[] fullTrace2 = data2.getTrace().getStackTrace(); int _size_2 = ((List<StackTraceElement>)Conversions.doWrapArray(fullTrace2)).size(); int _minus_1 = (_size_2 - traceStart); final String shortTrace2 = IterableExtensions.join(((List<StackTraceElement>)Conversions.doWrapArray(fullTrace2)).subList(0, _minus_1), "\n"); StringConcatenation _builder = new StringConcatenation(); _builder.append("Conflicting TextEdits during formatting:"); _builder.newLine(); _builder.append("------------------------------- document snippet --------------------------------"); _builder.newLine(); String _key = text.getKey(); _builder.append(_key); _builder.append("[!!!]"); String _value = text.getValue(); _builder.append(_value); _builder.newLineIfNotEmpty(); _builder.append("---------------------------------------------------------------------------------"); _builder.newLine(); _builder.append("TextEdit1: "); String _replaceAll = data1.toString().replaceAll("\\n\\s*", " "); _builder.append(_replaceAll); _builder.newLineIfNotEmpty(); _builder.append("TextEdit2: "); String _replaceAll_1 = data2.toString().replaceAll("\\n\\s*", " "); _builder.append(_replaceAll_1); _builder.newLineIfNotEmpty(); _builder.append("---------------------------------- Trace 1 --------------------------------------"); _builder.newLine(); _builder.append(shortTrace1); _builder.newLineIfNotEmpty(); _builder.append("---------------------------------- Trace 2 --------------------------------------"); _builder.newLine(); _builder.append(shortTrace2); _builder.newLineIfNotEmpty(); _builder.append("---------------------------------------------------------------------------------"); _builder.newLine(); FormattableDocument.log.error(_builder); }
Example 18
Source File: FormattableDocument.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected FormattingData addFormatting(final FormattingData data) { FormattingData _xifexpression = null; if ((data != null)) { FormattingData _xblockexpression = null; { int _length = data.getLength(); boolean _lessThan = (_length < 0); if (_lessThan) { final Pair<String, String> text = this.getTextAround(data); StringConcatenation _builder = new StringConcatenation(); _builder.append("lenght of text-edit can not be negative:"); _builder.newLine(); _builder.append("--------------------------------- document snippet ------------------------------"); _builder.newLine(); String _key = text.getKey(); _builder.append(_key); _builder.append("[[[!!]]]"); String _value = text.getValue(); _builder.append(_value); _builder.newLineIfNotEmpty(); _builder.append("---------------------------------------------------------------------------------"); _builder.newLine(); FormattableDocument.log.error(_builder); throw new IllegalStateException("Length of text edit can not be negative"); } int _length_1 = data.getLength(); boolean _greaterThan = (_length_1 > 0); if (_greaterThan) { int _offset = data.getOffset(); int _offset_1 = data.getOffset(); int _length_2 = data.getLength(); int _plus = (_offset_1 + _length_2); final String oldText = this.document.substring(_offset, _plus); boolean _isWhitespace = this.isWhitespace(oldText); boolean _not = (!_isWhitespace); if (_not) { final Pair<String, String> text_1 = this.getTextAround(data); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("Can not edit non-whitespace:"); _builder_1.newLine(); _builder_1.append("------------------------------- document snippet --------------------------------"); _builder_1.newLine(); String _key_1 = text_1.getKey(); _builder_1.append(_key_1); _builder_1.append("[[["); _builder_1.append(oldText); _builder_1.append("]]]"); String _value_1 = text_1.getValue(); _builder_1.append(_value_1); _builder_1.newLineIfNotEmpty(); _builder_1.append("---------------------------------------------------------------------------------"); _builder_1.newLine(); FormattableDocument.log.error(_builder_1); throw new IllegalStateException(("Can non format non-whitespace: " + oldText)); } } final FormattingData old = this.formattings.get(Integer.valueOf(data.getOffset())); FormattingData _xifexpression_1 = null; if ((old == null)) { _xifexpression_1 = data; } else { _xifexpression_1 = this.merge(old, data); } final FormattingData newData = _xifexpression_1; FormattingData _xifexpression_2 = null; if ((newData != null)) { _xifexpression_2 = this.formattings.put(Integer.valueOf(data.getOffset()), newData); } _xblockexpression = _xifexpression_2; } _xifexpression = _xblockexpression; } return _xifexpression; }
Example 19
Source File: SerializerFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private StringConcatenationClient genMethodCreateSequence() { StringConcatenationClient _xblockexpression = null; { final Function1<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>> _function = (IGrammarConstraintProvider.IConstraint it) -> { return Pair.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>of(it, it); }; final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints = SerializerFragment2.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>toMap(IterableExtensions.<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>>map(this._semanticSequencerExtensions.getGrammarConstraints(this._semanticSequencerExtensions.getSuperGrammar(this.getGrammar())), _function)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("@Override"); _builder.newLine(); _builder.append("public void sequence("); _builder.append(ISerializationContext.class); _builder.append(" context, "); _builder.append(EObject.class); _builder.append(" semanticObject) {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(EPackage.class, "\t"); _builder.append(" epackage = semanticObject.eClass().getEPackage();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(ParserRule.class, "\t"); _builder.append(" rule = context.getParserRule();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(Action.class, "\t"); _builder.append(" action = context.getAssignedAction();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(Set.class, "\t"); _builder.append("<"); _builder.append(Parameter.class, "\t"); _builder.append("> parameters = context.getEnabledBooleanParameters();"); _builder.newLineIfNotEmpty(); { Iterable<Pair<Integer, EPackage>> _indexed = IterableExtensions.<EPackage>indexed(SerializerFragment2.this.getAccessedPackages()); for(final Pair<Integer, EPackage> pkg : _indexed) { _builder.append("\t"); { Integer _key = pkg.getKey(); boolean _greaterThan = ((_key).intValue() > 0); if (_greaterThan) { _builder.append("else "); } } _builder.append("if (epackage == "); EPackage _value = pkg.getValue(); _builder.append(_value, "\t"); _builder.append("."); String _packageLiteral = GenModelUtil2.getPackageLiteral(); _builder.append(_packageLiteral, "\t"); _builder.append(")"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("switch (semanticObject.eClass().getClassifierID()) {"); _builder.newLine(); { Iterable<EClass> _accessedClasses = SerializerFragment2.this.getAccessedClasses(pkg.getValue()); for(final EClass type : _accessedClasses) { _builder.append("\t"); _builder.append("\t"); _builder.append("case "); EPackage _value_1 = pkg.getValue(); _builder.append(_value_1, "\t\t"); _builder.append("."); String _intLiteral = GenModelUtil2.getIntLiteral(type, SerializerFragment2.this.getLanguage().getResourceSet()); _builder.append(_intLiteral, "\t\t"); _builder.append(":"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("\t"); StringConcatenationClient _genMethodCreateSequenceCaseBody = SerializerFragment2.this.genMethodCreateSequenceCaseBody(superConstraints, type); _builder.append(_genMethodCreateSequenceCaseBody, "\t\t\t"); _builder.newLineIfNotEmpty(); } } _builder.append("\t"); _builder.append("\t"); _builder.append("}"); _builder.newLine(); } } _builder.append("\t"); _builder.append("if (errorAcceptor != null)"); _builder.newLine(); _builder.append("\t\t"); _builder.append("errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; _xblockexpression = _client; } return _xblockexpression; }
Example 20
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; }