org.eclipse.xtext.xbase.XSynchronizedExpression Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XSynchronizedExpression. 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: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _computeTypes(XSynchronizedExpression expr, ITypeComputationState state) {
	ITypeComputationState paramState = state.withExpectation(state.getReferenceOwner().newReferenceToObject());
	ITypeComputationResult paramType = paramState.computeTypes(expr.getParam());
	LightweightTypeReference actualParamType = paramType.getActualExpressionType();
	if (actualParamType != null && (actualParamType.isPrimitive() || actualParamType.isAny())) {
		state.addDiagnostic(new EObjectDiagnosticImpl(
				Severity.ERROR,
				IssueCodes.INCOMPATIBLE_TYPES,
				actualParamType.getHumanReadableName() +  " is not a valid type's argument for the synchronized expression.",
				expr.getParam(),
				null,
				-1,
				new String[] { 
				}));
	}
	state.computeTypes(expr.getExpression());
}
 
Example #2
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean bracesAreAddedByOuterStructure(XExpression expression) {
	EObject container = expression.eContainer();
	if (container instanceof XTryCatchFinallyExpression 
			|| container instanceof XIfExpression
			|| container instanceof XClosure
			|| container instanceof XSynchronizedExpression) {
		return true;
	}
	if (container instanceof XBlockExpression) {
		XBlockExpression blockExpression = (XBlockExpression) container;
		EList<XExpression> expressions = blockExpression.getExpressions();
		if (expressions.size() == 1 && expressions.get(0) == expression) {
			return bracesAreAddedByOuterStructure(blockExpression);
		}
	}
	if (!(container instanceof XExpression)) {
		return true;
	}
	return false;
}
 
Example #3
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _toJavaStatement(final XSynchronizedExpression synchronizedExpression, final ITreeAppendable b, boolean isReferenced) {
	if (isReferenced) {
		declareSyntheticVariable(synchronizedExpression, b);
	}
	ITreeAppendable synchronizedAppendable = b.trace(synchronizedExpression, true);
	XExpression param = synchronizedExpression.getParam();
	if (!canCompileToJavaExpression(param, b))
		internalToJavaStatement(param, synchronizedAppendable, isReferenced);
	
	synchronizedAppendable.newLine().append("synchronized (");
	internalToJavaExpression(param, synchronizedAppendable);
	synchronizedAppendable.append(") {").increaseIndentation();
	synchronizedAppendable.openPseudoScope();
	
	XExpression expression = synchronizedExpression.getExpression();
	internalToJavaStatement(expression, b, isReferenced);
	if (isReferenced) {
		b.newLine().append(getVarName(synchronizedExpression, synchronizedAppendable)).append(" = ");
		internalToConvertedExpression(expression, b, getLightweightType(synchronizedExpression));
		b.append(";");
	}
	
	synchronizedAppendable.closeScope();
	synchronizedAppendable.decreaseIndentation().newLine().append("}");
}
 
Example #4
Source File: DefaultEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Collection<IEarlyExitComputer.ExitPoint> exitPoints(final XExpression expression) {
  if (expression instanceof XDoWhileExpression) {
    return _exitPoints((XDoWhileExpression)expression);
  } else if (expression instanceof XWhileExpression) {
    return _exitPoints((XWhileExpression)expression);
  } else if (expression instanceof XAbstractFeatureCall) {
    return _exitPoints((XAbstractFeatureCall)expression);
  } else if (expression instanceof XBasicForLoopExpression) {
    return _exitPoints((XBasicForLoopExpression)expression);
  } else if (expression instanceof XBlockExpression) {
    return _exitPoints((XBlockExpression)expression);
  } else if (expression instanceof XConstructorCall) {
    return _exitPoints((XConstructorCall)expression);
  } else if (expression instanceof XForLoopExpression) {
    return _exitPoints((XForLoopExpression)expression);
  } else if (expression instanceof XIfExpression) {
    return _exitPoints((XIfExpression)expression);
  } else if (expression instanceof XReturnExpression) {
    return _exitPoints((XReturnExpression)expression);
  } else if (expression instanceof XSwitchExpression) {
    return _exitPoints((XSwitchExpression)expression);
  } else if (expression instanceof XSynchronizedExpression) {
    return _exitPoints((XSynchronizedExpression)expression);
  } else if (expression instanceof XThrowExpression) {
    return _exitPoints((XThrowExpression)expression);
  } else if (expression instanceof XTryCatchFinallyExpression) {
    return _exitPoints((XTryCatchFinallyExpression)expression);
  } else if (expression instanceof XVariableDeclaration) {
    return _exitPoints((XVariableDeclaration)expression);
  } else if (expression != null) {
    return _exitPoints(expression);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression).toString());
  }
}
 
