org.eclipse.xtext.xtype.XtypePackage Java Examples

The following examples show how to use org.eclipse.xtext.xtype.XtypePackage. 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: XImportDeclarationImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType)
{
	switch (featureID)
	{
		case XtypePackage.XIMPORT_DECLARATION__WILDCARD:
			return isWildcard();
		case XtypePackage.XIMPORT_DECLARATION__EXTENSION:
			return isExtension();
		case XtypePackage.XIMPORT_DECLARATION__STATIC:
			return isStatic();
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_TYPE:
			if (resolve) return getImportedType();
			return basicGetImportedType();
		case XtypePackage.XIMPORT_DECLARATION__MEMBER_NAME:
			return getMemberName();
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_NAMESPACE:
			return getImportedNamespace();
	}
	return super.eGet(featureID, resolve, coreType);
}
 
Example #2
Source File: XtendUIValidationTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testForbiddenConstructorCallInnerClass() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.core.tests.restricted.RestrictedClass$InnerRestrictedClass");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("InnerRestrictedClass x = new InnerRestrictedClass");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
    this.helper.assertError(xtendFile.getImportSection().getImportDeclarations().get(0), XtypePackage.Literals.XIMPORT_DECLARATION, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
    XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
    final XtendField field = ((XtendField) _head);
    this.helper.assertError(field.getType(), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
    this.helper.assertError(field.getInitialValue(), XbasePackage.Literals.XCONSTRUCTOR_CALL, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #3
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void checkUnnecessaryImportForEnumLiteral_3() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.annotation.RetentionPolicy.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@java.lang.annotation.Retention(CLASS)");
    _builder.newLine();
    _builder.append("annotation A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "The import \'java.lang.annotation.RetentionPolicy\' is never used.");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #4
Source File: DefaultImportsConfiguration.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getLegacyImportSyntax(XImportDeclaration importDeclaration) {
	List<INode> list = NodeModelUtils.findNodesForFeature(importDeclaration, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE);
	if (list.isEmpty()) {
		return null;
	}
	INode singleNode = list.get(0);
	if (singleNode.getText().indexOf('$') < 0) {
		return null;
	}
	StringBuilder sb = new StringBuilder();
	for(ILeafNode node: singleNode.getLeafNodes()) {
		if (!node.isHidden()) {
			sb.append(node.getText().replace("^", ""));
		}
	}
	return sb.toString();
}
 
Example #5
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void checkUnnecessaryImportForEnumLiteral_5() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.annotation.ElementType.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@java.lang.annotation.Retention(TYPE, METHOD)");
    _builder.newLine();
    _builder.append("annotation A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #6
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void checkUnnecessaryImportForEnumLiteral_8() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.annotation.ElementType.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@java.lang.annotation.Retention(value=#[TYPE, METHOD])");
    _builder.newLine();
    _builder.append("annotation A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: XFunctionTypeRefImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setReturnType(JvmTypeReference newReturnType)
{
	if (newReturnType != returnType)
	{
		NotificationChain msgs = null;
		if (returnType != null)
			msgs = ((InternalEObject)returnType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE, null, msgs);
		if (newReturnType != null)
			msgs = ((InternalEObject)newReturnType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE, null, msgs);
		msgs = basicSetReturnType(newReturnType, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE, newReturnType, newReturnType));
}
 
Example #8
Source File: XFunctionTypeRefImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XtypePackage.XFUNCTION_TYPE_REF__PARAM_TYPES:
			getParamTypes().clear();
			getParamTypes().addAll((Collection<? extends JvmTypeReference>)newValue);
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE:
			setReturnType((JvmTypeReference)newValue);
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__TYPE:
			setType((JvmType)newValue);
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__INSTANCE_CONTEXT:
			setInstanceContext((Boolean)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #9
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void checkUnnecessaryImportForEnumLiteral_4() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.annotation.ElementType.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@java.lang.annotation.Target(TYPE, METHOD)");
    _builder.newLine();
    _builder.append("annotation A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "The import \'java.lang.annotation.ElementType\' is never used.");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #10
Source File: XImportDeclarationImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public boolean eIsSet(int featureID)
{
	switch (featureID)
	{
		case XtypePackage.XIMPORT_DECLARATION__WILDCARD:
			return wildcard != WILDCARD_EDEFAULT;
		case XtypePackage.XIMPORT_DECLARATION__EXTENSION:
			return extension != EXTENSION_EDEFAULT;
		case XtypePackage.XIMPORT_DECLARATION__STATIC:
			return static_ != STATIC_EDEFAULT;
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_TYPE:
			return importedType != null;
		case XtypePackage.XIMPORT_DECLARATION__MEMBER_NAME:
			return MEMBER_NAME_EDEFAULT == null ? memberName != null : !MEMBER_NAME_EDEFAULT.equals(memberName);
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_NAMESPACE:
			return IMPORTED_NAMESPACE_EDEFAULT == null ? importedNamespace != null : !IMPORTED_NAMESPACE_EDEFAULT.equals(importedNamespace);
	}
	return super.eIsSet(featureID);
}
 
Example #11
Source File: ValidationTests.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testImportUnused_1() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.List");
    _builder.newLine();
    _builder.append("entity X {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("sb: java.util.List<String>");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertWarning(this._parseHelper.parse(_builder), XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #12
Source File: XFunctionTypeRefImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public boolean eIsSet(int featureID)
{
	switch (featureID)
	{
		case XtypePackage.XFUNCTION_TYPE_REF__PARAM_TYPES:
			return paramTypes != null && !paramTypes.isEmpty();
		case XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE:
			return returnType != null;
		case XtypePackage.XFUNCTION_TYPE_REF__TYPE:
			return type != null;
		case XtypePackage.XFUNCTION_TYPE_REF__INSTANCE_CONTEXT:
			return instanceContext != INSTANCE_CONTEXT_EDEFAULT;
	}
	return super.eIsSet(featureID);
}
 
Example #13
Source File: XFunctionTypeRefImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case XtypePackage.XFUNCTION_TYPE_REF__PARAM_TYPES:
			getParamTypes().clear();
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__RETURN_TYPE:
			setReturnType((JvmTypeReference)null);
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__TYPE:
			setType((JvmType)null);
			return;
		case XtypePackage.XFUNCTION_TYPE_REF__INSTANCE_CONTEXT:
			setInstanceContext(INSTANCE_CONTEXT_EDEFAULT);
			return;
	}
	super.eUnset(featureID);
}
 
Example #14
Source File: XtendUIValidationTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testForbiddenImport() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.core.tests.restricted.RestrictedClass");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
    this.helper.assertError(xtendFile.getImportSection().getImportDeclarations().get(0), XtypePackage.Literals.XIMPORT_DECLARATION, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #15
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithExtensionAccess_0() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.valueOf");
    _builder.newLine();
    _builder.append("import static java.lang.String.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String.valueOf");
    this.assertFeatureCallError(file, XbasePackage.Literals.XMEMBER_FEATURE_CALL);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #16
Source File: ExtraLanguageValidatorSupport.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected List<EPackage> getEPackages() {
	final List<EPackage> result = new ArrayList<>(super.getEPackages());
	result.add(io.sarl.lang.sarl.SarlPackage.eINSTANCE);
	result.add(XtendPackage.eINSTANCE);
	result.add(XbasePackage.eINSTANCE);
	result.add(TypesPackage.eINSTANCE);
	result.add(XtypePackage.eINSTANCE);
	result.add(XAnnotationsPackage.eINSTANCE);
	return result;
}
 
Example #17
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void unresolvedImport_2() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.math.BigDecimal.print;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {}");
    _builder.newLine();
    this._validationTestHelper.assertError(this.file(_builder.toString()), XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNRESOLVED, "java.math.BigDecimal.print");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkImportWithExtensionAccess_0() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.valueOf");
    _builder.newLine();
    _builder.append("import static java.lang.Integer.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String.valueOf");
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.Integer.valueOf");
    this.assertFeatureCallError(file, XbasePackage.Literals.XMEMBER_FEATURE_CALL);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #19
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithStaticAccess_5() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("valueOf(1)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #20
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithStaticAccess_2() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.append("import static java.lang.String.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("valueOf(1)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String.valueOf");
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #21
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithExtensionAccess_5() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.append("import static extension java.lang.String.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "\'java.lang.String\'");
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "\'java.lang.String.valueOf\'");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #22
Source File: XImportSectionTestLangPackageImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
 *
 * <p>This method is used to initialize {@link XImportSectionTestLangPackage#eINSTANCE} when that field is accessed.
 * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @see #eNS_URI
 * @see #createPackageContents()
 * @see #initializePackageContents()
 * @generated
 */
public static XImportSectionTestLangPackage init()
{
  if (isInited) return (XImportSectionTestLangPackage)EPackage.Registry.INSTANCE.getEPackage(XImportSectionTestLangPackage.eNS_URI);

  // Obtain or create and register package
  Object registeredXImportSectionTestLangPackage = EPackage.Registry.INSTANCE.get(eNS_URI);
  XImportSectionTestLangPackageImpl theXImportSectionTestLangPackage = registeredXImportSectionTestLangPackage instanceof XImportSectionTestLangPackageImpl ? (XImportSectionTestLangPackageImpl)registeredXImportSectionTestLangPackage : new XImportSectionTestLangPackageImpl();

  isInited = true;

  // Initialize simple dependencies
  XtypePackage.eINSTANCE.eClass();
  TypesPackage.eINSTANCE.eClass();

  // Create package meta-data objects
  theXImportSectionTestLangPackage.createPackageContents();

  // Initialize created meta-data
  theXImportSectionTestLangPackage.initializePackageContents();

  // Mark meta-data to indicate it can't be changed
  theXImportSectionTestLangPackage.freeze();

  // Update the registry and return the package
  EPackage.Registry.INSTANCE.put(XImportSectionTestLangPackage.eNS_URI, theXImportSectionTestLangPackage);
  return theXImportSectionTestLangPackage;
}
 
Example #23
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkImportWithExtensionAccess_1() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.valueOf");
    _builder.newLine();
    _builder.append("import static java.lang.Integer.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String.valueOf");
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.Integer");
    this.assertFeatureCallError(file, XbasePackage.Literals.XMEMBER_FEATURE_CALL);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #24
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithStaticAccess_9() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.append("import static extension java.lang.String.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("valueOf(1)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "\'java.lang.String\'");
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "\'java.lang.String.valueOf\'");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #25
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkImportWithExtensionAccess_5() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static java.lang.String.*");
    _builder.newLine();
    _builder.append("import static extension java.lang.Integer.valueOf");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String");
    this._validationTestHelper.assertNoWarnings(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.Integer");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source File: XImportDeclarationImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case XtypePackage.XIMPORT_DECLARATION__WILDCARD:
			setWildcard(WILDCARD_EDEFAULT);
			return;
		case XtypePackage.XIMPORT_DECLARATION__EXTENSION:
			setExtension(EXTENSION_EDEFAULT);
			return;
		case XtypePackage.XIMPORT_DECLARATION__STATIC:
			setStatic(STATIC_EDEFAULT);
			return;
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_TYPE:
			setImportedType((JvmDeclaredType)null);
			return;
		case XtypePackage.XIMPORT_DECLARATION__MEMBER_NAME:
			setMemberName(MEMBER_NAME_EDEFAULT);
			return;
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_NAMESPACE:
			setImportedNamespace(IMPORTED_NAMESPACE_EDEFAULT);
			return;
	}
	super.eUnset(featureID);
}
 
Example #27
Source File: XImportDeclarationImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XtypePackage.XIMPORT_DECLARATION__WILDCARD:
			setWildcard((Boolean)newValue);
			return;
		case XtypePackage.XIMPORT_DECLARATION__EXTENSION:
			setExtension((Boolean)newValue);
			return;
		case XtypePackage.XIMPORT_DECLARATION__STATIC:
			setStatic((Boolean)newValue);
			return;
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_TYPE:
			setImportedType((JvmDeclaredType)newValue);
			return;
		case XtypePackage.XIMPORT_DECLARATION__MEMBER_NAME:
			setMemberName((String)newValue);
			return;
		case XtypePackage.XIMPORT_DECLARATION__IMPORTED_NAMESPACE:
			setImportedNamespace((String)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #28
Source File: ValidationTests.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testImportCollision() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.List");
    _builder.newLine();
    _builder.append("import java.awt.List");
    _builder.newLine();
    _builder.append("entity X {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("sb: List");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op foo() : List {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("sb");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertError(this._parseHelper.parse(_builder), XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_COLLISION);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #29
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkDuplicateImportWithExtensionAccess_7() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static extension java.lang.String.*");
    _builder.newLine();
    _builder.append("import static extension java.lang.String.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1.valueOf");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    this._validationTestHelper.assertWarning(file, XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED, "java.lang.String");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #30
Source File: XImportDeclarationImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportedNamespace(String newImportedNamespace)
{
	String oldImportedNamespace = importedNamespace;
	importedNamespace = newImportedNamespace;
	if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XtypePackage.XIMPORT_DECLARATION__IMPORTED_NAMESPACE, oldImportedNamespace, importedNamespace));
}