Java Code Examples for org.eclipse.xtext.common.types.JvmVisibility#PUBLIC

The following examples show how to use org.eclipse.xtext.common.types.JvmVisibility#PUBLIC . 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: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isMorePrivateThan(JvmVisibility o1, JvmVisibility o2) {
	if (o1 == o2) {
		return false;
	} else {
		switch (o1) {
			case DEFAULT:
				return o2 != JvmVisibility.PRIVATE;
			case PRIVATE:
				return true;
			case PROTECTED:
				return o2 == JvmVisibility.PUBLIC;
			case PUBLIC:
				return false;
			default:
				throw new IllegalArgumentException("Unknown JvmVisibility " + o1);
		}
	}
}
 
Example 2
Source File: JvmMemberDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void setVisibility(final Visibility visibility) {
  this.checkMutable();
  T _delegate = this.getDelegate();
  JvmVisibility _switchResult = null;
  if (visibility != null) {
    switch (visibility) {
      case DEFAULT:
        _switchResult = JvmVisibility.DEFAULT;
        break;
      case PUBLIC:
        _switchResult = JvmVisibility.PUBLIC;
        break;
      case PRIVATE:
        _switchResult = JvmVisibility.PRIVATE;
        break;
      case PROTECTED:
        _switchResult = JvmVisibility.PROTECTED;
        break;
      default:
        break;
    }
  }
  _delegate.setVisibility(_switchResult);
}
 
Example 3
Source File: OverrideTester.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isMorePrivateThan(JvmVisibility o1, JvmVisibility o2) {
	if (o1 == o2) {
		return false;
	} else {
		switch (o1) {
			case DEFAULT:
				return o2 != JvmVisibility.PRIVATE;
			case PRIVATE:
				return true;
			case PROTECTED:
				return o2 == JvmVisibility.PUBLIC;
			case PUBLIC:
				return false;
			default:
				throw new IllegalArgumentException("Unknown JvmVisibility " + o1);
		}
	}
}
 
Example 4
Source File: XtendMemberImplCustom.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public JvmVisibility getDeclaredVisibility() {
	for(String modifier: getModifiers()) {
		if(equal(modifier, "public")) 
			return JvmVisibility.PUBLIC;
		if(equal(modifier, "package")) 
			return JvmVisibility.DEFAULT;
		if(equal(modifier, "protected")) 
			return JvmVisibility.PROTECTED;
		if(equal(modifier, "private")) 
			return JvmVisibility.PRIVATE;
	}
	return null;
}
 
Example 5
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of an interface when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getInterfaceDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlAgent) {
		return JvmVisibility.PROTECTED;
	}
	return JvmVisibility.PUBLIC;
}
 
Example 6
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of an enumeration when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getEnumerationDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlAgent) {
		return JvmVisibility.PROTECTED;
	}
	return JvmVisibility.PUBLIC;
}
 
Example 7
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of a class when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getClassDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlAgent) {
		return JvmVisibility.PROTECTED;
	}
	return JvmVisibility.PUBLIC;
}
 
Example 8
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of an annotation type when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getAnnotationTypeDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlAgent) {
		return JvmVisibility.PROTECTED;
	}
	return JvmVisibility.PUBLIC;
}
 
Example 9
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of an action when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getActionDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlAgent) {
		return JvmVisibility.PROTECTED;
	}
	return JvmVisibility.PUBLIC;
}
 
Example 10
Source File: IDefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the default visibility of a field when inside the given container.
 *
 * @param container the container.
 * @return the default visibility.
 * @since 0.6
 */
static JvmVisibility getFieldDefaultVisibilityIn(EObject container) {
	if (container instanceof SarlEvent
			|| container instanceof XtendInterface
			|| container instanceof XtendAnnotationType) {
		return JvmVisibility.PUBLIC;
	}
	return JvmVisibility.PRIVATE;
}
 
Example 11
Source File: DefaultVisibilityProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("checkstyle:npathcomplexity")
public JvmVisibility getDefaultJvmVisibility(EObject container, EClass element) {
	EObject realObject = container;
	if (realObject instanceof JvmIdentifiableElement) {
		final EObject obj = this.associations.getPrimarySourceElement(realObject);
		if (obj != null) {
			realObject = obj;
		}
	}
	if (realObject != null) {
		if (XtendPackage.eINSTANCE.getXtendFunction().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getActionDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendField().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getFieldDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendClass().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getClassDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendInterface().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getInterfaceDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendEnum().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getEnumerationDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendAnnotationType().isSuperTypeOf(element)) {
			return IDefaultVisibilityProvider.getAnnotationTypeDefaultVisibilityIn(realObject);
		}
		if (XtendPackage.eINSTANCE.getXtendMember().isSuperTypeOf(element)) {
			return JvmVisibility.PUBLIC;
		}
	}
	return JvmVisibility.DEFAULT;
}
 
Example 12
Source File: XtendFieldImplCustom.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected JvmVisibility getDefaultVisibility() {
	if(getDeclaringType() instanceof XtendInterface || getDeclaringType() instanceof XtendAnnotationType)
		return JvmVisibility.PUBLIC;
	else 
		return JvmVisibility.PRIVATE;
}
 