Example #5
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) {
	if (obj instanceof XBlockExpression) {
		_toJavaExpression((XBlockExpression) obj, appendable);
	} else if (obj instanceof XCastedExpression) {
		_toJavaExpression((XCastedExpression) obj, appendable);
	} else if (obj instanceof XClosure) {
		_toJavaExpression((XClosure) obj, appendable);
	} else if (obj instanceof XAnnotation) {
		_toJavaExpression((XAnnotation) obj, appendable);
	} else if (obj instanceof XConstructorCall) {
		_toJavaExpression((XConstructorCall) obj, appendable);
	} else if (obj instanceof XIfExpression) {
		_toJavaExpression((XIfExpression) obj, appendable);
	} else if (obj instanceof XInstanceOfExpression) {
		_toJavaExpression((XInstanceOfExpression) obj, appendable);
	} else if (obj instanceof XSwitchExpression) {
		_toJavaExpression((XSwitchExpression) obj, appendable);
	} else if (obj instanceof XTryCatchFinallyExpression) {
		_toJavaExpression((XTryCatchFinallyExpression) obj, appendable);
	} else if (obj instanceof XListLiteral) {
		_toJavaExpression((XListLiteral) obj, appendable);
	} else if (obj instanceof XSetLiteral) {
		_toJavaExpression((XSetLiteral) obj, appendable);
	} else if (obj instanceof XSynchronizedExpression) {
		_toJavaExpression((XSynchronizedExpression) obj, appendable);
	} else if (obj instanceof XReturnExpression) {
		_toJavaExpression((XReturnExpression) obj, appendable);
	} else if (obj instanceof XThrowExpression) {
		_toJavaExpression((XThrowExpression) obj, appendable);
	} else {
		super.internalToConvertedExpression(obj, appendable);
	}
}
 
Example #6
Source File: DefaultEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XSynchronizedExpression expression) {
  Collection<IEarlyExitComputer.ExitPoint> paramExitPoints = this.getExitPoints(expression.getParam());
  boolean _isNotEmpty = this.isNotEmpty(paramExitPoints);
  if (_isNotEmpty) {
    return paramExitPoints;
  }
  return this.getExitPoints(expression.getExpression());
}
 
Example #7
Source File: AbstractXbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Deprecated
protected void sequence_XSynchronizedExpression(EObject context, XSynchronizedExpression semanticObject) {
	sequence_XSynchronizedExpression(createContext(context, semanticObject), semanticObject);
}
 
