Java Code Examples for org.eclipse.xtext.common.types.JvmOperation#getSimpleName()

The following examples show how to use org.eclipse.xtext.common.types.JvmOperation#getSimpleName() . 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: FunctionTypes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private boolean isValidFunction(JvmOperation op) {
	// TODO we need context here - the op has to be visible
	if (op.isAbstract()) {
		if (Object.class.getName().equals(op.getDeclaringType().getIdentifier()))
			return false;
		final String name = op.getSimpleName();
		if (name.equals("toString") && op.getParameters().isEmpty())
			return false;
		if (name.equals("equals") && op.getParameters().size() == 1)
			return false;
		if (name.equals("hashCode") && op.getParameters().isEmpty())
			return false;
		return true;
	}
	return false;
}
 
Example 2
Source File: Bug621ResolvedFeatures.java    From sarl with Apache License 2.0 6 votes vote down vote up
protected void computeAllOperations(boolean isSuperClassBranch, Multimap<String, AbstractResolvedOperation> superClassBranchOperations,
		JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(isSuperClassBranch, operation, processedOperations, superClassBranchOperations);
		} else {
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				addToResult = !isOverridden(operation, processedOperations.get(simpleName));
			}
		}
		if (addToResult) {
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(operation.getSimpleName(), resolvedOperation);
			if (isSuperClassBranch) {
				superClassBranchOperations.put(operation.getSimpleName(), resolvedOperation);
			}
		}
	}
}
 
Example 3
Source File: SARLHoverSignatureProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected String _signature(JvmOperation jvmOperation, boolean typeAtEnd) {
	String returnTypeString = this.keywords.getVoidKeyword();
	final JvmTypeReference returnType = jvmOperation.getReturnType();
	if (returnType != null) {
		if (returnType instanceof JvmAnyTypeReference) {
			throw new IllegalStateException();
		}
		returnTypeString = returnType.getSimpleName();
	}

	final String signature = jvmOperation.getSimpleName() + this.hoverUiStrings.parameters(jvmOperation);
	final String postSignature = getThrowsDeclaration(jvmOperation);
	final String typeParameter = this.uiStrings.typeParameters(jvmOperation.getTypeParameters());
	if (typeParameter != null && typeParameter.length() > 0) {
		if (typeAtEnd) {
			return signature + " " + typeParameter + " " //$NON-NLS-1$ //$NON-NLS-2$
				+ this.keywords.getColonKeyword() + " " + returnTypeString + postSignature; //$NON-NLS-1$
		}
		return typeParameter + " " + returnTypeString + " " + signature + postSignature; //$NON-NLS-1$ //$NON-NLS-2$
	}
	if (typeAtEnd) {
		return signature + " " + this.keywords.getColonKeyword() + " " + returnTypeString + postSignature; //$NON-NLS-1$ //$NON-NLS-2$
	}
	return returnTypeString + " " + enrichWithDeclarator(signature, jvmOperation) + postSignature; //$NON-NLS-1$
}
 
Example 4
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmOperation findOperation(final String name) {
  ConditionUtils.checkJavaIdentifier(name, "name");
  final JvmAnnotationType annotationType = this.delegate.getAnnotation();
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(annotationType.getDeclaredOperations(), _function);
  if ((jvmOperation == null)) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("The annotation property \'");
    _builder.append(name);
    _builder.append("\' is not declared on the annotation type \'");
    String _identifier = annotationType.getIdentifier();
    _builder.append(_identifier);
    _builder.append("\'.");
    throw new IllegalArgumentException(_builder.toString());
  }
  return jvmOperation;
}
 