Example 13
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isApi(XtendTypeDeclaration type) {
	if (type.isAnonymous())
		return false;
	boolean api = type.getVisibility() == JvmVisibility.PUBLIC;
	if (type.getDeclaringType() != null) {
		api = api || (type.getVisibility() == JvmVisibility.PROTECTED && ! type.getDeclaringType().isFinal()); 
		api = api && isApi(type.getDeclaringType());
	}
	return api;
}
 
Example 14
Source File: InferredJvmModelTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testDispatchFunction_05() throws Exception {
	XtendFile xtendFile = file("class Foo {" + 
			"  def private dispatch private_private  (Integer x) {} def private   dispatch private_private  (Double x) {}" +
			"  def private dispatch private_protected(Integer x) {} def protected dispatch private_protected(Double x) {}" +
			"  def private dispatch private_public   (Integer x) {} def public    dispatch private_public   (Double x) {}" +
			"  def private dispatch private_default  (Integer x) {} def           dispatch private_default  (Double x) {}" +
			"  def protected dispatch protected_private  (Integer x) {} def private   dispatch protected_private  (Double x) {}" +
			"  def protected dispatch protected_protected(Integer x) {} def protected dispatch protected_protected(Double x) {}" +
			"  def protected dispatch protected_public   (Integer x) {} def public    dispatch protected_public   (Double x) {}" +
			"  def protected dispatch protected_default  (Integer x) {} def           dispatch protected_default  (Double x) {}" +
			"  def public dispatch public_private  (Integer x) {} def private   dispatch public_private  (Double x) {}" +
			"  def public dispatch public_protected(Integer x) {} def protected dispatch public_protected(Double x) {}" +
			"  def public dispatch public_public   (Integer x) {} def public    dispatch public_public   (Double x) {}" +
			"  def public dispatch public_default  (Integer x) {} def           dispatch public_default  (Double x) {}" +
			"  def dispatch default_private  (Integer x) {} def private   dispatch default_private  (Double x) {}" +
			"  def dispatch default_protected(Integer x) {} def protected dispatch default_protected(Double x) {}" +
			"  def dispatch default_public   (Integer x) {} def public    dispatch default_public   (Double x) {}" +
			"  def dispatch default_default  (Integer x) {} def           dispatch default_default  (Double x) {}" +
			"}");
	JvmGenericType inferredType = getInferredType(xtendFile);
	for(JvmOperation op: inferredType.getDeclaredOperations()) {
		String[] split = op.getSimpleName().toUpperCase().split("_");
		JvmVisibility expectedVisibility = null;
		if(!op.getSimpleName().startsWith("_")) {
			if(equal(split[0], split[1]))
				expectedVisibility = "DEFAULT".equals(split[0]) ? JvmVisibility.PUBLIC : JvmVisibility.get(split[0]);
			else 	
				expectedVisibility = JvmVisibility.PUBLIC;
		}
		else if(equal(op.getParameters().get(0).getParameterType().getIdentifier(), "java.lang.Integer"))
			expectedVisibility = "DEFAULT".equals(split[1]) ? JvmVisibility.PROTECTED : JvmVisibility.get(split[1]);
		else
			expectedVisibility = "DEFAULT".equals(split[2]) ? JvmVisibility.PROTECTED : JvmVisibility.get(split[2]);
		assertEquals(op.getIdentifier(), expectedVisibility, op.getVisibility());
	}
}
 
Example 15
Source File: ExtractMethodUserInputPage.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void createAccessModifierSection(Composite result) {
	GridLayout layout;
	Label label = new Label(result, SWT.NONE);
	label.setText("Access modifier:");
	Composite group = new Composite(result, SWT.NONE);
	group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	layout = new GridLayout();
	layout.numColumns = 3;
	layout.marginWidth = 0;
	group.setLayout(layout);
	String[] labels = new String[] { "public", "protected", "private" };
	JvmVisibility[] data = new JvmVisibility[] { JvmVisibility.PUBLIC, JvmVisibility.PROTECTED,
			JvmVisibility.PRIVATE };
	JvmVisibility visibility = refactoring.getVisibility();
	for (int i = 0; i < labels.length; i++) {
		Button radio = new Button(group, SWT.RADIO);
		radio.setText(labels[i]);
		radio.setData(data[i]);
		if (data[i].equals(visibility))
			radio.setSelection(true);
		radio.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				final JvmVisibility selectedModifier = (JvmVisibility) event.widget.getData();
				visibilityModified(selectedModifier);
				updatePreview();
			}
		});
	}
}
 
Example 16
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 17
Source File: XtendMemberImplCustom.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected JvmVisibility getDefaultVisibility() {
	return JvmVisibility.PUBLIC;
}
 
Example 18
Source File: SARLValidator.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("synthetic-access")
protected boolean isPublicByDefault(XtendMember member) {
	final JvmVisibility defaultVisibility = SARLValidator.this.defaultVisibilityProvider.getDefaultJvmVisibility(member);
	return defaultVisibility == JvmVisibility.PUBLIC;
}
 
Example 19
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isApi(XtendMember member) {
	if (!isApi(member.getDeclaringType())) return false;
	return member.getVisibility() == JvmVisibility.PUBLIC 
			|| member.getVisibility() == JvmVisibility.PROTECTED && !member.getDeclaringType().isFinal();
}
 
Example 20
Source File: PublicVisibilityHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isVisible(/* @NonNull */ JvmMember member) {
	return member.getVisibility() == JvmVisibility.PUBLIC;
}