private boolean isNestedTypeOf(JvmType child, JvmDeclaredType parent) { if (child instanceof JvmMember) { JvmMember member = (JvmMember) child; return member.getDeclaringType() == parent; } return false; }
protected boolean isInheritanceRelation(JvmMember overriding, JvmMember overridden) { return superTypeCollector.isSuperType(overriding.getDeclaringType(), overridden.getDeclaringType()); }
protected String getPackageName(JvmMember context) { if(context.getDeclaringType() != null) return getPackageName(context.getDeclaringType()); if(context instanceof JvmDeclaredType) return ((JvmDeclaredType)context).getPackageName(); else return null; }
protected String getDeclaratorSimpleName(JvmIdentifiableElement element) { if (element instanceof JvmConstructor) { return null; } if (element instanceof JvmMember) { return ((JvmMember) element).getDeclaringType().getSimpleName(); } return null; }
protected String getDeclaratorSimpleName(JvmIdentifiableElement element) { if (element instanceof JvmConstructor) { return null; } if (element instanceof JvmMember) { return ((JvmMember) element).getDeclaringType().getSimpleName(); } return null; }
protected void acceptStaticImport(JvmMember member) { JvmDeclaredType declarator = member.getDeclaringType(); if (!needsStaticImport(declarator) || implicitStaticImports.contains(declarator)) return; typeUsages.addStaticImport(member); }
protected void acceptStaticExtensionImport(JvmMember member) { JvmDeclaredType declarator = member.getDeclaringType(); if (!needsStaticImport(declarator) || implicitExtensionImports.contains(declarator)) return; typeUsages.addExtensionImport(member); }
protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) { final JvmIdentifiableElement feature = sourceCandidate.getFeature(); if ((feature instanceof JvmMember)) { final JvmDeclaredType type = ((JvmMember)feature).getDeclaringType(); this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor); } }
@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; } } } _xblockexpression = super.generateVisibilityModifier(it, result); } return _xblockexpression; }
public boolean addStaticExtensionImport(JvmMember member) { if (member instanceof JvmDeclaredType) { return addStaticExtensionImport((JvmDeclaredType) member, null); } else { return addStaticExtensionImport(member.getDeclaringType(), member.getSimpleName()); } }
protected IScope getThisOrSuperScope(XAbstractFeatureCall call, JvmType thisOrSuper) { QualifiedName name = THIS; JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(call); if (logicalContainer instanceof JvmMember) { JvmDeclaredType thisType = ((JvmMember) logicalContainer).getDeclaringType(); if (thisType != thisOrSuper) { name = SUPER; } } return new SingletonScope(EObjectDescription.create(name, thisOrSuper), IScope.NULLSCOPE); } }
/** 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</code> 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; }
@Override public TypeDeclaration getDeclaringType() { return this.getCompilationUnit().toTypeDeclaration(this.getDelegate().getDeclaringType()); }
public boolean addStaticImport(JvmMember member) { if (member instanceof JvmDeclaredType) { return addStaticImport((JvmDeclaredType) member, null); } else { return addStaticImport(member.getDeclaringType(), member.getSimpleName()); } }
private boolean isFromXbaseLibrary(final XAbstractFeatureCall it, final EvaluationContext context) { boolean _xblockexpression = false; { final JvmIdentifiableElement feature = this.getFeature(it, context); boolean _switchResult = false; boolean _matched = false; if (feature instanceof JvmMember) { _matched=true; JvmDeclaredType _declaringType = null; if (((JvmMember)feature)!=null) { _declaringType=((JvmMember)feature).getDeclaringType(); } String _packageName = null; if (_declaringType!=null) { _packageName=_declaringType.getPackageName(); } String _string = XImportSectionNamespaceScopeProvider.XBASE_LIB.toString(); _switchResult = Objects.equal(_packageName, _string); } if (!_matched) { _switchResult = false; } _xblockexpression = _switchResult; } return _xblockexpression; }
/** * 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; }
public boolean isVisible(final JvmMember jvmMember, JvmDeclaredType contextType) { if (jvmMember.getVisibility() == JvmVisibility.PUBLIC) return true; if (contextType == null) { return false; } else if (jvmMember.getVisibility() == JvmVisibility.DEFAULT) { if (jvmMember instanceof JvmDeclaredType) { return equal(((JvmDeclaredType) jvmMember).getPackageName(), contextType.getPackageName()); } else { JvmDeclaredType declaringType = jvmMember.getDeclaringType(); if (declaringType != null) return equal(declaringType.getPackageName(), contextType.getPackageName()); return true; } } else if (contextType.equals(jvmMember.getDeclaringType())) { return true; } else { JvmParameterizedTypeReference typeReference = typesFactory.createJvmParameterizedTypeReference(); typeReference.setType(contextType); Set<JvmType> rawTypes = superTypeCollector.collectSuperTypesAsRawTypes(typeReference); if (rawTypes.contains(jvmMember.getDeclaringType())) { return jvmMember.getVisibility() == JvmVisibility.PROTECTED; } return false; } } }
protected void process(JvmMember context, Map<String, JvmIdentifiableElement> result) { if (context instanceof JvmDeclaredType) { if (!result.containsKey(context.getSimpleName())) result.put(context.getSimpleName(), context); JvmDeclaredType contextType = (JvmDeclaredType) context; ContextualVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(this.visibilityHelper, contextType); addInnerTypes(contextType, "", visibilityHelper, result); Set<JvmType> superTypes = rawSuperTypes.collect(contextType); for (JvmType superType : superTypes) { if (superType instanceof JvmDeclaredType) addInnerTypes((JvmDeclaredType) superType, "", visibilityHelper, result); } } if (context instanceof JvmTypeParameterDeclarator) addTypeParameters((JvmTypeParameterDeclarator) context, result); JvmDeclaredType declaringType = context.getDeclaringType(); if (declaringType != null) process(declaringType, result); }
public LightweightTypeReference getExpectedReceiverType(JvmIdentifiableElement linkedFeature, LightweightTypeReference receiverType) { if (receiverType.isMultiType() && linkedFeature instanceof JvmMember) { LightweightTypeReference declaratorReference = receiverType.getOwner().newParameterizedTypeReference(((JvmMember) linkedFeature).getDeclaringType()); if (!declaratorReference.isAssignableFrom(receiverType.toJavaType())) { for(LightweightTypeReference multiTypeComponent: receiverType.getMultiTypeComponents()) { if (declaratorReference.isAssignableFrom(multiTypeComponent)) { return multiTypeComponent; } } } else { return declaratorReference; } } else if (receiverType.isSynonym() && linkedFeature instanceof JvmMember) { List<LightweightTypeReference> components = receiverType.getMultiTypeComponents(); return components.get(components.size() - 1); } return receiverType; }
/** * Tries to locate the syntax for the type reference that the user used in the original code. * Especially interesting for nested types, where one could prefer the (arguably) more explicit (or verbose) * {@code Resource$Factory} with an import of {@code org.eclipse.emf.core.Resource} over the probably shorter * {@code Factory} with an import of {@code org.eclipse.emf.core.Resource$Factory}. * * The function relies on a node model to be available. Otherwise the actually referenced type is * used as the preferred type. * * @param owner the referrer to the JVM concept. * @param reference a reference to a {@link JvmType} or {@link JvmMember} that is declared in a type. * @return the referenced type or one of its containers. */ protected PreferredType findPreferredType(EObject owner, EReference reference, String text) { JvmIdentifiableElement referencedThing = getReferencedElement(owner, reference); JvmDeclaredType referencedType = null; if (referencedThing instanceof JvmDeclaredType) { referencedType = (JvmDeclaredType) referencedThing; } else if (referencedThing instanceof JvmMember) { referencedType = ((JvmMember) referencedThing).getDeclaringType(); } else if(referencedThing instanceof JvmType) { if (referencedThing.eIsProxy()) { String importedName = getFirstNameSegment(owner, reference); return new PreferredType(importedName); } return null; } return findPreferredType(referencedType, text); }