use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.
the class XtypeProposalProvider method completeXImportDeclaration_MemberName.
@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));
}
}
}
use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.
the class XbaseHyperLinkHelper method createHyperlinksTo.
@Override
protected void createHyperlinksTo(XtextResource resource, INode node, EObject target, IHyperlinkAcceptor acceptor) {
EObject semanticObj = NodeModelUtils.findActualSemanticObjectFor(node);
if (semanticObj instanceof XImportDeclaration) {
if (((XImportDeclaration) semanticObj).isStatic()) {
final ITextRegion textRegion = this.locationInFileProvider.getSignificantTextRegion(semanticObj, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, 0);
int _offset = textRegion.getOffset();
int _length = textRegion.getLength();
final Region region = new Region(_offset, _length);
this.createHyperlinksTo(resource, region, target, acceptor);
}
} else if (semanticObj instanceof XAbstractFeatureCall) {
if (target instanceof JvmType) {
XAbstractFeatureCall casted = (XAbstractFeatureCall) semanticObj;
while (casted.isPackageFragment()) {
casted = (XAbstractFeatureCall) casted.eContainer();
}
if (casted.isTypeLiteral()) {
ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(casted);
Region jfaceRegion = new Region(textRegion.getOffset(), textRegion.getLength());
createHyperlinksTo(resource, jfaceRegion, target, acceptor);
return;
}
}
}
super.createHyperlinksTo(resource, node, target, acceptor);
}
use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method parseImportSection.
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());
}
}
}
}
use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.
the class XbaseReferenceUpdater method createReferenceUpdate.
@Override
protected void createReferenceUpdate(EObject referringElement, URI referringResourceURI, EReference reference, int indexInList, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
if (referringElement instanceof XImportDeclaration) {
XImportDeclaration importDeclaration = (XImportDeclaration) referringElement;
JvmDeclaredType importedType = importDeclaration.getImportedType();
boolean isStatic = importDeclaration.isStatic();
boolean isExtension = importDeclaration.isExtension();
String memberName = importDeclaration.getMemberName();
if (newTargetElement instanceof JvmDeclaredType) {
JvmDeclaredType type = (JvmDeclaredType) newTargetElement;
ImportAwareUpdateAcceptor importAwareUpdateAcceptor = (ImportAwareUpdateAcceptor) updateAcceptor;
importAwareUpdateAcceptor.removeImport(type, isStatic, isExtension, memberName);
importAwareUpdateAcceptor.acceptImport(type, isStatic, isExtension, memberName);
return;
}
if (newTargetElement instanceof JvmFeature) {
JvmFeature feature = (JvmFeature) newTargetElement;
String featureName = feature.getSimpleName();
if (featureName.equals(memberName)) {
// type rename is handled separately
return;
}
ImportAwareUpdateAcceptor importAwareUpdateAcceptor = (ImportAwareUpdateAcceptor) updateAcceptor;
if (!importAwareUpdateAcceptor.isUsed(importedType, isStatic, isExtension, memberName)) {
importAwareUpdateAcceptor.removeImport(importedType, isStatic, isExtension, memberName);
}
if (importAwareUpdateAcceptor.isConflicted(importedType, isStatic, isExtension, featureName)) {
JvmDeclaredType parentType = importedType;
while (parentType != null && !importAwareUpdateAcceptor.getImportSection().hasImportedType(parentType) && !importAwareUpdateAcceptor.acceptImport(parentType, false, false, null)) {
parentType = parentType.getDeclaringType();
}
} else {
importAwareUpdateAcceptor.acceptImport(importedType, isStatic, isExtension, featureName);
}
return;
}
}
if (referringElement instanceof XAbstractFeatureCall) {
if (newTargetElement instanceof JvmDeclaredType) {
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) referringElement;
JvmIdentifiableElement feature = featureCall.getFeature();
if (isStaticExtensionFeatureCall(referringElement, reference, feature)) {
return;
}
if (isStaticFeatureCall(referringElement, reference, feature)) {
return;
}
}
}
if (!(referringElement instanceof XFeatureCall && newTargetElement instanceof JvmConstructor)) {
// skip constructor calls like this() or super()
super.createReferenceUpdate(referringElement, referringResourceURI, reference, indexInList, newTargetElement, updateAcceptor);
}
}
use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-xtend by eclipse.
the class ParserTest method testImport_02.
@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());
}
Aggregations