org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable. 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: ThrownExceptionSwitch.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Checks if the automatically called close method of resources in
 * try block (implementing AutoCloseable) throws exceptions.
 * Add those those exceptions to the list of the thrownExceptionDelegate.
 * 
 * @param resources the resources of the try statement
 * @param thrownExceptionDelegate the (filtered) delegate holding the utilities
 * 
 * @since 2.18
 */
protected void processExceptionsFromAutoclosable(List<XVariableDeclaration> resources,
		IThrownExceptionDelegate thrownExceptionDelegate) {
	
	// If no resources are give, no exceptions are thrown
	if (resources.isEmpty()) {
		return;
	}
	
	// Check for each resource which exceptions are thrown
	for (XVariableDeclaration resource : resources) {
		LightweightTypeReference autoClosableType = thrownExceptionDelegate.getActualType((JvmIdentifiableElement) resource);
		JvmOperation closeMethod = findCloseMethod(autoClosableType);
		// Collect all exceptions
		if (autoClosableType != null && closeMethod != null) {
			IResolvedExecutable resolvedCloseMethod = thrownExceptionDelegate.getResolvedFeature(closeMethod, autoClosableType);
			List<LightweightTypeReference> declaredExceptions = resolvedCloseMethod.getResolvedExceptions();
			for(LightweightTypeReference exception: declaredExceptions) {
				thrownExceptionDelegate.accept(exception);
			}
		}
	}
}
 
Example #2
Source File: MemberFromSuperImplementor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) {
  final JvmExecutable executable = overridden.getDeclaration();
  builder.setContext(overrider);
  builder.setVisibility(overridden.getDeclaration().getVisibility());
  final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> {
    final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue());
    final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder();
    parameterBuilder.setName(declaredParameter.getSimpleName());
    parameterBuilder.setType(it);
    JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class);
    boolean _tripleNotEquals = (_findAnnotation != null);
    parameterBuilder.setExtensionFlag(_tripleNotEquals);
  };
  IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function);
  builder.setVarArgsFlag(executable.isVarArgs());
  builder.setExceptions(overridden.getResolvedExceptions());
}
 
Example #3
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isCandidate(LightweightTypeReference type, IResolvedExecutable executable,
		IVisibilityHelper visibilityHelper) {
	JvmDeclaredType declaringType = executable.getDeclaration().getDeclaringType();
	if (type.getType() != declaringType && isVisible(executable, visibilityHelper)) {
		JvmExecutable rawExecutable = executable.getDeclaration();
		if (rawExecutable instanceof JvmOperation) {
			JvmOperation operation = (JvmOperation) rawExecutable;
			if (operation.isFinal() || operation.isStatic()) {
				return false;
			} else {
				if (type.getType() instanceof JvmGenericType && ((JvmGenericType) type.getType()).isInterface()) {
					return  declaringType instanceof JvmGenericType
							&& ((JvmGenericType) declaringType).isInterface() && !operation.isAbstract();
				} else {
					return true;
				}
			}
		} else {
			return true;
		}
	}
	return false;
}
 
Example #4
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void addConstructorCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	LightweightTypeReference typeReference = resolvedFeatures.getType();
	List<LightweightTypeReference> superTypes = typeReference.getSuperTypes();
	for (LightweightTypeReference superType : superTypes) {
		if (!superType.isInterfaceType()) {
			List<IResolvedConstructor> declaredConstructors = resolvedFeatures.getDeclaredConstructors();
			Set<String> erasedSignatures = Sets.<String>newHashSet();
			for (IResolvedConstructor constructor : declaredConstructors) {
				erasedSignatures.add(constructor.getResolvedErasureSignature());
			}
			ResolvedFeatures superClass = overrideHelper.getResolvedFeatures(superType);
			for (IResolvedConstructor superclassConstructor : superClass.getDeclaredConstructors()) {
				IResolvedConstructor overriddenConstructor = new ResolvedConstructor(
						superclassConstructor.getDeclaration(), typeReference);
				if (isCandidate(typeReference, overriddenConstructor, visibilityHelper)) {
					if (erasedSignatures.add(superclassConstructor.getResolvedErasureSignature())) {
						result.add(overriddenConstructor);
					}
				}
			}
			return;
		}
	}
}
 
Example #5
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addOperationCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	List<IResolvedOperation> allOperations = resolvedFeatures.getAllOperations();
	LightweightTypeReference inferredType = resolvedFeatures.getType();
	for (IResolvedOperation operation : allOperations) {
		if (isCandidate(inferredType, operation, visibilityHelper)) {
			result.add(operation);
		}
	}
}
 
Example #6
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public List<IResolvedExecutable> getImplementationCandidates(JvmDeclaredType type, boolean isAnonymous) {
	if (type == null || !(type instanceof JvmGenericType)) {
		return Collections.emptyList();
	}
	JavaVersion sourceVersion = generatorConfigProvider.get(type).getJavaSourceVersion();
	ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(type, sourceVersion);
	List<IResolvedExecutable> result = new ArrayList<>();
	ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper,
			resolvedFeatures.getType());
	addOperationCandidates(resolvedFeatures, contextualVisibilityHelper, result);
	if (!isAnonymous && !((JvmGenericType) type).isInterface()) {
		addConstructorCandidates(resolvedFeatures, contextualVisibilityHelper, result);
	}
	return result;
}
 
