Java Code Examples for org.eclipse.xtext.util.Triple#getFirst()

The following examples show how to use org.eclipse.xtext.util.Triple#getFirst() . 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: BatchLinkableResource.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError {
	if (!isValidationDisabled()) {
		EObject context = triple.getFirst();
		if (context.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
			// here we may end up with cyclic resolution requests in rare situations, e.g. for input types
			// like :
			/*
			 * package p;
			 * class C extends p.C.Bogus {}
			 */
			return null;
		}
		DiagnosticMessage message = new DiagnosticMessage("Cyclic linking detected : " + getReferences(triple, resolving), Severity.ERROR, "cyclic-resolution");
		List<Diagnostic> list = getDiagnosticList(message);
		Diagnostic diagnostic = createDiagnostic(triple, message);
		if (!list.contains(diagnostic))
			list.add(diagnostic);
	}
	return null;
}
 
Example 2
Source File: TestErrorAcceptor.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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: TestErrorAcceptor.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 4
Source File: ParallelResourceLoader.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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 vote down vote up
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: LazyLinkingResource2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@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 7
Source File: LazyLinkingResource2.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** {@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;
  }
}