Java源码示例:org.eclipse.xtext.xtype.XImportSection

示例1
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportSection(XImportSection newImportSection)
{
  if (newImportSection != importSection)
  {
    NotificationChain msgs = null;
    if (importSection != null)
      msgs = ((InternalEObject)importSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - PureXbasePackage.MODEL__IMPORT_SECTION, null, msgs);
    if (newImportSection != null)
      msgs = ((InternalEObject)newImportSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - PureXbasePackage.MODEL__IMPORT_SECTION, null, msgs);
    msgs = basicSetImportSection(newImportSection, msgs);
    if (msgs != null) msgs.dispatch();
  }
  else if (eNotificationRequired())
    eNotify(new ENotificationImpl(this, Notification.SET, PureXbasePackage.MODEL__IMPORT_SECTION, newImportSection, newImportSection));
}
 
示例2
protected void checkConflicts(XImportSection importSection, final Map<String, List<XImportDeclaration>> imports,
		final Map<String, JvmType> importedNames) {
	for (JvmDeclaredType declaredType : importsConfiguration.getLocallyDefinedTypes((XtextResource)importSection.eResource())) {
		if(importedNames.containsKey(declaredType.getSimpleName())){
			JvmType importedType = importedNames.get(declaredType.getSimpleName());
			if (importedType != declaredType  && importedType.eResource() != importSection.eResource()) {
				List<XImportDeclaration> list = imports.get(importedType.getIdentifier());
				if (list != null) {
					for (XImportDeclaration importDeclaration: list ) {
						error("The import '" 
								+ importedType.getIdentifier() 
								+ "' conflicts with a type defined in the same file", 
								importDeclaration, null, IssueCodes.IMPORT_CONFLICT);
					}
				}
			}
		}
	}
}
 
示例3
public RewritableImportSection(XtextResource resource, IImportsConfiguration importsConfiguration, XImportSection originalImportSection,
		String lineSeparator, ImportSectionRegionUtil regionUtil, IValueConverter<String> nameConverter) {
	this.importsConfiguration = importsConfiguration;
	this.resource = resource;
	this.lineSeparator = lineSeparator;
	this.regionUtil = regionUtil;
	this.nameValueConverter = nameConverter;
	this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource);
	this.importRegion = regionUtil.computeRegion(resource);
	if (originalImportSection != null) {
		for (XImportDeclaration originalImportDeclaration : originalImportSection.getImportDeclarations()) {
			this.originalImportDeclarations.add(originalImportDeclaration);
			JvmDeclaredType importedType = originalImportDeclaration.getImportedType();
			if (originalImportDeclaration.isStatic()) {
				String memberName = originalImportDeclaration.getMemberName();
				if (originalImportDeclaration.isExtension()) {
					Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports);
				} else {
					Maps2.putIntoSetMap(importedType, memberName, staticImports);
				}
			} else if (importedType != null) {
				Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports);
			}
		}
	}
}
 
示例4
public void update() {
	XImportSection importSection = importsConfiguration.getImportSection(resource);
	if (importSection == null && importsConfiguration instanceof IMutableImportsConfiguration) {
		importSection = XtypeFactory.eINSTANCE.createXImportSection();

		IMutableImportsConfiguration mutableImportsConfiguration = (IMutableImportsConfiguration) importsConfiguration;
		mutableImportsConfiguration.setImportSection(resource, importSection);
	}
	if (importSection == null) {
		return;
	}
	removeObsoleteStaticImports();

	List<XImportDeclaration> allImportDeclarations = newArrayList();
	allImportDeclarations.addAll(originalImportDeclarations);
	allImportDeclarations.addAll(addedImportDeclarations);
	allImportDeclarations.removeAll(removedImportDeclarations);

	List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
	importDeclarations.clear();
	importDeclarations.addAll(allImportDeclarations);
}
 
示例5
@Override
public void createTypeProposals(EReference reference, ContentAssistContext context,
		Predicate<? super ITypeDescriptor> filter, IIdeContentProposalAcceptor acceptor) {
	ITextRegion importSectionRegion = null;
	XImportSection importSection = null;
	if (!isImportDeclaration(reference, context)) {
		importSection = importsConfiguration.getImportSection(context.getResource());
		importSectionRegion = importSectionRegionUtil.computeRegion(context.getResource());
	}
	for (ITypeDescriptor typeDesc : getTypeDescriptors(context)) {
		if (!acceptor.canAcceptMoreProposals()) {
			return;
		}
		if (canPropose(typeDesc, context, filter)) {
			ContentAssistEntry entry = createProposal(reference, typeDesc, context, importSection,
					importSectionRegion);
			int priority = ((XbaseIdeContentProposalPriorities) proposalPriorities).getTypeRefPriority(typeDesc,
					entry);
			acceptor.accept(entry, priority);
		}
	}
}
 