Example 5
Source File: JvmAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private JvmOperation findOperation(final String name) {
  ConditionUtils.checkJavaIdentifier(name, "name");
  AnnotationTypeDeclaration _annotationTypeDeclaration = this.getAnnotationTypeDeclaration();
  final JvmAnnotationType jvmAnnoType = ((JvmAnnotationTypeDeclarationImpl) _annotationTypeDeclaration).getDelegate();
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(jvmAnnoType.getDeclaredOperations(), _function);
  if ((jvmOperation == null)) {
    String _identifier = jvmAnnoType.getIdentifier();
    String _plus = ((("The annotation property \'" + name) + "\' is not declared on the annotation type \'") + _identifier);
    String _plus_1 = (_plus + "\'.");
    throw new IllegalArgumentException(_plus_1);
  }
  return jvmOperation;
}
 
Example 6
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected String _signature(JvmOperation jvmOperation, boolean typeAtEnd) {
		String returnTypeString = "void";
		// TODO resolved operations?
		JvmTypeReference returnType = jvmOperation.getReturnType();
		if (returnType != null) {
			if (returnType instanceof JvmAnyTypeReference) {
				throw new IllegalStateException();
//				returnTypeString = "Object";
			} else {
				returnTypeString = returnType.getSimpleName();
			}
		}

		String signature = jvmOperation.getSimpleName() + hoverUiStrings.parameters(jvmOperation)
				+ getThrowsDeclaration(jvmOperation);
		String typeParameter = uiStrings.typeParameters(jvmOperation.getTypeParameters());
		if(typeParameter != null && typeParameter.length() > 0){
			if (typeAtEnd)
				return signature + " " + typeParameter + " : " + returnTypeString;
			return typeParameter + " " + returnTypeString + " " + signature;
		}
		if (typeAtEnd)
			return signature + " : " + returnTypeString;
		return returnTypeString + " " + enrichWithDeclarator(signature, jvmOperation);
	}
 
Example 7
Source File: ResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllOperations(JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(operation, processedOperations);
		} else {
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				addToResult = !isOverridden(operation, processedOperations.get(simpleName));
			}
		}
		if (addToResult) {
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(operation.getSimpleName(), resolvedOperation);
		}
	}
}
 
Example 8
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllFeatures(
		JvmDeclaredType type,
		String name,
		Multimap<String, AbstractResolvedOperation> processedOperations,
		Set<String> processedFields,
		List<JvmFeature> result) {
	Iterable<JvmFeature> features = type.findAllFeaturesByName(name);
	for(JvmFeature feature: features) {
		if (feature instanceof JvmOperation) {
			JvmOperation operation = (JvmOperation) feature;
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				if (isOverridden(operation, processedOperations.get(simpleName))) {
					continue;
				}
			}
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(simpleName, resolvedOperation);
			result.add(operation);	
		} else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) {
			result.add(feature);
		}
	}
}
 
Example 9
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllFeatures(
		JvmDeclaredType type,
		Multimap<String, AbstractResolvedOperation> processedOperations,
		Set<String> processedFields,
		ListMultimap<String, JvmFeature> result,
		Set<String> seenNames) {
	Iterable<JvmFeature> features = type.getAllFeatures();
	for(JvmFeature feature: features) {
		if (!seenNames.contains(feature.getSimpleName())) {
			if (feature instanceof JvmOperation) {
				JvmOperation operation = (JvmOperation) feature;
				String simpleName = operation.getSimpleName();
				if (processedOperations.containsKey(simpleName)) {
					if (isOverridden(operation, processedOperations.get(simpleName))) {
						continue;
					}
				}
				BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
				processedOperations.put(simpleName, resolvedOperation);
				result.put(simpleName, operation);	
			} else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) {
				result.put(feature.getSimpleName(), feature);
			}
		}
	}
}
 
Example 10
Source File: JvmAnnotationValueImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getValueName() {
	JvmOperation operation = getOperation();
	if (operation == null || operation.eIsProxy())
		return null;
	return operation.getSimpleName();
}
 
Example 11
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String createSimpleMemberLink(EObject type) {
	String label = "";
	if (type instanceof JvmDeclaredType)
		label = ((JvmDeclaredType) type).getSimpleName();
	else if (type instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) type;
		label = operation.getSimpleName();
		if (operation.getParameters().size() > 0) {
			label += "(...)";
		}
	}
	return createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, EcoreUtil.getURI(type), label);
}
 
