public ContextualVisibilityHelper(IVisibilityHelper parent, JvmType rawContextType) { this.parent = parent; this.rawContextType = rawContextType; if (rawContextType instanceof JvmDeclaredType) { this.packageName = ((JvmDeclaredType) rawContextType).getPackageName(); } }
public boolean needsImport(JvmDeclaredType type) { if (type.getDeclaringType() != null) return true; String packageName = type.getPackageName(); return packageName != null && !(implicitlyImportedPackages.contains(packageName)); }
@Override public String getPackageName() { JvmDeclaredType declaringType = internalGetDeclaringType(); if (declaringType != null) return declaringType.getPackageName(); return packageName; }
@Override public String getPackageName() { JvmDeclaredType declaringType = getDeclaringType(); if (declaringType != null) return declaringType.getPackageName(); return packageName; }
/** 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; }
private boolean isAccessibleBy(final JvmField field, final JvmDeclaredType sourceType) { JvmVisibility _visibility = field.getVisibility(); boolean _equals = Objects.equal(_visibility, JvmVisibility.PRIVATE); if (_equals) { return false; } JvmVisibility _visibility_1 = field.getVisibility(); boolean _equals_1 = Objects.equal(_visibility_1, JvmVisibility.DEFAULT); if (_equals_1) { String _packageName = field.getDeclaringType().getPackageName(); String _packageName_1 = sourceType.getPackageName(); return Objects.equal(_packageName, _packageName_1); } return true; }
protected Multimap<String, JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) { Multimap<String, JvmDeclaredType> result = LinkedHashMultimap.create(); for(JvmDeclaredType type: config.getLocallyDefinedTypes(resource)) { String packageName = type.getPackageName(); if(isEmpty(packageName)) result.put(type.getQualifiedName('.'), type); else result.put(type.getQualifiedName('.').substring(packageName.length() + 1), type); } return result; }
public ContextualVisibilityHelper(IVisibilityHelper parent, LightweightTypeReference contextType) { this.parent = parent; this.rawContextType = contextType.getRawTypeReference().getType(); if (rawContextType instanceof JvmDeclaredType) { this.packageName = ((JvmDeclaredType) rawContextType).getPackageName(); } }
/** * 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; }
protected String getPackageLocalName(JvmDeclaredType type) { String packageName = type.getPackageName(); if (isEmpty(packageName)) return type.getQualifiedName('.'); else return type.getQualifiedName('.').substring(packageName.length() + 1); }
private AbstractScope getResourceTypeScope(Resource resource, String packageName, AbstractScope parent) { List<EObject> contents = resource.getContents(); List<JvmType> knownTypes = Lists.newArrayListWithExpectedSize(contents.size() - 1); for(EObject content: contents) { if (content instanceof JvmType) { if (content instanceof JvmDeclaredType) { if (Strings.equal(packageName, ((JvmDeclaredType) content).getPackageName())) { knownTypes.add((JvmType) content); } } else { knownTypes.add((JvmType) content); } } } if (knownTypes.isEmpty()) return parent; return new KnownTypesScope(knownTypes, parent); }
protected String getPackageName(JvmMember context) { if(context.getDeclaringType() != null) return getPackageName(context.getDeclaringType()); if(context instanceof JvmDeclaredType) return ((JvmDeclaredType)context).getPackageName(); else return null; }
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; }
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; } } }
@Override protected void preApply() { XAbstractFeatureCall expression = getExpression(); JvmType type = getType(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } else { String queriedName = description.getName().toString(); // may be Map$Entry String qualifiedName = declaredType.getIdentifier(); String packageName = Strings.emptyIfNull(declaredType.getPackageName()); if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } } }
protected AbstractNestedFeatureScopeSession tryCreateNestedSessionWithVisibilityContext(Map<QualifiedName, JvmIdentifiableElement> elements, ITypeReferenceOwner owner, QualifiedName thisName) { if (elements.containsKey(thisName)) { JvmIdentifiableElement associatedWithThis = elements.get(thisName); if (associatedWithThis instanceof JvmType) { if (IFeatureNames.SELF.equals(thisName)) { IEObjectDescription thisDescription = getLocalElement(IFeatureNames.THIS); if (thisDescription != null && thisDescription.getEObjectOrProxy() instanceof JvmDeclaredType) { JvmDeclaredType thisType = (JvmDeclaredType) thisDescription.getEObjectOrProxy(); LightweightTypeReference context = owner.toPlainTypeReference((JvmType) associatedWithThis); FeatureScopeSessionWithContext contextSession = new FeatureScopeSessionWithContext(this, context, thisType.getPackageName()); AbstractNestedFeatureScopeSession result = new FeatureScopeSessionWithLocalElements(contextSession, elements); return result; } } LightweightTypeReference context = owner.toPlainTypeReference((JvmType) associatedWithThis); FeatureScopeSessionWithContext contextSession = new FeatureScopeSessionWithContext(this, context); AbstractNestedFeatureScopeSession result = new FeatureScopeSessionWithLocalElements(contextSession, elements); return result; } } return null; }
protected boolean isUsedInLocalContextOnly(JvmDeclaredType type, Iterable<TypeUsage> usages, NonOverridableTypesProvider nonOverridableTypesProvider, String name) { for (TypeUsage usage : usages) { JvmIdentifiableElement visibleType = nonOverridableTypesProvider.getVisibleType(usage.getContext(), name); if (visibleType == null && ( !equal(usage.getContextPackageName(), type.getPackageName()) || (type.getDeclaringType() != null && usage.getContext().eResource() != type.getDeclaringType().eResource()) )) return false; } return true; } }
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
private ReplaceRegion getReplaceRegion(String nameToUse, String packageLocalName, JvmDeclaredType type, TypeUsage usage, RewritableImportSection importSection) { // if the resource contains two types with the same simple name, we don't add any import // but we can still use the package local name within the same package. // Except for inner types if (equal(usage.getContextPackageName(), type.getPackageName()) && type.getDeclaringType() == null) { if (type.eContainer() != null) { String declarationLocalName = getLocalName(type, usage.getContext()); nameToUse = declarationLocalName; } else if (importSection.getImportedTypes(packageLocalName) == null) { nameToUse = packageLocalName; } } String textToUse = getConcreteSyntax(nameToUse, type, usage); return new ReplaceRegion(usage.getTextRegion(), textToUse); }
public CharSequence generateType(final JvmDeclaredType type, final GeneratorConfig config) { final ImportManager importManager = this.createImportManager(type); final TreeAppendable bodyAppendable = this.createAppendable(type, importManager, config); bodyAppendable.openScope(); this.assignThisAndSuper(bodyAppendable, type, config); this.generateBody(type, bodyAppendable, config); bodyAppendable.closeScope(); final TreeAppendable importAppendable = this.createAppendable(type, importManager, config); this.generateFileHeader(type, importAppendable, config); String _packageName = type.getPackageName(); boolean _tripleNotEquals = (_packageName != null); if (_tripleNotEquals) { importAppendable.append("package ").append(type.getPackageName()).append(";"); importAppendable.newLine().newLine(); } List<String> _imports = importManager.getImports(); for (final String i : _imports) { importAppendable.append("import ").append(i).append(";").newLine(); } boolean _isEmpty = importManager.getImports().isEmpty(); boolean _not = (!_isEmpty); if (_not) { importAppendable.newLine(); } importAppendable.append(bodyAppendable); return importAppendable; }