Example #8
Source File: XtendImplicitReturnFinder.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  if (expression instanceof AnonymousClass) {
    _findImplicitReturns((AnonymousClass)expression, acceptor);
    return;
  } else if (expression instanceof RichString) {
    _findImplicitReturns((RichString)expression, acceptor);
    return;
  } else if (expression instanceof XAbstractFeatureCall) {
    _findImplicitReturns((XAbstractFeatureCall)expression, acceptor);
    return;
  } else if (expression instanceof XBlockExpression) {
    _findImplicitReturns((XBlockExpression)expression, acceptor);
    return;
  } else if (expression instanceof XBooleanLiteral) {
    _findImplicitReturns((XBooleanLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XCastedExpression) {
    _findImplicitReturns((XCastedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XClosure) {
    _findImplicitReturns((XClosure)expression, acceptor);
    return;
  } else if (expression instanceof XCollectionLiteral) {
    _findImplicitReturns((XCollectionLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XConstructorCall) {
    _findImplicitReturns((XConstructorCall)expression, acceptor);
    return;
  } else if (expression instanceof XIfExpression) {
    _findImplicitReturns((XIfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XInstanceOfExpression) {
    _findImplicitReturns((XInstanceOfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XNullLiteral) {
    _findImplicitReturns((XNullLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XNumberLiteral) {
    _findImplicitReturns((XNumberLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XStringLiteral) {
    _findImplicitReturns((XStringLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XSwitchExpression) {
    _findImplicitReturns((XSwitchExpression)expression, acceptor);
    return;
  } else if (expression instanceof XSynchronizedExpression) {
    _findImplicitReturns((XSynchronizedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTryCatchFinallyExpression) {
    _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTypeLiteral) {
    _findImplicitReturns((XTypeLiteral)expression, acceptor);
    return;
  } else if (expression != null) {
    _findImplicitReturns(expression, acceptor);
    return;
  } else if (expression == null) {
    _findImplicitReturns((Void)null, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression, acceptor).toString());
  }
}
 
Example #9
Source File: StaticExtensionMethodImporter.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns true if the expression should be wrapped in ( )
 * in order to accept a static extension call.
 */
private boolean shouldWrap(final XExpression expression) {
  boolean _switchResult = false;
  boolean _matched = false;
  if (expression instanceof XMemberFeatureCall) {
    _matched=true;
  }
  if (!_matched) {
    if (expression instanceof XFeatureCall) {
      _matched=true;
    }
  }
  if (_matched) {
    _switchResult = false;
  }
  if (!_matched) {
    if (expression instanceof XAbstractFeatureCall) {
      _matched=true;
    }
    if (!_matched) {
      if (expression instanceof XSwitchExpression) {
        _matched=true;
      }
    }
    if (!_matched) {
      if (expression instanceof XTryCatchFinallyExpression) {
        _matched=true;
      }
    }
    if (!_matched) {
      if (expression instanceof XSynchronizedExpression) {
        _matched=true;
      }
    }
    if (!_matched) {
      if (expression instanceof XIfExpression) {
        _matched=true;
      }
    }
    if (_matched) {
      _switchResult = true;
    }
  }
  if (!_matched) {
    _switchResult = false;
  }
  return _switchResult;
}
 
Example #10
Source File: ImplicitReturnFinderTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testSynchronized() throws Exception {
	XSynchronizedExpression block = (XSynchronizedExpression) expression("synchronized (this) {1}");
	hasImplicitReturns(block, Iterables.getFirst(((XBlockExpression) block.getExpression()).getExpressions(), null));
}
 
Example #11
Source File: XbaseImplicitReturnFinder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  if (expression instanceof XAbstractFeatureCall) {
    _findImplicitReturns((XAbstractFeatureCall)expression, acceptor);
    return;
  } else if (expression instanceof XBlockExpression) {
    _findImplicitReturns((XBlockExpression)expression, acceptor);
    return;
  } else if (expression instanceof XBooleanLiteral) {
    _findImplicitReturns((XBooleanLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XCastedExpression) {
    _findImplicitReturns((XCastedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XClosure) {
    _findImplicitReturns((XClosure)expression, acceptor);
    return;
  } else if (expression instanceof XCollectionLiteral) {
    _findImplicitReturns((XCollectionLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XConstructorCall) {
    _findImplicitReturns((XConstructorCall)expression, acceptor);
    return;
  } else if (expression instanceof XIfExpression) {
    _findImplicitReturns((XIfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XInstanceOfExpression) {
    _findImplicitReturns((XInstanceOfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XNullLiteral) {
    _findImplicitReturns((XNullLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XNumberLiteral) {
    _findImplicitReturns((XNumberLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XStringLiteral) {
    _findImplicitReturns((XStringLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XSwitchExpression) {
    _findImplicitReturns((XSwitchExpression)expression, acceptor);
    return;
  } else if (expression instanceof XSynchronizedExpression) {
    _findImplicitReturns((XSynchronizedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTryCatchFinallyExpression) {
    _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTypeLiteral) {
    _findImplicitReturns((XTypeLiteral)expression, acceptor);
    return;
  } else if (expression != null) {
    _findImplicitReturns(expression, acceptor);
    return;
  } else if (expression == null) {
    _findImplicitReturns((Void)null, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression, acceptor).toString());
  }
}
 
Example #12
Source File: XbaseImplicitReturnFinder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void _findImplicitReturns(final XSynchronizedExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  this.findImplicitReturns(expression.getExpression(), acceptor);
}
 
Example #13
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Object _doEvaluate(XSynchronizedExpression expression, IEvaluationContext context, CancelIndicator indicator) {
	internalEvaluate(expression.getParam(), context, indicator);
	return internalEvaluate(expression.getExpression(), context, indicator);
}
 
Example #14
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * don't call this directly. Always call evaluate() internalEvaluate()
 */
protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) {
	if (expression instanceof XAssignment) {
      return _doEvaluate((XAssignment)expression, context, indicator);
    } else if (expression instanceof XDoWhileExpression) {
      return _doEvaluate((XDoWhileExpression)expression, context, indicator);
    } else if (expression instanceof XMemberFeatureCall) {
      return _doEvaluate((XMemberFeatureCall)expression, context, indicator);
    } else if (expression instanceof XWhileExpression) {
      return _doEvaluate((XWhileExpression)expression, context, indicator);
    } else if (expression instanceof XFeatureCall) {
    	return _doEvaluate((XFeatureCall)expression, context, indicator);
    } else if (expression instanceof XAbstractFeatureCall) {
    	return _doEvaluate((XAbstractFeatureCall)expression, context, indicator);
    } else if (expression instanceof XBlockExpression) {
      return _doEvaluate((XBlockExpression)expression, context, indicator);
    } else if (expression instanceof XSynchronizedExpression) {
	  return _doEvaluate((XSynchronizedExpression)expression, context, indicator);
	} else if (expression instanceof XBooleanLiteral) {
      return _doEvaluate((XBooleanLiteral)expression, context, indicator);
    } else if (expression instanceof XCastedExpression) {
      return _doEvaluate((XCastedExpression)expression, context, indicator);
    } else if (expression instanceof XClosure) {
      return _doEvaluate((XClosure)expression, context, indicator);
    } else if (expression instanceof XConstructorCall) {
      return _doEvaluate((XConstructorCall)expression, context, indicator);
    } else if (expression instanceof XForLoopExpression) {
      return _doEvaluate((XForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XBasicForLoopExpression) {
	  return _doEvaluate((XBasicForLoopExpression)expression, context, indicator);
	} else if (expression instanceof XIfExpression) {
      return _doEvaluate((XIfExpression)expression, context, indicator);
    } else if (expression instanceof XInstanceOfExpression) {
      return _doEvaluate((XInstanceOfExpression)expression, context, indicator);
    } else if (expression instanceof XNullLiteral) {
      return _doEvaluate((XNullLiteral)expression, context, indicator);
    } else if (expression instanceof XNumberLiteral) {
      return _doEvaluate((XNumberLiteral)expression, context, indicator);
    } else if (expression instanceof XReturnExpression) {
      return _doEvaluate((XReturnExpression)expression, context, indicator);
    } else if (expression instanceof XStringLiteral) {
      return _doEvaluate((XStringLiteral)expression, context, indicator);
    } else if (expression instanceof XSwitchExpression) {
      return _doEvaluate((XSwitchExpression)expression, context, indicator);
    } else if (expression instanceof XThrowExpression) {
      return _doEvaluate((XThrowExpression)expression, context, indicator);
    } else if (expression instanceof XTryCatchFinallyExpression) {
      return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator);
    } else if (expression instanceof XTypeLiteral) {
      return _doEvaluate((XTypeLiteral)expression, context, indicator);
    } else if (expression instanceof XVariableDeclaration) {
	      return _doEvaluate((XVariableDeclaration)expression, context, indicator);
    } else if (expression instanceof XListLiteral) {
	      return _doEvaluate((XListLiteral)expression, context, indicator);
    } else if (expression instanceof XSetLiteral) {
	      return _doEvaluate((XSetLiteral)expression, context, indicator);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(expression, context, indicator).toString());
    }
}
 
Example #15
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void _toJavaExpression(XSynchronizedExpression synchronizedExpression, ITreeAppendable b) {
	b.trace(synchronizedExpression, false).append(getVarName(synchronizedExpression, b));
}
 
Example #16
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) {
	if (obj instanceof XBlockExpression) {
		_toJavaStatement((XBlockExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XCastedExpression) {
		_toJavaStatement((XCastedExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XClosure) {
		_toJavaStatement((XClosure) obj, appendable, isReferenced);
	} else if (obj instanceof XConstructorCall) {
		_toJavaStatement((XConstructorCall) obj, appendable, isReferenced);
	} else if (obj instanceof XDoWhileExpression) {
		_toJavaStatement((XDoWhileExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XForLoopExpression) {
		_toJavaStatement((XForLoopExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XBasicForLoopExpression) {
		_toJavaStatement((XBasicForLoopExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XIfExpression) {
		_toJavaStatement((XIfExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XInstanceOfExpression) {
		_toJavaStatement((XInstanceOfExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XReturnExpression) {
		_toJavaStatement((XReturnExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XSwitchExpression) {
		_toJavaStatement((XSwitchExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XThrowExpression) {
		_toJavaStatement((XThrowExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XTryCatchFinallyExpression) {
		_toJavaStatement((XTryCatchFinallyExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XVariableDeclaration) {
		_toJavaStatement((XVariableDeclaration) obj, appendable, isReferenced);
	} else if (obj instanceof XWhileExpression) {
		_toJavaStatement((XWhileExpression) obj, appendable, isReferenced);
	} else if (obj instanceof XListLiteral) {
		_toJavaStatement((XListLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XSetLiteral) {
		_toJavaStatement((XSetLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XSynchronizedExpression) {
		_toJavaStatement((XSynchronizedExpression) obj, appendable, isReferenced);
	} else {
		super.doInternalToJavaStatement(obj, appendable, isReferenced);
	}
}
 
Example #17
Source File: ExtendedEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isDefiniteEarlyExit(XExpression expression) {
	// TODO further improvements
	if (expression instanceof XIfExpression) {
		XIfExpression ifExpression = (XIfExpression) expression;
		return isDefiniteEarlyExit(ifExpression.getThen()) && isDefiniteEarlyExit(ifExpression.getElse());
	} else if (expression instanceof XSwitchExpression) {
		XSwitchExpression switchExpression = (XSwitchExpression) expression;
		if (isDefiniteEarlyExit(switchExpression.getDefault())) {
			for(XCasePart caseExpression: switchExpression.getCases()) {
				if (!isDefiniteEarlyExit(caseExpression.getThen())) {
					return false;
				}
			}
			return true;
		}
		return false;
	} else if (expression instanceof XTryCatchFinallyExpression) {
		XTryCatchFinallyExpression tryExpression = (XTryCatchFinallyExpression) expression;
		if (isDefiniteEarlyExit(tryExpression.getFinallyExpression())) {
			return true;
		}
		if (isDefiniteEarlyExit(tryExpression.getExpression())) {
			for(XCatchClause catchClause: tryExpression.getCatchClauses()) {
				if (!isDefiniteEarlyExit(catchClause.getExpression())) {
					return false;
				}
			}
			return true;
		}
		return false;
	} else if (expression instanceof XBlockExpression) {
		List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
		for(int i = expressions.size() - 1; i >= 0; i--) {
			if (isDefiniteEarlyExit(expressions.get(i))) {
				return true;
			}
		}
	} else if (expression instanceof XSynchronizedExpression) {
		return isDefiniteEarlyExit(((XSynchronizedExpression) expression).getExpression());
	}
	return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
}
 
Example #18
Source File: ExtendedEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns <code>true</code> for expressions that seem to be early exit expressions, e.g.
 * <pre>
 *   while(condition) {
 *     if (anotherCondition)
 *       return value
 *     changeResultOfFirstCondition
 *   }
 * </pre>
 */
public boolean isIntentionalEarlyExit(/* @Nullable */ XExpression expression) {
	if (expression == null) {
		return true;
	}
	if (expression instanceof XBlockExpression) {
		XBlockExpression block = (XBlockExpression) expression;
		List<XExpression> children = block.getExpressions();
		for(XExpression child: children) {
			if (isIntentionalEarlyExit(child)) {
				return true;
			}
		}
	} else if (expression instanceof XIfExpression) {
		return isIntentionalEarlyExit(((XIfExpression) expression).getThen()) 
				|| isIntentionalEarlyExit(((XIfExpression) expression).getElse());
	} else if (expression instanceof XSwitchExpression) {
		XSwitchExpression switchExpression = (XSwitchExpression) expression;
		for(XCasePart caseExpression: switchExpression.getCases()) {
			if (isIntentionalEarlyExit(caseExpression.getThen())) {
				return true;
			}
		}
		if (isIntentionalEarlyExit(switchExpression.getDefault())) {
			return true;
		}
	} else if (expression instanceof XTryCatchFinallyExpression) {
		XTryCatchFinallyExpression tryCatchFinally = (XTryCatchFinallyExpression) expression;
		if (isIntentionalEarlyExit(tryCatchFinally.getExpression())) {
			for(XCatchClause catchClause: tryCatchFinally.getCatchClauses()) {
				if (!isIntentionalEarlyExit(catchClause.getExpression()))
					return false;
			}
			return true;
		}
		return false;
	} else if (expression instanceof XAbstractWhileExpression) {
		return isIntentionalEarlyExit(((XAbstractWhileExpression) expression).getBody());
	} else if (expression instanceof XForLoopExpression) {
		return isIntentionalEarlyExit(((XForLoopExpression) expression).getEachExpression());
	} else if (expression instanceof XBasicForLoopExpression) {
		return isIntentionalEarlyExit(((XBasicForLoopExpression) expression).getEachExpression());
	} else if (expression instanceof XSynchronizedExpression) {
		return isIntentionalEarlyExit(((XSynchronizedExpression) expression).getExpression());
	}
	return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
}
 
Example #19
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void computeTypes(XExpression expression, ITypeComputationState state) {
	if (expression instanceof XAssignment) {
		_computeTypes((XAssignment)expression, state);
	} else if (expression instanceof XAbstractFeatureCall) {
		_computeTypes((XAbstractFeatureCall)expression, state);
	} else if (expression instanceof XDoWhileExpression) {
		_computeTypes((XDoWhileExpression)expression, state);
	} else if (expression instanceof XWhileExpression) {
		_computeTypes((XWhileExpression)expression, state);
	} else if (expression instanceof XBlockExpression) {
		_computeTypes((XBlockExpression)expression, state);
	} else if (expression instanceof XBooleanLiteral) {
		_computeTypes((XBooleanLiteral)expression, state);
	} else if (expression instanceof XCastedExpression) {
		_computeTypes((XCastedExpression)expression, state);
	} else if (expression instanceof XClosure) {
		_computeTypes((XClosure)expression, state);
	} else if (expression instanceof XConstructorCall) {
		_computeTypes((XConstructorCall)expression, state);
	} else if (expression instanceof XForLoopExpression) {
		_computeTypes((XForLoopExpression)expression, state);
	} else if (expression instanceof XBasicForLoopExpression) {
		_computeTypes((XBasicForLoopExpression)expression, state);
	} else if (expression instanceof XIfExpression) {
		_computeTypes((XIfExpression)expression, state);
	} else if (expression instanceof XInstanceOfExpression) {
		_computeTypes((XInstanceOfExpression)expression, state);
	} else if (expression instanceof XNumberLiteral) {
		_computeTypes((XNumberLiteral)expression, state);
	} else if (expression instanceof XNullLiteral) {
		_computeTypes((XNullLiteral)expression, state);
	} else if (expression instanceof XReturnExpression) {
		_computeTypes((XReturnExpression)expression, state);
	} else if (expression instanceof XStringLiteral) {
		_computeTypes((XStringLiteral)expression, state);
	} else if (expression instanceof XSwitchExpression) {
		_computeTypes((XSwitchExpression)expression, state);
	} else if (expression instanceof XThrowExpression) {
		_computeTypes((XThrowExpression)expression, state);
	} else if (expression instanceof XTryCatchFinallyExpression) {
		_computeTypes((XTryCatchFinallyExpression)expression, state);
	} else if (expression instanceof XTypeLiteral) {
		_computeTypes((XTypeLiteral)expression, state);
	} else if (expression instanceof XVariableDeclaration) {
		_computeTypes((XVariableDeclaration)expression, state);
	} else if (expression instanceof XListLiteral) {
		_computeTypes((XListLiteral)expression, state);
	} else if (expression instanceof XSetLiteral) {
		_computeTypes((XSetLiteral)expression, state);
	} else if (expression instanceof XSynchronizedExpression) {
		_computeTypes((XSynchronizedExpression)expression, state);
	} else {
		throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state);
	}
}
 
Example #20
Source File: AbstractXbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Contexts:
 *     XExpression returns XSynchronizedExpression
 *     XAssignment returns XSynchronizedExpression
 *     XAssignment.XBinaryOperation_1_1_0_0_0 returns XSynchronizedExpression
 *     XOrExpression returns XSynchronizedExpression
 *     XOrExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XAndExpression returns XSynchronizedExpression
 *     XAndExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XEqualityExpression returns XSynchronizedExpression
 *     XEqualityExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XRelationalExpression returns XSynchronizedExpression
 *     XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XSynchronizedExpression
 *     XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XSynchronizedExpression
 *     XOtherOperatorExpression returns XSynchronizedExpression
 *     XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XAdditiveExpression returns XSynchronizedExpression
 *     XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XMultiplicativeExpression returns XSynchronizedExpression
 *     XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XSynchronizedExpression
 *     XUnaryOperation returns XSynchronizedExpression
 *     XCastedExpression returns XSynchronizedExpression
 *     XCastedExpression.XCastedExpression_1_0_0_0 returns XSynchronizedExpression
 *     XPostfixOperation returns XSynchronizedExpression
 *     XPostfixOperation.XPostfixOperation_1_0_0 returns XSynchronizedExpression
 *     XMemberFeatureCall returns XSynchronizedExpression
 *     XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XSynchronizedExpression
 *     XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XSynchronizedExpression
 *     XPrimaryExpression returns XSynchronizedExpression
 *     XParenthesizedExpression returns XSynchronizedExpression
 *     XExpressionOrVarDeclaration returns XSynchronizedExpression
 *     XSynchronizedExpression returns XSynchronizedExpression
 *
 * Constraint:
 *     (param=XExpression expression=XExpression)
 */
protected void sequence_XSynchronizedExpression(ISerializationContext context, XSynchronizedExpression semanticObject) {
	if (errorAcceptor != null) {
		if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__PARAM) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__PARAM));
		if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__EXPRESSION) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__EXPRESSION));
	}
	SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
	feeder.accept(grammarAccess.getXSynchronizedExpressionAccess().getParamXExpressionParserRuleCall_1_0(), semanticObject.getParam());
	feeder.accept(grammarAccess.getXSynchronizedExpressionAccess().getExpressionXExpressionParserRuleCall_3_0(), semanticObject.getExpression());
	feeder.finish();
}
 
Example #21
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** 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(XSynchronizedExpression expression, ISideEffectContext context) {
	return hasSideEffects(expression.getExpression(), context);
}
 
Example #22
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Generate the given object.
 *
 * @param synchronizedStatement the synchronized statement.
 * @param it the target for the generated content.
 * @param context the context.
 * @return the statement.
 */
protected XExpression _generate(XSynchronizedExpression synchronizedStatement, IAppendable it, IExtraLanguageGeneratorContext context) {
	return generate(synchronizedStatement.getExpression(), context.getExpectedExpressionType(), it, context);
}