Java Code Examples for org.eclipse.xtext.common.types.JvmMember#getVisibility()
The following examples show how to use
org.eclipse.xtext.common.types.JvmMember#getVisibility() .
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: XtendGenerator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
/** * Determine whether the given member is visible without considering the class hierarchy. */ private boolean isVisible(final JvmMember member, final JvmDeclaredType context) { final JvmVisibility visibility = member.getVisibility(); boolean _equals = Objects.equal(visibility, JvmVisibility.PUBLIC); if (_equals) { return true; } JvmDeclaredType _xifexpression = null; if ((member instanceof JvmDeclaredType)) { _xifexpression = ((JvmDeclaredType)member); } else { _xifexpression = member.getDeclaringType(); } final JvmDeclaredType type = _xifexpression; if ((Objects.equal(type, context) || EcoreUtil.isAncestor(context, type))) { return true; } if (((type != null) && (Objects.equal(visibility, JvmVisibility.DEFAULT) || Objects.equal(visibility, JvmVisibility.PROTECTED)))) { if (((Strings.isEmpty(context.getPackageName()) && Strings.isEmpty(type.getPackageName())) || Objects.equal(context.getPackageName(), type.getPackageName()))) { return true; } } return false; }
Example 2
Source File: ContextualVisibilityHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isVisible(JvmMember member) { // TODO private visibility? JvmVisibility visibility = member.getVisibility(); if (visibility == JvmVisibility.PUBLIC) { return true; } JvmDeclaredType type = member instanceof JvmDeclaredType ? (JvmDeclaredType) member : member.getDeclaringType(); if (type == rawContextType || EcoreUtil.isAncestor(rawContextType, type)) { return true; } if (type != null && visibility == JvmVisibility.PROTECTED) { if (superTypeNames == null) { this.superTypeNames = computeSuperTypeNames(); } if (superTypeNames.contains(type.getIdentifier())) { return true; } if (type == member) { JvmDeclaredType declaringType = member.getDeclaringType(); if (declaringType != null && superTypeNames.contains(declaringType.getIdentifier())) { return true; } } } if (type != null && (rawContextType == null || rawContextType instanceof JvmDeclaredType) && (visibility == JvmVisibility.DEFAULT || visibility == JvmVisibility.PROTECTED)) { if (Strings.isEmpty(packageName) && Strings.isEmpty(type.getPackageName()) || (packageName != null && packageName.equals(type.getPackageName()))) { return true; } } return parent.isVisible(member); }
Example 3
Source File: XtendGenerator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ITreeAppendable generateVisibilityModifier(final JvmMember it, final ITreeAppendable result) { ITreeAppendable _xblockexpression = null; { JvmVisibility _visibility = it.getVisibility(); boolean _equals = Objects.equal(_visibility, JvmVisibility.PRIVATE); if (_equals) { JvmDeclaredType _declaringType = it.getDeclaringType(); boolean _tripleEquals = (_declaringType == null); if (_tripleEquals) { return result; } if ((it.getDeclaringType().isLocal() && (it instanceof JvmOperation))) { JvmDeclaredType _declaringType_1 = it.getDeclaringType(); final JvmGenericType declarator = ((JvmGenericType) _declaringType_1); boolean _isAnonymous = declarator.isAnonymous(); boolean _not = (!_isAnonymous); if (_not) { return result; } } } else { JvmVisibility _visibility_1 = it.getVisibility(); boolean _equals_1 = Objects.equal(_visibility_1, JvmVisibility.PUBLIC); if (_equals_1) { if (((it.getDeclaringType() instanceof JvmGenericType) && ((JvmGenericType) it.getDeclaringType()).isInterface())) { return result; } } } _xblockexpression = super.generateVisibilityModifier(it, result); } return _xblockexpression; }
Example 4
Source File: Utils.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the target feature is visible from the type. * * @param fromType - the type from which the feature visibility is tested. * @param target - the feature to test for the visibility. * @return {@code true} if the given type can see the target feature. */ public static boolean isVisible(JvmDeclaredType fromType, JvmMember target) { switch (target.getVisibility()) { case DEFAULT: return target.getDeclaringType().getPackageName().equals(fromType.getPackageName()); case PROTECTED: case PUBLIC: return true; case PRIVATE: default: } return false; }
Example 5
Source File: PublicVisibilityHelper.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public boolean isVisible(/* @NonNull */ JvmMember member) { return member.getVisibility() == JvmVisibility.PUBLIC; }
Example 6
Source File: FeatureScopeSessionWithContext.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public boolean isVisible(JvmMember member, /* @Nullable */ LightweightTypeReference receiverType, /* @Nullable */ JvmIdentifiableElement receiverFeature) { boolean result = isVisible(member); if (result && JvmVisibility.PROTECTED == member.getVisibility()) { if (receiverFeature != null) { // We bypass this check for qualified.this and qualified.super in the scope provider // they are considered to be always visible /* * class A { * class B { * { * A.super.toString * } * } * } */ if (isThisSuperOrTypeLiteral(receiverFeature)) { if (receiverType == null || !receiverType.isType(Class.class)) { return true; } } } JvmType contextType = visibilityHelper.getRawContextType(); if (contextType instanceof JvmDeclaredType) { String packageName = visibilityHelper.getPackageName(); JvmDeclaredType declaringType = member.getDeclaringType(); String memberPackageName = declaringType.getPackageName(); if (Strings.equal(packageName, memberPackageName)) { return true; } } if (receiverType != null) { if (receiverType.isSubtypeOf(contextType)) { return true; } EObject container = contextType.eContainer(); while (container instanceof JvmType) { if (receiverType.isSubtypeOf((JvmType)container)) { return true; } container = container.eContainer(); } } return false; } return result; }
Example 7
Source File: JdtTypesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * Compute the JVM modifiers that corresponds to the given description. * * <p>This function fixes the issue related to the missed modifiers given to the content assist. * * @param context the current content assist context. * @param description the description. * @return the JVM modifiers. * @since 2.11 */ protected int getDirtyStateModifiers(ContentAssistContext context, IEObjectDescription description) { EObject eobject = description.getEObjectOrProxy(); if (eobject.eIsProxy()) { eobject = EcoreUtil.resolve(eobject, context.getResource().getResourceSet()); } int accessModifiers = Flags.AccPublic; int otherModifiers = 0; if (eobject instanceof JvmMember) { final JvmMember member = (JvmMember) eobject; switch (member.getVisibility()) { case PUBLIC: accessModifiers = Flags.AccPublic; break; case PRIVATE: accessModifiers = Flags.AccPrivate; break; case PROTECTED: accessModifiers = Flags.AccProtected; break; case DEFAULT: default: accessModifiers = Flags.AccDefault; break; } if (DeprecationUtil.isDeprecated(member)) { otherModifiers |= Flags.AccDeprecated; } if (eobject instanceof JvmDeclaredType) { final JvmDeclaredType type = (JvmDeclaredType) eobject; if (type.isFinal()) { otherModifiers |= Flags.AccFinal; } if (type.isAbstract()) { otherModifiers |= Flags.AccAbstract; } if (type.isStatic()) { otherModifiers |= Flags.AccStatic; } if (type instanceof JvmEnumerationType) { otherModifiers |= Flags.AccEnum; } else if (type instanceof JvmAnnotationType) { otherModifiers |= Flags.AccAnnotation; } else if (type instanceof JvmGenericType) { if (((JvmGenericType) type).isInterface()) { otherModifiers |= Flags.AccInterface; } } } } return accessModifiers | otherModifiers; }