Java Code Examples for org.eclipse.xtext.xbase.XAssignment#getFeature()
The following examples show how to use
org.eclipse.xtext.xbase.XAssignment#getFeature() .
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: AssignmentLinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testParameter() throws Exception { XtendClass clazz = clazz( "class SomeClass {\n" + " def void method(String aString) {\n" + " aString = 'foo'\n" + " }\n" + "}"); XAssignment assignment = getLastAssignment(clazz); assertNotNull("feature is available", assignment.getFeature()); JvmIdentifiableElement linked = assignment.getFeature(); assertFalse("is resolved", linked.eIsProxy()); assertEquals("aString", linked.getIdentifier()); assertTrue(TypesPackage.Literals.JVM_FORMAL_PARAMETER.isInstance(linked)); assertNull(assignment.getInvalidFeatureIssueCode(), assignment.getInvalidFeatureIssueCode()); }
Example 2
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDeclaredConstructor_01() throws Exception { XtendClass clazz = clazz( "class Foo { " + " int i" + " new(int i) { this.i = i }" + "}"); assertEquals(2, clazz.getMembers().size()); XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1); XAssignment assignment = (XAssignment) ((XBlockExpression)constructor.getExpression()).getExpressions().get(0); JvmField field = (JvmField) assignment.getFeature(); assertEquals("i", field.getSimpleName()); XFeatureCall target = (XFeatureCall) assignment.getAssignable(); JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature(); assertEquals("Foo", identifiableElement.getSimpleName()); XFeatureCall value = (XFeatureCall) assignment.getValue(); JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature(); assertEquals("i", parameter.getSimpleName()); }
Example 3
Source File: SARLValidator.java From sarl with Apache License 2.0 | 6 votes |
/** Replies if the given object is locally assigned. * * <p>An object is locally assigned when it is the left operand of an assignment operation. * * @param target the object to test. * @param containerToFindUsage the container in which the usages should be find. * @return {@code true} if the given object is assigned. * @since 0.7 */ protected boolean isLocallyAssigned(EObject target, EObject containerToFindUsage) { if (this.readAndWriteTracking.isAssigned(target)) { return true; } final Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage); // field are assigned when they are not used as the left operand of an assignment operator. for (final Setting usage : usages) { final EObject object = usage.getEObject(); if (object instanceof XAssignment) { final XAssignment assignment = (XAssignment) object; if (assignment.getFeature() == target) { // Mark the field as assigned in order to be faster during the next assignment test. this.readAndWriteTracking.markAssignmentAccess(target); return true; } } } return false; }
Example 4
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isLocallyUsed(EObject target, EObject containerToFindUsage) { if (readAndWriteTracking.isRead(target)) { return true; } Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage); // field and local variables are used when they are not used as the left operand of an assignment operator. if (target instanceof XVariableDeclaration || target instanceof JvmField) { for (final Setting usage : usages) { final EObject object = usage.getEObject(); if (object instanceof XAssignment) { final XAssignment assignment = (XAssignment) object; if (assignment.getFeature() != target) { return true; } } else { return true; } } return false; } // for non-private members it is enough to check that there are usages if (!(target instanceof JvmOperation) || ((JvmOperation)target).getVisibility()!=JvmVisibility.PRIVATE) { return !usages.isEmpty(); } else { // for private members it has to be checked if all usages are within the operation EObject targetSourceElem = associations.getPrimarySourceElement(target); for (Setting s : usages) { if (s.getEObject() instanceof XAbstractFeatureCall) { XAbstractFeatureCall fc = (XAbstractFeatureCall) s.getEObject(); // when the feature call does not call itself or the call is // from another function, then it is locally used if (fc.getFeature() != target || !EcoreUtil.isAncestor(targetSourceElem, fc)) return true; } else { return true; } } return false; } }
Example 5
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Object _doEvaluate(XAssignment assignment, IEvaluationContext context, CancelIndicator indicator) { JvmIdentifiableElement feature = assignment.getFeature(); if (feature instanceof JvmOperation && ((JvmOperation) feature).isVarArgs()) { return _doEvaluate((XAbstractFeatureCall) assignment, context, indicator); } Object value = internalEvaluate(assignment.getValue(), context, indicator); Object assign = assignValueTo(feature, assignment, value, context, indicator); return assign; }
Example 6
Source File: AssignmentLinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void assertLinksTo(String identifier, EClass type, XAssignment featureCall, boolean withIssues) { assertNotNull("feature is available", featureCall.getFeature()); JvmIdentifiableElement linked = featureCall.getFeature(); assertFalse("is resolved", linked.eIsProxy()); assertEquals(identifier, linked.getIdentifier()); assertTrue(type.isInstance(linked)); if (withIssues) assertNotNull("Expected issues", featureCall.getInvalidFeatureIssueCode()); else { assertNull(featureCall.getInvalidFeatureIssueCode(), featureCall.getInvalidFeatureIssueCode()); validator.assertNoErrors(featureCall); } }
Example 7
Source File: SARLOperationHelper.java From sarl with Apache License 2.0 | 5 votes |
/** Test if the given expression has side effects. * * @param expression the expression. * @param context the list of context expressions. * @return {@code true} if the expression has side effects. */ protected Boolean _hasSideEffects(XAssignment expression, ISideEffectContext context) { if (internalHasOperationSideEffects(expression, context, true)) { return true; } if (hasSideEffects(expression.getValue(), context)) { return true; } final JvmIdentifiableElement feature = expression.getFeature(); if (feature instanceof XVariableDeclaration) { context.assignVariable(feature.getIdentifier(), expression.getValue()); } return false; }