示例6
protected ContentAssistEntry createProposal(EReference reference, ITypeDescriptor typeDesc,
		ContentAssistContext context, XImportSection importSection, ITextRegion importSectionRegion) {
	boolean importDecl = isImportDeclaration(reference, context);
	String qualifiedName = qualifiedNameConverter.toString(typeDesc.getQualifiedName());
	String proposal;
	if (importDecl) {
		proposal = qualifiedName;
	} else {
		proposal = typeDesc.getSimpleName();
	}
	return proposalCreator.createProposal(proposal, context, (ContentAssistEntry it) -> {
		it.setKind(ContentAssistEntry.KIND_REFERENCE);
		if (importDecl) {
			it.setLabel(typeDesc.getSimpleName());
			it.setDescription(proposal);
		} else {
			it.setDescription(qualifiedName);
			if (importSectionRegion != null
					&& isImportDeclarationRequired(typeDesc, qualifiedName, context, importSection)) {
				addImportDeclaration(it, importSectionRegion, typeDesc, qualifiedName, context);
			}
		}
	});
}
 
示例7
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportSection(XImportSection newImportSection)
{
  if (newImportSection != importSection)
  {
    NotificationChain msgs = null;
    if (importSection != null)
      msgs = ((InternalEObject)importSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION, null, msgs);
    if (newImportSection != null)
      msgs = ((InternalEObject)newImportSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION, null, msgs);
    msgs = basicSetImportSection(newImportSection, msgs);
    if (msgs != null) msgs.dispatch();
  }
  else if (eNotificationRequired())
    eNotify(new ENotificationImpl(this, Notification.SET, XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION, newImportSection, newImportSection));
}
 
示例8
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportSection(XImportSection newImportSection)
{
  if (newImportSection != importSection)
  {
    NotificationChain msgs = null;
    if (importSection != null)
      msgs = ((InternalEObject)importSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DomainmodelPackage.ENTITIES__IMPORT_SECTION, null, msgs);
    if (newImportSection != null)
      msgs = ((InternalEObject)newImportSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DomainmodelPackage.ENTITIES__IMPORT_SECTION, null, msgs);
    msgs = basicSetImportSection(newImportSection, msgs);
    if (msgs != null) msgs.dispatch();
  }
  else if (eNotificationRequired())
    eNotify(new ENotificationImpl(this, Notification.SET, DomainmodelPackage.ENTITIES__IMPORT_SECTION, newImportSection, newImportSection));
}
 
示例9
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case DomainmodelPackage.ENTITIES__IMPORT_SECTION:
      setImportSection((XImportSection)newValue);
      return;
    case DomainmodelPackage.ENTITIES__ELEMENTS:
      getElements().clear();
      getElements().addAll((Collection<? extends AbstractElement>)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
 
示例10
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportSection(XImportSection newImportSection)
{
  if (newImportSection != importSection)
  {
    NotificationChain msgs = null;
    if (importSection != null)
      msgs = ((InternalEObject)importSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DomainmodelPackage.DOMAIN_MODEL__IMPORT_SECTION, null, msgs);
    if (newImportSection != null)
      msgs = ((InternalEObject)newImportSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DomainmodelPackage.DOMAIN_MODEL__IMPORT_SECTION, null, msgs);
    msgs = basicSetImportSection(newImportSection, msgs);
    if (msgs != null) msgs.dispatch();
  }
  else if (eNotificationRequired())
    eNotify(new ENotificationImpl(this, Notification.SET, DomainmodelPackage.DOMAIN_MODEL__IMPORT_SECTION, newImportSection, newImportSection));
}
 
示例11
protected void parseImportSection(XImportSection importSection, IAcceptor<String> visiblePackages,
		IAcceptor<String> importedTypes) {
	for (XImportDeclaration importDeclaration : importSection.getImportDeclarations()) {
		if (!importDeclaration.isStatic()) {
			if (importDeclaration.getImportedNamespace() != null) {
				String importedAsString = importDeclaration.getImportedNamespace();
				if (importDeclaration.isWildcard()) {
					importedAsString = importedAsString.substring(0, importedAsString.length() - 2);
					visiblePackages.accept(importedAsString);
				} else {
					importedTypes.accept(importedAsString);
				}
			} else {
				importedTypes.accept(importDeclaration.getImportedTypeName());
			}
		}
	}
}
 
示例12
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setImportSection(XImportSection newImportSection)
{
	if (newImportSection != importSection)
	{
		NotificationChain msgs = null;
		if (importSection != null)
			msgs = ((InternalEObject)importSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XtendPackage.XTEND_FILE__IMPORT_SECTION, null, msgs);
		if (newImportSection != null)
			msgs = ((InternalEObject)newImportSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XtendPackage.XTEND_FILE__IMPORT_SECTION, null, msgs);
		msgs = basicSetImportSection(newImportSection, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XtendPackage.XTEND_FILE__IMPORT_SECTION, newImportSection, newImportSection));
}
 
示例13
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XtendPackage.XTEND_FILE__IMPORT_SECTION:
			setImportSection((XImportSection)newValue);
			return;
		case XtendPackage.XTEND_FILE__XTEND_TYPES:
			getXtendTypes().clear();
			getXtendTypes().addAll((Collection<? extends XtendTypeDeclaration>)newValue);
			return;
		case XtendPackage.XTEND_FILE__PACKAGE:
			setPackage((String)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
示例14
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case XtendPackage.XTEND_FILE__IMPORT_SECTION:
			setImportSection((XImportSection)null);
			return;
		case XtendPackage.XTEND_FILE__XTEND_TYPES:
			getXtendTypes().clear();
			return;
		case XtendPackage.XTEND_FILE__PACKAGE:
			setPackage(PACKAGE_EDEFAULT);
			return;
	}
	super.eUnset(featureID);
}
 
