use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-eclipse by eclipse.
the class XbaseQuickfixProvider method fixInvisibleFeature.
@Fix(IssueCodes.FEATURE_NOT_VISIBLE)
public void fixInvisibleFeature(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null && issue.getData().length >= 1 && "subclass-context".equals(issue.getData()[0])) {
String fixup;
if (issue.getData().length == 1)
fixup = "Add type cast.";
else
fixup = "Add cast to " + issue.getData()[1] + ".";
acceptor.accept(issue, fixup, fixup, null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
if (!(element instanceof XAbstractFeatureCall))
return;
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) element;
if (!(featureCall.getFeature() instanceof JvmMember))
return;
JvmType declaringType = ((JvmMember) featureCall.getFeature()).getDeclaringType();
if (featureCall instanceof XMemberFeatureCall) {
addTypeCastToExplicitReceiver(featureCall, context, declaringType, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET);
} else if (featureCall instanceof XAssignment) {
addTypeCastToExplicitReceiver(featureCall, context, declaringType, XbasePackage.Literals.XASSIGNMENT__ASSIGNABLE);
} else if (featureCall instanceof XFeatureCall) {
addTypeCastToImplicitReceiver((XFeatureCall) featureCall, context, declaringType);
}
}
});
}
}
use of org.eclipse.xtext.xbase.XFeatureCall 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.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ParserTest method testFunction_1.
@Test
public void testFunction_1() throws Exception {
XtendFunction func = function("def String foo() {foo}");
assertEquals("foo", func.getName());
assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
assertEquals(0, func.getParameters().size());
assertNotNull(func.getReturnType());
assertEquals(0, func.getTypeParameters().size());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ParserTest method testFunction_0.
@Test
public void testFunction_0() throws Exception {
XtendFunction func = function("def foo() {foo}");
assertEquals("foo", func.getName());
assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
assertEquals(0, func.getParameters().size());
assertNull(func.getReturnType());
assertEquals(0, func.getTypeParameters().size());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ParserTest method testFunction_6.
@Test
public void testFunction_6() throws Exception {
XtendFunction func = function("override dispatch foo(String s) { foo('x')}");
assertEquals("foo", func.getName());
assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
assertEquals(1, func.getParameters().size());
assertNull(func.getReturnType());
assertTrue(func.isOverride());
assertTrue(func.isDispatch());
assertEquals(0, func.getTypeParameters().size());
}
Aggregations