org.eclipse.xtext.xtype.XImportDeclaration Java Examples
The following examples show how to use
org.eclipse.xtext.xtype.XImportDeclaration.
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: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean addStaticImport(JvmDeclaredType type, String memberName) { if (hasStaticImport(staticImports, type, memberName)) { return false; } Maps2.putIntoSetMap(type, memberName, staticImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); importDeclaration.setStatic(true); if (memberName == null) { importDeclaration.setWildcard(true); } else { importDeclaration.setMemberName(memberName); } addedImportDeclarations.add(importDeclaration); return true; }
Example #2
Source File: JavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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()); } } } }
Example #3
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private boolean hasStaticImport(String typeName, String memberName, boolean extension) { for (String string : implicitlyImportedPackages) { if (typeName.startsWith(string)) { return typeName.substring(string.length()).lastIndexOf('.') == 0; } } Map<JvmDeclaredType, Set<String>> imports = staticImports; if (extension) { imports = staticExtensionImports; } for (JvmDeclaredType type : imports.keySet()) { if (typeName.equals(type.getIdentifier())) { Set<String> members = imports.get(type); return members != null && ((members.contains(memberName) || members.contains(null))); } } for (XImportDeclaration importDeclr : addedImportDeclarations) { String identifier = importDeclr.getImportedTypeName(); if (importDeclr.isStatic() && typeName.equals(identifier)) { if (Objects.equal(importDeclr.getMemberName(), memberName) || importDeclr.isWildcard() || "*".equals(importDeclr.getMemberName())) { return true; } } } return false; }
Example #4
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean removeImport(JvmDeclaredType type) { List<XImportDeclaration> addedImportDeclarationsToRemove = findOriginalImports(type, null, addedImportDeclarations, false, false); addedImportDeclarations.removeAll(addedImportDeclarationsToRemove); List<XImportDeclaration> originalImportDeclarationsToRemove = findOriginalImports(type, null, originalImportDeclarations, false, false); removedImportDeclarations.addAll(originalImportDeclarationsToRemove); for (Map.Entry<String, List<JvmDeclaredType>> entry : plainImports.entrySet()) { List<JvmDeclaredType> values = entry.getValue(); if (values.size() == 1) { if (values.get(0) == type) { plainImports.remove(type.getSimpleName()); return true; } } Iterator<JvmDeclaredType> iterator = values.iterator(); while (iterator.hasNext()) { JvmDeclaredType value = iterator.next(); if (value == type) { iterator.remove(); return true; } } } return false; }
Example #5
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void appendImport(StringBuilder builder, XImportDeclaration newImportDeclaration) { builder.append("import "); if (newImportDeclaration.isStatic()) { builder.append("static "); if (newImportDeclaration.isExtension()) { builder.append("extension "); } } String qualifiedTypeName = newImportDeclaration.getImportedNamespace(); if (newImportDeclaration.getImportedType() != null) { qualifiedTypeName = serializeType(newImportDeclaration.getImportedType()); } String escapedTypeName = nameValueConverter.toString(qualifiedTypeName); builder.append(escapedTypeName); if (newImportDeclaration.isStatic()) { builder.append("."); if (newImportDeclaration.isWildcard()) { builder.append("*"); } else { builder.append(newImportDeclaration.getMemberName()); } } builder.append(lineSeparator); }
Example #6
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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); } } } } } }
Example #7
Source File: DefaultImportsConfiguration.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #8
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void checkDeprecated(XImportDeclaration decl) { XtendFile file = EcoreUtil2.getContainerOfType(decl, XtendFile.class); if (file != null) { for (XtendTypeDeclaration t : file.getXtendTypes()) { for (EObject e : jvmModelAssociations.getJvmElements(t)) { if (e instanceof JvmAnnotationTarget) { if (DeprecationUtil.isDeprecated((JvmAnnotationTarget) e)) { return; } } } if (hasAnnotation(t, Deprecated.class)) { return; } } } super.checkDeprecated(decl); }
Example #9
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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); }
Example #10
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean addStaticExtensionImport(JvmDeclaredType type, String memberName) { if (hasStaticImport(staticExtensionImports, type, memberName)) { return false; } Maps2.putIntoSetMap(type, memberName, staticExtensionImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); importDeclaration.setStatic(true); importDeclaration.setExtension(true); if (memberName == null) { importDeclaration.setWildcard(true); } else { importDeclaration.setMemberName(memberName); } addedImportDeclarations.add(importDeclaration); return true; }
Example #11
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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); } } } }
Example #12
Source File: XImportSectionImpl.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public EList<XImportDeclaration> getImportDeclarations() { if (importDeclarations == null) { importDeclarations = new EObjectContainmentEList<XImportDeclaration>(XImportDeclaration.class, this, XtypePackage.XIMPORT_SECTION__IMPORT_DECLARATIONS); } return importDeclarations; }
Example #13
Source File: XtypeFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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); } } } }
Example #14
Source File: XImportSectionImpl.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XtypePackage.XIMPORT_SECTION__IMPORT_DECLARATIONS: getImportDeclarations().clear(); getImportDeclarations().addAll((Collection<? extends XImportDeclaration>)newValue); return; } super.eSet(featureID, newValue); }
Example #15
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public boolean addImport(JvmDeclaredType type) { if (plainImports.containsKey(type.getSimpleName()) || !needsImport(type)) return false; Maps2.putIntoListMap(type.getSimpleName(), type, plainImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); addedImportDeclarations.add(importDeclaration); return true; }
Example #16
Source File: StaticallyImportedMemberProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public Iterable<JvmFeature> findAllFeatures(XImportDeclaration it) { JvmDeclaredType importedType = it.getImportedType(); if (!it.isStatic() || importedType == null) { return Collections.emptyList(); } IVisibilityHelper visibilityHelper = getVisibilityHelper(it.eResource()); IResolvedFeatures resolvedFeatures = resolvedFeaturesProvider.getResolvedFeatures(importedType); return Iterables.filter(resolvedFeatures.getAllFeatures(), (JvmFeature feature) -> { return feature.isStatic() && visibilityHelper.isVisible(feature) && (it.getMemberName() == null || feature.getSimpleName().startsWith(it.getMemberName())); }); }
Example #17
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected List<XImportDeclaration> sort(Iterable<XImportDeclaration> declarations) { List<XImportDeclaration> sortMe = newArrayList(filter(declarations, new Predicate<XImportDeclaration>() { @Override public boolean apply(XImportDeclaration in) { return !isEmpty(in.getImportedTypeName()); } })); Collections.sort(sortMe, new Comparator<XImportDeclaration>() { @Override public int compare(XImportDeclaration o1, XImportDeclaration o2) { return o1.getImportedName().compareTo(o2.getImportedName()); } }); return sortMe; }
Example #18
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean appendSubsection(StringBuilder builder, Iterable<XImportDeclaration> subSection, boolean needsNewline) { if (!isEmpty(subSection)) { if (needsNewline) builder.append(lineSeparator); for (XImportDeclaration declaration : isSort() ? sort(subSection) : subSection) { appendImport(builder, declaration); } return true; } return needsNewline; }
Example #19
Source File: XtypeFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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()); } }
Example #20
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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); })); }
Example #21
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testImport_04() throws Exception { XImportDeclaration importDeclaration = importDeclaration("import static extension java.lang.reflect.\nArrays.*"); assertNotNull(importDeclaration); assertEquals("java.lang.reflect.Arrays", importDeclaration.getImportedTypeName()); assertTrue(importDeclaration.isWildcard()); assertTrue(importDeclaration.isStatic()); assertTrue(importDeclaration.isExtension()); }
Example #22
Source File: DomainmodelLabelProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected Object doGetImage(Object element) { if (element instanceof JvmIdentifiableElement || element instanceof XImportSection || element instanceof XImportDeclaration) { return super.doGetImage(element); } else if (element instanceof EObject) { return ((EObject) element).eClass().getName() + ".gif"; } return super.doGetImage(element); }
Example #23
Source File: XbaseUIValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Check public void checkRestrictedType(XImportDeclaration importDeclaration){ if (isRestrictionCheckIgnored()) return; JvmType importedType = importDeclaration.getImportedType(); if(importedType instanceof JvmDeclaredType) checkRestrictedType(importDeclaration, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, (JvmDeclaredType) importedType); }
Example #24
Source File: XbaseLabelProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @return the {@code ImageDescriptor} for a given {@code obj} * @throws NullPointerException * if the passed {@code obj} is null */ protected ImageDescriptor imageDescriptor(Object obj) { Preconditions.checkNotNull(obj); if (obj instanceof JvmConstructor) { return _imageDescriptor((JvmConstructor) obj); } else if (obj instanceof JvmOperation) { return _imageDescriptor((JvmOperation) obj); } else if (obj instanceof JvmAnnotationType) { return _imageDescriptor((JvmAnnotationType) obj); } else if (obj instanceof JvmEnumerationType) { return _imageDescriptor((JvmEnumerationType) obj); } else if (obj instanceof JvmField) { return _imageDescriptor((JvmField) obj); } else if (obj instanceof JvmGenericType) { return _imageDescriptor((JvmGenericType) obj); } else if (obj instanceof JvmTypeParameter) { return _imageDescriptor((JvmTypeParameter) obj); } else if (obj instanceof JvmFormalParameter) { return _imageDescriptor((JvmFormalParameter) obj); } else if (obj instanceof XVariableDeclaration) { return _imageDescriptor((XVariableDeclaration) obj); } else if (obj instanceof IResolvedConstructor) { return _imageDescriptor((IResolvedConstructor) obj); } else if (obj instanceof IResolvedOperation) { return _imageDescriptor((IResolvedOperation) obj); } else if (obj instanceof XImportDeclaration) { return _imageDescriptor((XImportDeclaration) obj); } else if (obj instanceof XImportSection) { return _imageDescriptor((XImportSection) obj); } else if (obj instanceof IResolvedField) { return _imageDescriptor((IResolvedField) obj); } return _imageDescriptor(obj); }
Example #25
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testImport_03() throws Exception { XImportDeclaration importDeclaration = importDeclaration("import static java.util.Collections. * // foobar"); assertNotNull(importDeclaration); assertEquals("java.util.Collections", importDeclaration.getImportedTypeName()); assertTrue(importDeclaration.isWildcard()); assertTrue(importDeclaration.isStatic()); assertFalse(importDeclaration.isExtension()); }
Example #26
Source File: XbaseLabelProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String text(XImportDeclaration importDeclaration) { StringBuilder builder = new StringBuilder(); builder.append(importDeclaration.getImportedTypeName()); if (importDeclaration.isWildcard()) { builder.append(".*"); } else { if (importDeclaration.getMemberName() != null) { builder.append("."); builder.append(importDeclaration.getMemberName()); } } return builder.toString(); }
Example #27
Source File: XtypeProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void completeXImportDeclaration_MemberName(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model instanceof XImportDeclaration) { XImportDeclaration importDeclaration = (XImportDeclaration) model; for (JvmFeature feature : staticallyImportedMemberProvider.findAllFeatures(importDeclaration)) { Image image = getImage(feature); LightweightTypeReferenceFactory typeConverter = getTypeConverter(context.getResource()); StyledString displayString = getStyledDisplayString(feature, false, 0, feature.getQualifiedName(), feature.getSimpleName(), typeConverter); acceptor.accept(createCompletionProposal(feature.getSimpleName(), displayString, image, context)); } } }
Example #28
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private ITextRegion getTextRegion(final XImportDeclaration it, final int offset) { final List<INode> nodes = NodeModelUtils.findNodesForFeature(it, XtypePackage.Literals.XIMPORT_DECLARATION__MEMBER_NAME); for (final INode node : nodes) { final ITextRegion textRegion = node.getTextRegion(); if (textRegion.contains(offset)) { return textRegion; } } return null; }
Example #29
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testImport_02() throws Exception { XImportDeclaration importDeclaration = importDeclaration("import java . util . /*comment*/ List"); assertNotNull(importDeclaration); assertEquals("java.util.List", importDeclaration.getImportedTypeName()); assertFalse(importDeclaration.isWildcard()); assertFalse(importDeclaration.isStatic()); assertFalse(importDeclaration.isExtension()); }
Example #30
Source File: ModelExtensionsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testXtendImport() throws Exception { XImportDeclaration xtendImport = xtypeFactory.createXImportDeclaration(); assertFalse(xtendImport.isWildcard()); assertNull(xtendImport.getImportedTypeName()); xtendImport.setImportedNamespace(""); assertFalse(xtendImport.isWildcard()); assertEquals("", xtendImport.getImportedTypeName()); xtendImport.setImportedNamespace("java.lang.Collections.*"); assertTrue(xtendImport.isWildcard()); assertEquals("java.lang.Collections", xtendImport.getImportedTypeName()); }