protected void checkIsValidConstructorArgument(XExpression argument, JvmType containerType) { TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument); while(iterator.hasNext()) { EObject partOfArgumentExpression = iterator.next(); if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression; XExpression actualReceiver = featureCall.getActualReceiver(); if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy()) { if (feature instanceof JvmField) { if (!((JvmField) feature).isStatic()) error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } else if (feature instanceof JvmOperation) { if (!((JvmOperation) feature).isStatic()) error("Cannot refer to an instance method while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } } } } else if(isLocalClassSemantics(partOfArgumentExpression)) { iterator.prune(); } } }
protected void checkNoJavaStyleTypeCasting(INode node) { BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator(); ILeafNode child = getFirstLeafNode(iterator); if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) { INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1()); EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode); if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject; if (featureCall.isTypeLiteral()) { ICompositeNode parenthesizedNode = child.getParent(); ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion(); addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST); } } } }
@Override protected void preApply() { XAbstractFeatureCall expression = getExpression(); JvmType type = getType(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } else { String queriedName = description.getName().toString(); // may be Map$Entry String qualifiedName = declaredType.getIdentifier(); String packageName = Strings.emptyIfNull(declaredType.getPackageName()); if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } } }
public XExpression getSyntacticReceiver(XExpression expression) { if (expression instanceof XAbstractFeatureCall) { if (expression instanceof XFeatureCall) { return null; } if (expression instanceof XMemberFeatureCall) { return ((XMemberFeatureCall) expression).getMemberCallTarget(); } if (expression instanceof XAssignment) { return ((XAssignment) expression).getAssignable(); } if (expression instanceof XBinaryOperation) { return ((XBinaryOperation) expression).getLeftOperand(); } if (expression instanceof XUnaryOperation) { return ((XUnaryOperation) expression).getOperand(); } if (expression instanceof XPostfixOperation) { return ((XPostfixOperation) expression).getOperand(); } } return null; }
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) { if (expression instanceof XFeatureCall) { return ((XFeatureCall) expression).getFeatureCallArguments(); } if (expression instanceof XMemberFeatureCall) { return ((XMemberFeatureCall) expression).getMemberCallArguments(); } if (expression instanceof XAssignment) { return Collections.singletonList(((XAssignment) expression).getValue()); } if (expression instanceof XBinaryOperation) { return Collections.singletonList(((XBinaryOperation) expression).getRightOperand()); } // explicit condition to make sure we thought about it if (expression instanceof XUnaryOperation) { return Collections.emptyList(); } if (expression instanceof XPostfixOperation) { return Collections.emptyList(); } return Collections.emptyList(); }
@Override public void applyToComputationState() { super.applyToComputationState(); XAbstractFeatureCall featureCall = getFeatureCall(); if (featureCall instanceof XMemberFeatureCall) { XExpression target = ((XMemberFeatureCall) featureCall).getMemberCallTarget(); if (target == null || !(target instanceof XAbstractFeatureCall)) throw new IllegalStateException(); XAbstractFeatureCall targetFeatureCall = (XAbstractFeatureCall) target; ResolvedTypes resolvedTypes = getState().getResolvedTypes(); LightweightTypeReference targetType = resolvedTypes.getActualType(targetFeatureCall.getFeature()); if (targetType == null) { throw new IllegalStateException(); } TypeExpectation expectation = new TypeExpectation(null, getState(), false); resolvedTypes.acceptType(targetFeatureCall, expectation, targetType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED); } }
@Test public void testClosureParameter() throws Exception { // List<? super String> list = Lists.newArrayList(); // ListExtensions.map(list, new Functions.Function1<CharSequence, String>() { // public String apply(CharSequence p) { // return null; // } // }); // ListExtensions.map(list, new Functions.Function1<Object, String>() { // public String apply(Object p) { // return null; // } // }); XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? super String> list = null;\n" + " list.map(e|e)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(1); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); JvmFormalParameter e = closure.getDeclaredFormalParameters().get(0); LightweightTypeReference typeRef = typeResolver.resolveTypes(closure).getActualType(e); assertEquals("java.lang.Object", typeRef.getIdentifier()); }
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
protected XAbstractFeatureCall doGetRootTypeLiteral(XMemberFeatureCall featureCall) { boolean staticNotation = featureCall.isExplicitStatic(); XMemberFeatureCall current = featureCall; while(current.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) { XMemberFeatureCall container = (XMemberFeatureCall) current.eContainer(); if (container.isExplicitStatic()) { if (staticNotation == false) { return current; } current = container; } else if (staticNotation) { return (XAbstractFeatureCall) current.getMemberCallTarget(); } else { current = container; } } if (current != featureCall && staticNotation) { return (XAbstractFeatureCall) current.getMemberCallTarget(); } return null; }
protected ILocationData getLocationWithoutTypeArguments(XAbstractFeatureCall call) { final ICompositeNode startNode = NodeModelUtils.getNode(call); if (startNode != null) { List<INode> resultNodes = Lists.newArrayList(); if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) { boolean featureReferenceSeen = false; for (INode child : startNode.getChildren()) { if (featureReferenceSeen) { resultNodes.add(child); } else { EObject grammarElement = child.getGrammarElement(); if (grammarElement instanceof CrossReference) { Assignment assignment = GrammarUtil.containingAssignment(grammarElement); if (assignment != null && "feature".equals(assignment.getFeature())) { featureReferenceSeen = true; resultNodes.add(child); } } } } } return toLocationData(resultNodes); } return null; }
protected boolean prependNewLineIfMultiline(final EObject obj) { boolean _switchResult = false; boolean _matched = false; if (obj instanceof XMemberFeatureCall) { _matched=true; _switchResult = this.prependNewLineIfMultiline(this.builder(((XMemberFeatureCall)obj).getMemberCallArguments())); } if (!_matched) { if (obj instanceof XClosure) { _matched=true; _switchResult = false; } } if (!_matched) { if (obj instanceof XBlockExpression) { _matched=true; _switchResult = false; } } if (!_matched) { _switchResult = true; } return _switchResult; }
protected void _visit(final XMemberFeatureCall semanticObj, final INode originNode, final ImportsAcceptor acceptor) { if (((semanticObj.getFeature() instanceof JvmType) && semanticObj.isTypeLiteral())) { JvmIdentifiableElement _feature = semanticObj.getFeature(); this.visit(((JvmType) _feature), originNode, acceptor); } boolean _isExplicitStatic = semanticObj.isExplicitStatic(); boolean _not = (!_isExplicitStatic); if (_not) { final XExpression target = semanticObj.getMemberCallTarget(); if ((target instanceof XAbstractFeatureCall)) { boolean _isTypeLiteral = ((XAbstractFeatureCall)target).isTypeLiteral(); if (_isTypeLiteral) { return; } } this.collectStaticImportsFrom(semanticObj, acceptor); } }
protected void completeXFeatureCall(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { if ((model != null)) { boolean _hasExpressionScope = this.typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN); if (_hasExpressionScope) { return; } } if ((model instanceof XMemberFeatureCall)) { final ICompositeNode node = NodeModelUtils.getNode(model); boolean _isInMemberFeatureCall = this.isInMemberFeatureCall(model, node.getEndOffset(), context); if (_isInMemberFeatureCall) { return; } } this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor); }
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver); final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver); if (((receiverType == null) || receiverType.isPrimitiveVoid())) { return; } final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER); IScope scope = null; final EObject currentModel = context.getCurrentModel(); if ((currentModel != receiver)) { if (((currentModel instanceof XMemberFeatureCall) && (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference); } else { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference); } } else { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference); } this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate); }
@Test public void testClosure_04() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? super String> list = null;\n" + " list.map(e|e == null)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(1); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); LightweightTypeReference typeRef = getType(closure); assertEquals("(java.lang.Object)=>boolean", toString(typeRef)); }
@Ignore("TODO eager binding of type arguments to expectation") @Test public void testStaticFeatureCall_08() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ val Iterable<CharSequence> iterable = testdata::MethodOverrides4::staticM5(null) }"); XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight(); assertEquals("testdata.MethodOverrides3.staticM5(T)", featureCall.getFeature().getIdentifier()); }
@Test public void testOverloadedMethods_04() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? extends Object> objects = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded(objects, objects)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier()); }
@Override protected void preApply() { JvmType type = getType(); XAbstractFeatureCall expression = getExpression(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } }
protected boolean isStaticWithDeclaringType() { XAbstractFeatureCall featureCall = getFeatureCall(); if (featureCall instanceof XMemberFeatureCall) { return ((XMemberFeatureCall) featureCall).isStaticWithDeclaringType(); } if (featureCall instanceof XAssignment) { return isStaticWithDeclaringType((XAssignment) featureCall); } return false; }
@Test public void testTypeParamInference_04() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ var Integer i = new testdata.ClosureClient().invoke1([e|null],'foo') }"); XVariableDeclaration var = (XVariableDeclaration) block.getExpressions().get(0); XMemberFeatureCall fc = (XMemberFeatureCall) var.getRight(); final XExpression closure = fc.getMemberCallArguments().get(0); assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String, java.lang.Integer>", closure); }
@Test public void testOverloadedMethods_02() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<CharSequence> chars = null\n" + " var java.util.List<String> strings = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded(strings, chars)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(3); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded(java.lang.Iterable,java.util.Collection)", overloaded.getIdentifier()); }
protected void applyPackageFragment(XMemberFeatureCall memberFeatureCall, JvmDeclaredType type) { XExpression target = memberFeatureCall.getMemberCallTarget(); state.getResolvedTypes().acceptType( target, new NoExpectation(state, false), state.getReferenceOwner().newParameterizedTypeReference(type), false, ConformanceFlags.CHECKED_SUCCESS); if (target instanceof XMemberFeatureCall) { applyPackageFragment((XMemberFeatureCall) target, type); } }
@Override protected ITextRegion getLocationOfContainmentReference(EObject owner, EReference reference, int indexInList, RegionDescription query) { if (owner instanceof XMemberFeatureCall && reference == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) { XMemberFeatureCall casted = (XMemberFeatureCall) owner; if (casted.isExplicitStatic() || casted.isStaticWithDeclaringType()) { XExpression target = ((XMemberFeatureCall) owner).getMemberCallTarget(); return getTextRegion(target, query); } } return super.getLocationOfContainmentReference(owner, reference, indexInList, query); }
@Test public void testClosure_03() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? super String> list = null;\n" + " list.map(e|e)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(1); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); LightweightTypeReference typeRef = getType(closure); assertEquals("(java.lang.Object)=>java.lang.Object", toString(typeRef)); }
@Override public IScope getScope(EObject context, EReference reference) { if (context == null || context.eResource() == null || context.eResource().getResourceSet() == null) { return IScope.NULLSCOPE; } if (isFeatureCallScope(reference)) { IExpressionScope.Anchor anchor = IExpressionScope.Anchor.BEFORE; if (context instanceof XAbstractFeatureCall) { EObject proxyOrResolved = (EObject) context.eGet(reference, false); if (proxyOrResolved != null && !proxyOrResolved.eIsProxy()) { XExpression receiver = ((XAbstractFeatureCall) context).getActualReceiver(); if (receiver == null && context instanceof XMemberFeatureCall) { receiver = ((XMemberFeatureCall) context).getMemberCallTarget(); } if (receiver != null) { anchor = IExpressionScope.Anchor.RECEIVER; context = receiver; } } else if (context instanceof XBinaryOperation) { context = ((XBinaryOperation) context).getLeftOperand(); anchor = IExpressionScope.Anchor.RECEIVER; } else if (context instanceof XMemberFeatureCall) { context = ((XMemberFeatureCall) context).getMemberCallTarget(); anchor = IExpressionScope.Anchor.RECEIVER; } } IExpressionScope expressionScope = typeResolver.resolveTypes(context).getExpressionScope(context, anchor); return expressionScope.getFeatureScope(); } if (isTypeScope(reference)) { return typeScopes.createTypeScope(context, reference); } return delegateGetScope(context, reference); }
protected boolean isValidStaticState(XExpression receiver) { boolean validStaticState = true; if (receiver instanceof XMemberFeatureCall) { XExpression thisReference = ((XMemberFeatureCall) receiver).getMemberCallTarget(); if (thisReference instanceof XFeatureCall && ((XFeatureCall) thisReference).getFeature() instanceof JvmType) { validStaticState = getSession().isInstanceContext(); } } return validStaticState; }
/** * Returns <code>true</code> if the given feature call can be a type literal (structurally). * Otherwise <code>false</code>. */ public boolean isPotentialTypeLiteral(XExpression featureCall, /* @Nullable */ IResolvedTypes resolvedTypes) { if (featureCall instanceof XMemberFeatureCall) { return isPotentialTypeLiteralImpl(featureCall, resolvedTypes, ((XMemberFeatureCall) featureCall).isExplicitStatic()); } return isPotentialTypeLiteralImpl(featureCall, resolvedTypes, false); }
protected boolean appendReceiver(XAbstractFeatureCall call, ITreeAppendable b, @SuppressWarnings("unused") boolean isExpressionContext) { if (call.isStatic()) { if (expressionHelper.findInlineAnnotation(call) != null) { return false; } if (call instanceof XMemberFeatureCall) { XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) call; if (memberFeatureCall.isStaticWithDeclaringType()) { XAbstractFeatureCall target = (XAbstractFeatureCall) memberFeatureCall.getMemberCallTarget(); JvmType declaringType = (JvmType) target.getFeature(); b.trace(target, false).append(declaringType); return true; } } b.append(((JvmFeature) call.getFeature()).getDeclaringType()); return true; } XExpression receiver = getActualReceiver(call); if (receiver != null) { internalToJavaExpression(receiver, b); if (receiver instanceof XAbstractFeatureCall) { // some local types have a reference name bound to the empty string // which is the reason why we have to check for an empty string as a valid // reference name here // see AnonymousClassCompilerTest.testCapturedLocalVar_04 // if it turns out that we have to deal with generics there too, we may // have to create a field in the synthesized local class with a unique // name that points to 'this' if (((XAbstractFeatureCall) receiver).getFeature() instanceof JvmType) { String referenceName = getReferenceName(receiver, b); if (referenceName != null && referenceName.length() == 0) { return false; } } } return true; } else { return false; } }
@Ignore("TODO eager binding of type arguments to expectation") @Test public void testStaticFeatureCall_17() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ val Iterable<CharSequence> iterable = testdata.MethodOverrides4::staticM5(null) }"); XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight(); assertEquals("testdata.MethodOverrides3.staticM5(T)", featureCall.getFeature().getIdentifier()); }
private boolean isOuterTypeLiteral(XAbstractFeatureCall featureCall) { if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) { XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer(); if (container.isTypeLiteral()) { return true; } } return false; }
protected boolean isStaticMemberCallTarget(final EObject contextObject) { boolean candidate = ((contextObject instanceof XFeatureCall) && (contextObject.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET)); if (candidate) { EObject _eContainer = contextObject.eContainer(); XMemberFeatureCall memberFeatureCall = ((XMemberFeatureCall) _eContainer); boolean _isExplicitStatic = memberFeatureCall.isExplicitStatic(); if (_isExplicitStatic) { return true; } } return false; }
protected boolean isMultiParamInOwnLine(final XExpression fc, final FormattableDocument doc) { if (fc instanceof XFeatureCall) { return _isMultiParamInOwnLine((XFeatureCall)fc, doc); } else if (fc instanceof XMemberFeatureCall) { return _isMultiParamInOwnLine((XMemberFeatureCall)fc, doc); } else if (fc instanceof XConstructorCall) { return _isMultiParamInOwnLine((XConstructorCall)fc, doc); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(fc, doc).toString()); } }
public void visit(final EObject jvmType, final INode originNode, final ImportsAcceptor acceptor) { if (jvmType instanceof JvmGenericType) { _visit((JvmGenericType)jvmType, originNode, acceptor); return; } else if (jvmType instanceof JvmDeclaredType) { _visit((JvmDeclaredType)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XFeatureCall) { _visit((XFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XMemberFeatureCall) { _visit((XMemberFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XAbstractFeatureCall) { _visit((XAbstractFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XConstructorCall) { _visit((XConstructorCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XTypeLiteral) { _visit((XTypeLiteral)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XAnnotation) { _visit((XAnnotation)jvmType, originNode, acceptor); return; } else if (jvmType instanceof JvmTypeReference) { _visit((JvmTypeReference)jvmType, originNode, acceptor); return; } else if (jvmType != null) { _visit(jvmType, originNode, acceptor); return; } else if (jvmType == null) { _visit((Void)null, originNode, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(jvmType, originNode, acceptor).toString()); } }
@Test public void testShortClosure_2() throws Exception { XMemberFeatureCall featureCall = (XMemberFeatureCall) expression("foo.bar(a,b|a+b)"); assertEquals(1, featureCall.getMemberCallArguments().size()); assertTrue(featureCall.getMemberCallArguments().get(0) instanceof XClosure); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); assertEquals(2, closure.getFormalParameters().size()); }
@Test public void testFeatureCall_3() throws Exception { XMemberFeatureCall call = (XMemberFeatureCall) expression("'holla'.bar(4)"); assertNotNull(call); assertEquals(2, call.getExplicitArguments().size()); assertEquals("4", ((XNumberLiteral) call.getExplicitArguments().get(1)).getValue()); assertTrue(call.getExplicitArguments().get(0) instanceof XStringLiteral); }
@Test public void testOverloadedMethods_09() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? extends Object> objects = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded2(objects, objects)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded2(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier()); }
protected void doTestSwitch_2(XSwitchExpression se) { assertEquals(2,se.getCases().size()); assertNull(se.getDefault()); XCasePart c1 = se.getCases().get(0); assertEquals("java.lang.String",c1.getTypeGuard().getIdentifier()); assertFeatureCall("length",c1.getCase()); assertFeatureCall("foo",((XMemberFeatureCall)c1.getCase()).getMemberCallTarget()); assertFeatureCall("bar",c1.getThen()); XCasePart c2 = se.getCases().get(1); assertEquals("java.lang.String",c2.getTypeGuard().getIdentifier()); assertNull(c2.getCase()); assertFeatureCall("baz",((XBlockExpression)c2.getThen()).getExpressions().get(0)); }
@Test public void testFeatureCall_04() throws Exception { String text = "String::<Invalid>valueOf('a')"; XMemberFeatureCall featureCall = castedExpression(text); ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall); String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength()); assertEquals(text.substring(text.indexOf('>') + 1), significant); }
@Test public void testStaticFeatureCall_01() throws Exception { String text = "String::<Invalid>valueOf('a')"; XMemberFeatureCall featureCall = castedExpression(text); ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0); String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength()); assertEquals("String", significant); }
@Test public void testStaticFeatureCall_02() throws Exception { String text = "java::util::Collections::emptyList"; XMemberFeatureCall featureCall = castedExpression(text); ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0); String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength()); assertEquals("java::util::Collections", significant); }