Java Code Examples for org.eclipse.xtext.util.Triple#getSecond()
The following examples show how to use
org.eclipse.xtext.util.Triple#getSecond() .
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: TestErrorAcceptor.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private boolean compareTriple(Triple<TransformationErrorCode, String, EObject> one, Triple<TransformationErrorCode, String, EObject> other) { if (one.equals(other)) return true; if (other == null) return false; if (other == one) return true; TransformationErrorCode first = one.getFirst(); boolean isFirstEqual = ((first == null) ? other.getFirst() == null : first.equals(other.getFirst())); if (!isFirstEqual) return false; String second = one.getSecond(); boolean isSecondEqual = second == ANY_STRING || ((second == null) ? other.getSecond() == null : second.equals(other.getSecond())); if (!isSecondEqual) return false; EObject third = one.getThird(); boolean isThirdEqual = third == ANY_EOBJECT || (third == null ? other.getThird() == null : one.getThird().equals(other.getThird())); return isThirdEqual; }
Example 2
Source File: TestErrorAcceptor.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private boolean compareTriple(Triple<TransformationErrorCode, String, EObject> one, Triple<TransformationErrorCode, String, EObject> other) { if (one.equals(other)) return true; if (other == null) return false; if (other == one) return true; TransformationErrorCode first = one.getFirst(); boolean isFirstEqual = ((first == null) ? other.getFirst() == null : first.equals(other.getFirst())); if (!isFirstEqual) return false; String second = one.getSecond(); boolean isSecondEqual = second == ANY_STRING || ((second == null) ? other.getSecond() == null : second.equals(other.getSecond())); if (!isSecondEqual) return false; EObject third = one.getThird(); boolean isThirdEqual = third == ANY_EOBJECT || (third == null ? other.getThird() == null : one.getThird().equals(other.getThird())); return isThirdEqual; }
Example 3
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError { // Don't throw exception for cyclic resolution of IdentifierRef.id or PropertyAccess.property // since this is currently unavoidable because type system and scoping don't work together // but have independent control flow logic. // This JS snippet will cause trouble: // // function(a){ return a.b } // System.err.println("CYCLIC RESOLUTION FOR: " + NodeModelUtils.getTokenText(triple.getThird())); if (N4JSPackage.Literals.IDENTIFIER_REF__ID == triple.getSecond() || N4JSPackage.Literals.PARAMETERIZED_PROPERTY_ACCESS_EXPRESSION__PROPERTY == triple.getSecond()) { return null; } return super.handleCyclicResolution(triple); }
Example 4
Source File: ParallelResourceLoader.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public LoadResult next() { if (!hasNext()) throw new NoSuchElementException("The resource queue is empty or the execution was cancelled."); Triple<URI, Resource, Throwable> result = null; try { result = resourceQueue.poll(waitTime, TimeUnit.MILLISECONDS); toProcess--; } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (result == null) { throw new NullPointerException("Resource load job didn't return a result"); } URI uri = result.getFirst(); Resource resource = result.getSecond(); Throwable throwable = result.getThird(); if (throwable != null) { // rethrow errors in the main thread if (throwable instanceof WrappedException) throw new LoadOperationException(uri, (Exception) throwable.getCause()); if (throwable instanceof Exception) throw new LoadOperationException(uri, (Exception) throwable); else throw (Error)throwable; } if(resource == null && uri != null) { // failed to load resource in parallel (due to file synchronization issues) // load the resource here, in the main builder thread resource = parent.getResource(uri, true); } return new LoadResult(resource, uri); }
Example 5
Source File: BoundTypeArgumentMergerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public LightweightMergedBoundTypeArgument mergeWithSource(final Object source, final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def void method("); final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> { return it.getFirst(); }; String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>)Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function); _builder.append(_join); _builder.append(") {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(); final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> { final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()]; LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType()); Object _elvis = null; if (source != null) { _elvis = source; } else { Object _object = new Object(); _elvis = _object; } VarianceInfo _second = input.getSecond(); VarianceInfo _third = input.getThird(); LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _elvis, _second, _third); mergable.add(_lightweightBoundTypeArgument); }; IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1); return this.merger.merge(mergable, this.getOwner()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 6
Source File: NodeModelSemanticSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void createSequence(ISerializationContext context, EObject semanticObject) { SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject); while (ni.hasNext()) { Triple<INode, AbstractElement, EObject> node = ni.next(); if (node.getSecond() instanceof RuleCall) { RuleCall rc = (RuleCall) node.getSecond(); TypeRef ruleType = rc.getRule().getType(); if (ruleType == null || ruleType.getClassifier() instanceof EClass) acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst()); else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) { EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass()); acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst()); } else { String strVal = NodeModelUtils.getTokenText(node.getFirst()); Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst()); acceptSemantic(semanticObject, rc, val, node.getFirst()); } } else if (node.getSecond() instanceof Keyword) acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst()); else if (node.getSecond() instanceof Action) { acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst()); } } }
Example 7
Source File: LazyLinkingResource2.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} * * @return true if the {@link ICrossReferenceHelper} returns true */ @Override public boolean suppressDiagnostic(final Triple<EObject, EReference, INode> triple) { final EObject context = triple.getFirst(); final EReference reference = triple.getSecond(); final INode node = triple.getThird(); return crossReferenceHelper.isOptionalReference(context, reference, node); }
Example 8
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.4 */ protected EObject getEObject(String uriFragment, Triple<EObject, EReference, INode> triple) throws AssertionError { cyclicLinkingDetectionCounter++; if (cyclicLinkingDetectionCounter > cyclicLinkingDectectionCounterLimit) { if (!resolving.add(triple)) { return handleCyclicResolution(triple); } } try { Set<String> unresolveableProxies = getUnresolvableURIFragments(); if (unresolveableProxies.contains(uriFragment)) return null; EReference reference = triple.getSecond(); try { List<EObject> linkedObjects = getLinkingService().getLinkedObjects( triple.getFirst(), reference, triple.getThird()); if (linkedObjects.isEmpty()) { if (isUnresolveableProxyCacheable(triple)) unresolveableProxies.add(uriFragment); createAndAddDiagnostic(triple); return null; } if (linkedObjects.size() > 1) throw new IllegalStateException("linkingService returned more than one object for fragment " + uriFragment); EObject result = linkedObjects.get(0); if (!EcoreUtil2.isAssignableFrom(reference.getEReferenceType(), result.eClass())) { log.error("An element of type " + result.getClass().getName() + " is not assignable to the reference " + reference.getEContainingClass().getName() + "." + reference.getName()); if (isUnresolveableProxyCacheable(triple)) unresolveableProxies.add(uriFragment); createAndAddDiagnostic(triple); return null; } // remove previously added error markers, since everything should be fine now unresolveableProxies.remove(uriFragment); removeDiagnostic(triple); return result; } catch (CyclicLinkingException e) { if (e.triple.equals(triple)) { log.error(e.getMessage(), e); if (isUnresolveableProxyCacheable(triple)) unresolveableProxies.add(uriFragment); createAndAddDiagnostic(triple); return null; } else { throw e; } } } catch (IllegalNodeException ex) { createAndAddDiagnostic(triple, ex); return null; } finally { if (cyclicLinkingDetectionCounter > cyclicLinkingDectectionCounterLimit) { resolving.remove(triple); } cyclicLinkingDetectionCounter--; } }
Example 9
Source File: LazyLinkingResource2.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** {@inheritDoc} */ @Override public synchronized EObject getEObject(final String uriFragment) { try { final EObject result = super.getEObject(uriFragment); if (result == null && getEncoder().isCrossLinkFragment(this, uriFragment)) { final ResourceSet rs = getResourceSet(); if (rs.getLoadOptions().get(MARK_UNRESOLVABLE_XREFS) == Boolean.FALSE) { Triple<EObject, EReference, INode> refInfo = getEncoder().decode(this, uriFragment); EReference reference = refInfo.getSecond(); EObject context = refInfo.getFirst(); LOGGER.warn("Failed unexpected attempt to resolve reference during indexing " + context.eClass().getName() + "#" //$NON-NLS-1$ //$NON-NLS-2$ + reference.getName() + " for object " + EcoreUtil.getURI(context), new RuntimeException()); //$NON-NLS-1$ rs.getLoadOptions().put(MARK_UNRESOLVABLE_XREFS, Boolean.TRUE); } } return result; } catch (FastLazyURIEncoder.DecodingError err) { RuntimeException cause = err.getCause(); getErrors().add(new ExceptionDiagnostic(cause)); throw new WrappedException(cause); } catch (WrappedException e) { boolean logged = false; try { if (getEncoder().isCrossLinkFragment(this, uriFragment)) { Triple<EObject, EReference, INode> triple = getEncoder().decode(this, uriFragment); INode node = triple.getThird(); final String nodeName = getLinkingHelper().getCrossRefNodeAsString(node, true); LOGGER.error("Resolution of uriFragment '" + uriFragment + "' in the resource '" + this.getURI() + "' node_name " + nodeName //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + " line " + node.getStartLine() + " offset " + node.getOffset() + " failed.", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logged = true; } // CHECKSTYLE:OFF } catch (RuntimeException e1) { // CHECKSTYLE:ON // ignore } if (!logged) { LOGGER.error("Resolution of uriFragment '" + uriFragment + "' in the resource '" + this.getURI() + "' failed.", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } throw e; } }