示例15
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setImports(XImportSection newImports)
{
	if (newImports != imports)
	{
		NotificationChain msgs = null;
		if (imports != null)
			msgs = ((InternalEObject)imports).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CheckPackage.CHECK_CATALOG__IMPORTS, null, msgs);
		if (newImports != null)
			msgs = ((InternalEObject)newImports).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CheckPackage.CHECK_CATALOG__IMPORTS, null, msgs);
		msgs = basicSetImports(newImports, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, CheckPackage.CHECK_CATALOG__IMPORTS, newImports, newImports));
}
 
示例16
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetImportSection(XImportSection newImportSection, NotificationChain msgs)
{
  XImportSection oldImportSection = importSection;
  importSection = newImportSection;
  if (eNotificationRequired())
  {
    ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, PureXbasePackage.MODEL__IMPORT_SECTION, oldImportSection, newImportSection);
    if (msgs == null) msgs = notification; else msgs.add(notification);
  }
  return msgs;
}
 
示例17
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case PureXbasePackage.MODEL__IMPORT_SECTION:
      setImportSection((XImportSection)newValue);
      return;
    case PureXbasePackage.MODEL__BLOCK:
      setBlock((XBlockExpression)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
 
示例18
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
  switch (featureID)
  {
    case PureXbasePackage.MODEL__IMPORT_SECTION:
      setImportSection((XImportSection)null);
      return;
    case PureXbasePackage.MODEL__BLOCK:
      setBlock((XBlockExpression)null);
      return;
  }
  super.eUnset(featureID);
}
 
示例19
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
	if(EcoreUtil.getRootContainer(context) != context) 
		return Collections.emptyList();
	XImportSection importSection = importsConfiguration.getImportSection((XtextResource) context.eResource());
	if(importSection != null) {
		return getImportedNamespaceResolvers(importSection, ignoreCase);
	}
	return Collections.emptyList();
}
 
示例20
protected List<ImportNormalizer> getImportedNamespaceResolvers(XImportSection importSection, boolean ignoreCase) {
	List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
	List<ImportNormalizer> result = Lists.newArrayListWithExpectedSize(importDeclarations.size());
	for (XImportDeclaration imp: importDeclarations) {
		if (!imp.isStatic()) {
			String value = imp.getImportedNamespace();
			if(value == null)
				value = imp.getImportedTypeName();
			ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase);
			if (resolver != null)
				result.add(resolver);
		}
	}
	return result;
}
 
示例21
@Override
public IFeatureScopeSession newSession(Resource context) {
	List<JvmType> literalClasses = implicitlyImportedFeatures.getStaticImportClasses(context);
	List<JvmType> extensionClasses = implicitlyImportedFeatures.getExtensionClasses(context);
	IFeatureScopeSession result = rootSession.addTypesToStaticScope(literalClasses, extensionClasses);
	if (context.getContents().isEmpty() || !(context instanceof XtextResource))
		return result;
	final XImportSection importSection = importsConfig.getImportSection((XtextResource) context);
	if(importSection != null) {
		result = result.addImports(new ITypeImporter.Client() {

			@Override
			public void doAddImports(ITypeImporter importer) {
				List<XImportDeclaration> imports = importSection.getImportDeclarations();
				for(XImportDeclaration _import: imports) {
					if (_import.isStatic()) {
						if (_import.isWildcard()) {
							if (_import.isExtension()) {
								importer.importStaticExtension(_import.getImportedType(), false);
							} else {
								importer.importStatic(_import.getImportedType());
							}
						} else {
							if (_import.isExtension()) {
								importer.importStaticExtension(_import.getImportedType(), _import.getMemberName(), false);
							} else {
								importer.importStatic(_import.getImportedType(), _import.getMemberName());
							}
						}
					}
				}
			}
			
		});
	}
	return result;
}
 