Example 12
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkLocalUsageOfDeclaredXtendFunction(XtendFunction function){
	if(doCheckValidMemberName(function) && !isIgnored(UNUSED_PRIVATE_MEMBER)) {
		JvmOperation jvmOperation = function.isDispatch()?associations.getDispatchOperation(function):associations.getDirectlyInferredOperation(function);
		if(jvmOperation != null && jvmOperation.getVisibility() == JvmVisibility.PRIVATE && !isLocallyUsed(jvmOperation, getOutermostType(function))) {
			String message = "The method " + jvmOperation.getSimpleName() 
					+  uiStrings.parameters(jvmOperation)  
					+ " from the type "+ getDeclaratorName(jvmOperation)+" is never used locally.";
			addIssueToState(UNUSED_PRIVATE_MEMBER, message, XtendPackage.Literals.XTEND_FUNCTION__NAME);
		}
	}
}
 
Example 13
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isDispatchFunction(JvmOperation inferredOperation) {
	if (inferredOperation.getSimpleName() != null && inferredOperation.getSimpleName().startsWith("_")) {
		EObject sourceElement = associations.getPrimarySourceElement(inferredOperation);
		if (sourceElement instanceof XtendFunction) {
			XtendFunction function = (XtendFunction) sourceElement;
			if (function.isDispatch() && inferredOperation.getSimpleName().equals("_" + function.getName()))
				return true;
			return false;
		}
	}
	return false;
}
 
Example 14
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Return all the cases that are associated with the given dispatch operation.
 */
public List<JvmOperation> getAllDispatchCases(JvmOperation dispatcherOperation) {
	DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
	JvmDeclaredType type = dispatcherOperation.getDeclaringType();
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
	ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type));
	return getAllDispatchMethods(dispatchSignature, type, contextualVisibilityHelper);
}
 
Example 15
Source File: XtendAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Object translateAnnotationValue(final XExpression value, final String property) {
  final JvmType annotationType = this.getDelegate().getAnnotationType();
  if ((annotationType instanceof JvmAnnotationType)) {
    final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
      String _simpleName = it.getSimpleName();
      return Boolean.valueOf(Objects.equal(_simpleName, property));
    };
    final JvmOperation operation = IterableExtensions.<JvmOperation>findFirst(Iterables.<JvmOperation>filter(((JvmAnnotationType)annotationType).getMembers(), JvmOperation.class), _function);
    if ((operation != null)) {
      final boolean array = this.getCompilationUnit().getTypeReferences().isArray(operation.getReturnType());
      return this.getCompilationUnit().translateAnnotationValue(value, operation.getReturnType(), array);
    }
  }
  return this.getCompilationUnit().translateAnnotationValue(value, null, false);
}
 
Example 16
Source File: ExpressionScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getExtensionSignature(IIdentifiableElementDescription desc) {
	JvmOperation operation = (JvmOperation) desc.getElementOrProxy();
	StringBuilder builder = new StringBuilder(64).append(desc.getName());
	String opName = operation.getSimpleName();
	if (opName.length() - 3 == desc.getName().getFirstSegment().length() && opName.startsWith("set")) {
		builder.append("=");
	}
	appendParameters(operation, builder, desc.isExtension());
	return builder.toString();
}
 
Example 17
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected String getSimpleSignature(JvmOperation jvmOperation) {
	return jvmOperation.getSimpleName() + uiStrings.parameters(jvmOperation);
}
 
Example 18
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Return the local cases that contribute to the given dispatch operation (in no particular order, but usually as defined in the file).
 */
public List<JvmOperation> getLocalDispatchCases(JvmOperation dispatcherOperation) {
	DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
	JvmDeclaredType type = dispatcherOperation.getDeclaringType();
	return getLocalDispatchCases(type, dispatchSignature);
}