Example #7
Source File: ExtendedEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResolvedExecutable getResolvedFeature(JvmExecutable executable, LightweightTypeReference contextType) {
	if (executable instanceof JvmOperation) {
		return new BottomResolvedOperation((JvmOperation) executable, contextType, overrideTester);
	}
	if (executable instanceof JvmConstructor) {
		return new ResolvedConstructor((JvmConstructor) executable, contextType);
	}
	throw new IllegalArgumentException(String.valueOf(executable));
}
 
Example #8
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String toQualifiedName(XExpression expression, IResolvedExecutable resolvedExecutable, JvmExecutable executable,
		IResolvedTypes resolvedTypes, List<XExpression> arguments) {
	LightweightTypeReference actualType = resolvedTypes.getActualType(expression);
	if (actualType != null && !actualType.isAny() && !actualType.isUnknown()) {
		return actualType.getHumanReadableName();
	}

	int index = arguments.indexOf(expression);
	if (resolvedExecutable == null) {
		return executable.getParameters().get(index).getParameterType().getSimpleName();
	}
	return resolvedExecutable.getResolvedParameterTypes().get(index).getSimpleName();
}
 
Example #9
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _getQualifiedName(JvmExecutable executable, XAbstractFeatureCall featureCall) {
	IResolvedTypes resolvedTypes = typeResolver.resolveTypes(featureCall);
	IResolvedExecutable resolvedExecutable = resolveExecutable(executable, featureCall, resolvedTypes);
	return toFullyQualifiedName(executable) //
			+ "(" + toQualifiedNames(featureCall.getActualArguments(), //
					(argument) -> toQualifiedName(argument, resolvedExecutable, executable, resolvedTypes,
							featureCall.getActualArguments()))
			+ ")";
}
 
Example #10
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _getQualifiedName(JvmConstructor constructor, XConstructorCall constructorCall) {
	IResolvedTypes resolvedTypes = typeResolver.resolveTypes(constructorCall);
	IResolvedExecutable resolvedExecutable = resolveExecutable(constructor, constructorCall, resolvedTypes);
	return toFullyQualifiedName(constructor) //
			+ "(" + toQualifiedNames(constructorCall.getArguments(), //
					(argument) -> toQualifiedName(argument, resolvedExecutable, constructor, resolvedTypes,
							constructorCall.getArguments()))
			+ ")";
}
 
Example #11
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable resolveExecutable(JvmExecutable consturctor, XExpression expression, IResolvedTypes resolvedTypes) {
	if (consturctor instanceof JvmConstructor && expression instanceof XAbstractFeatureCall) {
		return _resolveExecutable((JvmConstructor) consturctor, (XAbstractFeatureCall) expression, resolvedTypes);
	} else if (consturctor instanceof JvmConstructor && expression instanceof XConstructorCall) {
		return _resolveExecutable((JvmConstructor) consturctor, (XConstructorCall) expression, resolvedTypes);
	} else if (consturctor instanceof JvmOperation && expression instanceof XAbstractFeatureCall) {
		return _resolveExecutable((JvmOperation) consturctor, (XAbstractFeatureCall) expression, resolvedTypes);
	} else {
		throw new IllegalArgumentException(
				"Unhandled parameter types: " + Arrays.asList(consturctor, expression, resolvedTypes).toString());
	}
}
 
Example #12
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private IResolvedExecutable findDeclaredConstructor(JvmConstructor constructor, LightweightTypeReference actualType) {
	ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(actualType);
	for (IResolvedConstructor declaredConstructor : resolvedFeatures.getDeclaredConstructors()) {
		if (declaredConstructor.getDeclaration().equals(constructor)) {
			return declaredConstructor;
		}
	}
	return null;
}
 
Example #13
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable _resolveExecutable(JvmConstructor constructor, XAbstractFeatureCall featureCall,
		IResolvedTypes resolvedTypes) {
	XExpression actualReceiver = featureCall.getActualReceiver();
	if (actualReceiver != null) {
		LightweightTypeReference actualType = resolvedTypes.getActualType(actualReceiver);
		return findDeclaredConstructor(constructor, actualType);
	}
	return null;
}
 
Example #14
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable _resolveExecutable(JvmConstructor constructor, XConstructorCall constructorCall,
		IResolvedTypes resolvedTypes) {
	LightweightTypeReference actualType = resolvedTypes.getActualType(constructorCall);
	if (actualType != null) {
		return findDeclaredConstructor(constructor, actualType);
	}
	return null;
}
 