示例22
public ITextRegion computeRegion(XtextResource resource) {
	XImportSection xImportSection = config.getImportSection(resource);
	// try to obtain the region from the text if it is not a synthetic region.
	if (xImportSection != null && xImportSection.eResource() != null) {
		INode node = NodeModelUtils.findActualNodeFor(xImportSection);
		if(node == null) 
			LOG.error("Cannot detect node for original import section");
		else 
			return node.getTextRegion();
	} 
	return new TextRegion(config.getImportSectionOffset(resource), 0);
}
 
示例23
@Override
public XImportSection getImportSection(XtextResource resource) {
	EList<EObject> contents = resource.getContents();
	if (!contents.isEmpty())
	{
		for (Iterator<EObject> i = contents.get(0).eAllContents(); i.hasNext();) {
			EObject next = i.next();
			if (next instanceof XImportSection)
				return (XImportSection) next;
		}
	}
	return null;
}
 
示例24
protected void _format(final XImportSection section, @Extension final IFormattableDocument format) {
  EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
  for (final XImportDeclaration imp : _importDeclarations) {
    {
      format.<XImportDeclaration>format(imp);
      XImportDeclaration _last = IterableExtensions.<XImportDeclaration>last(section.getImportDeclarations());
      boolean _notEquals = (!Objects.equal(imp, _last));
      if (_notEquals) {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesBetweenImports);
      } else {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesAfterImports);
      }
    }
  }
}
 
示例25
public void format(final Object ref, final IFormattableDocument document) {
  if (ref instanceof JvmTypeParameter) {
    _format((JvmTypeParameter)ref, document);
    return;
  } else if (ref instanceof XtextResource) {
    _format((XtextResource)ref, document);
    return;
  } else if (ref instanceof XFunctionTypeRef) {
    _format((XFunctionTypeRef)ref, document);
    return;
  } else if (ref instanceof JvmParameterizedTypeReference) {
    _format((JvmParameterizedTypeReference)ref, document);
    return;
  } else if (ref instanceof JvmWildcardTypeReference) {
    _format((JvmWildcardTypeReference)ref, document);
    return;
  } else if (ref instanceof XImportDeclaration) {
    _format((XImportDeclaration)ref, document);
    return;
  } else if (ref instanceof XImportSection) {
    _format((XImportSection)ref, document);
    return;
  } else if (ref instanceof EObject) {
    _format((EObject)ref, document);
    return;
  } else if (ref == null) {
    _format((Void)null, document);
    return;
  } else if (ref != null) {
    _format(ref, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(ref, document).toString());
  }
}
 
示例26
protected boolean isImportDeclarationRequired(ITypeDescriptor typeDesc, String qualifiedName,
		ContentAssistContext context, XImportSection importSection) {
	return !(typeDesc.getName().startsWith("java.lang") && typeDesc.getName().lastIndexOf('.') == "java.lang".length())
			&& (importSection == null || !IterableExtensions.exists(importSection.getImportDeclarations(),
					(XImportDeclaration it) -> {
						String importFqn = null;
						if (it.getImportedType() != null) {
							importFqn = it.getImportedType().getQualifiedName();
						}
						return Objects.equal(importFqn, qualifiedName);
					}));
}
 
示例27
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetImportSection(XImportSection newImportSection, NotificationChain msgs)
{
  XImportSection oldImportSection = importSection;
  importSection = newImportSection;
  if (eNotificationRequired())
  {
    ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION, oldImportSection, newImportSection);
    if (msgs == null) msgs = notification; else msgs.add(notification);
  }
  return msgs;
}
 
示例28
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION:
      setImportSection((XImportSection)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
 
示例29
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
  switch (featureID)
  {
    case XImportSectionTestLangPackage.IMPORT_SECTION_TEST_LANGUAGE_ROOT__IMPORT_SECTION:
      setImportSection((XImportSection)null);
      return;
  }
  super.eUnset(featureID);
}
 
示例30
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetImportSection(XImportSection newImportSection, NotificationChain msgs)
{
  XImportSection oldImportSection = importSection;
  importSection = newImportSection;
  if (eNotificationRequired())
  {
    ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DomainmodelPackage.ENTITIES__IMPORT_SECTION, oldImportSection, newImportSection);
    if (msgs == null) msgs = notification; else msgs.add(notification);
  }
  return msgs;
}