Java Code Examples for org.eclipse.xtext.common.types.JvmFeature#getDeclaringType()

The following examples show how to use org.eclipse.xtext.common.types.JvmFeature#getDeclaringType() . 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: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String resolveNameConflict(EObject referringElement, EReference reference, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
	if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_IDENTIFIABLE_ELEMENT, reference.getEReferenceType())) {
		if (newTargetElement instanceof JvmType) {
			JvmType type = (JvmType) newTargetElement;
			
			if (canLinkJvmType(referringElement, type)) {
				return toString(qualifiedNameProvider.getFullyQualifiedName(type));
			}
		}
		if (newTargetElement instanceof JvmFeature) {
			JvmFeature feature = (JvmFeature) newTargetElement;
			if (feature.isStatic() && !isStaticExtensionFeatureCall(referringElement, reference, newTargetElement)) {
				JvmDeclaredType declaringType = feature.getDeclaringType();
				
				if (canLinkJvmType(referringElement, declaringType)) {
					JvmDeclaredType parentType = declaringType;
					
					List<String> segments = new LinkedList<String>();
					segments.add(feature.getSimpleName());
					segments.add(0, parentType.getSimpleName());
					while (!hasImportedType(updateAcceptor, parentType)) {
						parentType = parentType.getDeclaringType();
						if (parentType == null) {
							return toString(qualifiedNameProvider.getFullyQualifiedName(feature));
						}
						segments.add(0, parentType.getSimpleName());
					}
					return toString(QualifiedName.create(segments));
				}
			}
		}
	}
	return super.resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
 
Example 2
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected String getDeclaratorName(JvmFeature feature) {
	JvmDeclaredType declarator = feature.getDeclaringType();
	if (declarator.isLocal()) {
		return "new " + Iterables.getLast(declarator.getSuperTypes()).getType().getSimpleName()+ "(){}";
	} else {
		return declarator.getSimpleName();
	}
}
 
Example 3
Source File: AbstractResolvedFeature.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public LightweightTypeReference getResolvedDeclarator() {
	JvmFeature declaration = getDeclaration();
	JvmDeclaredType declarator = declaration.getDeclaringType();
	return getContextType().getSuperType(declarator);
}
 
Example 4
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Image computeImage(JvmFeature feature) {
	int flags = 0;
	int decorator = 0;
	switch(feature.getVisibility()) {
		case PUBLIC: flags = Flags.AccPublic; break;
		case PROTECTED: flags = Flags.AccProtected; break;
		case PRIVATE: flags = Flags.AccPrivate; break;
		case DEFAULT: flags = Flags.AccDefault; break;
	}
	JvmDeclaredType declaringType = feature.getDeclaringType();
	boolean interfaceOrAnnotation = false;
	if (declaringType instanceof JvmGenericType) {
		interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
	} else if (declaringType instanceof JvmAnnotationType) {
		interfaceOrAnnotation = true;
	}
	if (feature instanceof JvmConstructor) {
		decorator = JavaElementImageDescriptor.CONSTRUCTOR;
		if (declaringType.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (operation.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (operation.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (operation.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		return computeMethodImage(interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		if (field.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (field.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		if (declaringType instanceof JvmEnumerationType)
			flags |= Flags.AccEnum;
		return computeFieldImage(interfaceOrAnnotation, flags, decorator);
	} 
	return null;
}