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

The following examples show how to use org.eclipse.xtext.common.types.JvmMember#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: NonOverridableTypesProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: AbstractMultiModeOutlineTreeProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private String createQualifier(JvmMember jvmMember) {
	String qualifier = null;
	if (jvmMember instanceof JvmFeature) {
		JvmDeclaredType declaringType = jvmMember.getDeclaringType();
		qualifier = getPackageFreeNameForType(declaringType);
	} else if (jvmMember instanceof JvmDeclaredType) {
		if (jvmMember.eContainer() instanceof JvmDeclaredType) {
			qualifier = getPackageFreeNameForType((JvmDeclaredType) jvmMember.eContainer());
		} else {
			JvmDeclaredType jvmDeclaredType = (JvmDeclaredType) jvmMember;
			if (StringUtils.isEmpty(jvmDeclaredType.getPackageName())) {
				qualifier = "(default package)";
			} else {
				qualifier = jvmDeclaredType.getPackageName();
			}
		}
	}
	return qualifier;
}
 
Example 3
Source File: XtendGenerator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isNestedTypeOf(JvmType child, JvmDeclaredType parent) {
	if (child instanceof JvmMember) {
		JvmMember member = (JvmMember) child;
		return member.getDeclaringType() == parent;
	}
	return false;
}
 
Example 5
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private boolean removeStaticImport(Map<String, List<XImportDeclaration>> staticImports, JvmMember member) {
	JvmDeclaredType declaringType = member.getDeclaringType();
	String identifier = declaringType.getIdentifier();
	
	List<XImportDeclaration> list = staticImports.get(identifier);
	if (list == null) {
		return false;
	}
	if (list.size() == 1) {
		staticImports.remove(identifier);
		return true;
	}
	int indexToRemove = -1;
	for (int i = 0; i < list.size(); i++) {
		XImportDeclaration staticImportDeclaration = list.get(i);
		if (staticImportDeclaration.isWildcard()) {
			if (indexToRemove == -1) {
				indexToRemove = i;
			}
			continue;
		}
		if (Objects.equal(member.getSimpleName(), staticImportDeclaration.getMemberName())) {
			indexToRemove = i;
			break;
		}
	}
	if (indexToRemove == -1) {
		indexToRemove = 0;
	}
	list.remove(indexToRemove);
	return true;
}
 
Example 6
Source File: ContextualVisibilityHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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 7
Source File: TypeUsage.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getPackageName(JvmMember context) {
	if(context.getDeclaringType() != null)
		return getPackageName(context.getDeclaringType());
	if(context instanceof JvmDeclaredType) 
		return ((JvmDeclaredType)context).getPackageName();
	else  
		return null;
}
 
Example 8
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isConflicted(JvmDeclaredType type, String memberName, Set<JvmMember> importedMembers) {
	for (JvmMember importedMember : importedMembers) {
		if (importedMember.getDeclaringType() != type && memberName.equals(importedMember.getSimpleName())) {
			return true;
		}
	}
	return false;
}
 
Example 9
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean contains(JvmDeclaredType type, String memberName, Set<JvmMember> importedMembers) {
	for (JvmMember staticImport : importedMembers) {
		if (staticImport.getDeclaringType() == type && memberName.equals(staticImport.getSimpleName())) {
			return true;
		}
	}
	return false;
}
 
Example 10
Source File: JavaElementFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
public IJavaElement getDeclaringTypeElement(JvmMember object) {
	if (object.getDeclaringType() != null) {
		IJavaElement typeElement = doSwitch(object.getDeclaringType());
		return typeElement;
	} 
	return null;
}
 
Example 11
Source File: XtendHoverSignatureProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String getDeclaratorName(JvmMember member) {
	JvmDeclaredType declaringType = member.getDeclaringType();
	if (declaringType.isLocal()) {
		String rawName = Iterables.getLast(declaringType.getSuperTypes()).getType().getSimpleName();
		return "new " + rawName + "(){}";
	} else {
		return super.getDeclaratorName(member);
	}
}
 
Example 12
Source File: XtendGenerator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 13
Source File: FeatureScopeSessionWithContext.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@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 14
Source File: TypeUsageCollector.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void acceptStaticImport(JvmMember member) {
	JvmDeclaredType declarator = member.getDeclaringType();
	if (!needsStaticImport(declarator) || implicitStaticImports.contains(declarator))
		return;
	typeUsages.addStaticImport(member);
}
 
Example 15
Source File: TypeUsageCollector.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void acceptStaticExtensionImport(JvmMember member) {
	JvmDeclaredType declarator = member.getDeclaringType();
	if (!needsStaticImport(declarator) || implicitExtensionImports.contains(declarator))
		return;
	typeUsages.addExtensionImport(member);
}
 
Example 16
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isDeclaredWithinInterface(final JvmMember it) {
  return ((it.getDeclaringType() instanceof JvmGenericType) && ((JvmGenericType) it.getDeclaringType()).isInterface());
}