Example #15
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable _resolveExecutable(JvmOperation operation, XAbstractFeatureCall featureCall,
		IResolvedTypes resolvedTypes) {
	XExpression actualReceiver = featureCall.getActualReceiver();
	if (actualReceiver != null) {
		LightweightTypeReference actualType = resolvedTypes.getActualType(actualReceiver);
		ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(actualType);
		for (IResolvedOperation resolvedOperation : resolvedFeatures.getAllOperations()) {
			if (resolvedOperation.getDeclaration().equals(operation)) {
				return resolvedOperation;
			}
		}
	}
	return null;
}
 
Example #16
Source File: ImplementMemberFromSuperAssist.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void createOverrideProposals(XtendTypeDeclaration model, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor, IProposalConflictHelper conflictHelper) {
	final JvmDeclaredType inferredType = associations.getInferredType(model);
	List<IResolvedExecutable> overrideables = overrideProposalUtil.getImplementationCandidates(inferredType, model.isAnonymous());
	for (IResolvedExecutable overrideable : overrideables) {
		ICompletionProposal completionProposal = createOverrideMethodProposal(model, overrideable, context,	conflictHelper);
		if (completionProposal != null)
			acceptor.accept(completionProposal);
	}
}
 
Example #17
Source File: ImplementMemberFromSuperAssist.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected StyledString getLabel(IResolvedExecutable executable) {
	if (executable instanceof IResolvedOperation) {
		IResolvedOperation resolvedOperation = (IResolvedOperation) executable;
		return new StyledString(resolvedOperation.getSimpleSignature()).append(
				" - Override method from " + resolvedOperation.getResolvedDeclarator().getHumanReadableName(),
				StyledString.QUALIFIER_STYLER);
	} else {
		return new StyledString("Add constructor 'new " + executable.getSimpleSignature() + "'");
	}
}
 
Example #18
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isVisible(IResolvedExecutable executable, IVisibilityHelper visibilityHelper) {
	return visibilityHelper.isVisible(executable.getDeclaration());
}
 
Example #19
Source File: ImplementMemberFromSuperAssist.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected ICompletionProposal createOverrideMethodProposal(XtendTypeDeclaration model, IResolvedExecutable overrideable,
		final ContentAssistContext context, IProposalConflictHelper conflictHelper) {
	IXtextDocument document = context.getDocument();
	XtextResource resource = (XtextResource) model.eResource();
	int offset = context.getReplaceRegion().getOffset();
	int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, resource);
	final int indentationLevel = currentIndentation == 0 ? 1 : currentIndentation;
	ReplacingAppendable appendable = appendableFactory.create(document, resource, offset, context.getReplaceRegion().getLength(), new OptionalParameters() {{ 
				ensureEmptyLinesAround = true;
				baseIndentationLevel = indentationLevel;	
			}});
	final String simpleName;
	JvmExecutable declaration = overrideable.getDeclaration();
	if (overrideable instanceof IResolvedOperation) {
		implementor.appendOverrideFunction(model, (IResolvedOperation) overrideable, appendable);
		simpleName = overrideable.getDeclaration().getSimpleName();
	} else if (model instanceof XtendClass) {
		implementor.appendConstructorFromSuper((XtendClass) model, (IResolvedConstructor) overrideable, appendable);
		simpleName = "new";
	} else {
		return null;
	}
	String code = appendable.getCode();
	if (!isValidProposal(code.trim(), context, conflictHelper) && !isValidProposal(simpleName, context, conflictHelper))
		return null;
	ImageDescriptor imageDescriptor = images.forOperation(declaration.getVisibility(), adornments.getOverrideAdornment(declaration));
	ImportOrganizingProposal completionProposal = createCompletionProposal(appendable, context.getReplaceRegion(),
			getLabel(overrideable), imageHelper.getImage(imageDescriptor));
	Matcher matcher = bodyExpressionPattern.matcher(code);
	if (matcher.find()) {
		int bodyExpressionLength = matcher.end(1) - matcher.start(1);
		int bodyExpressionStart = matcher.start(1) + appendable.getTotalOffset() - completionProposal.getReplacementOffset();
		if (bodyExpressionLength == 0) {
			completionProposal.setCursorPosition(bodyExpressionStart);
		} else {
			completionProposal.setSelectionStart(completionProposal.getReplacementOffset() + bodyExpressionStart);
			completionProposal.setSelectionLength(bodyExpressionLength);
			completionProposal.setAutoInsertable(false);
			completionProposal.setCursorPosition(bodyExpressionStart + bodyExpressionLength);
			completionProposal.setSimpleLinkedMode(context.getViewer(), '\t');
		}
	}
	completionProposal.setPriority(getPriority(model, declaration, context));
	completionProposal.setMatcher(new PrefixMatcher() {

		@Override
		public boolean isCandidateMatchingPrefix(String name, String prefix) {
			PrefixMatcher delegate = context.getMatcher();
			boolean result = delegate.isCandidateMatchingPrefix(simpleName, prefix);
			return result;
		}
		
	});
	return completionProposal;
}
 
Example #20
Source File: IThrownExceptionDelegate.java    From xtext-extras with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @since 2.18
 */
IResolvedExecutable getResolvedFeature(JvmExecutable executable, LightweightTypeReference contextType);