本文整理汇总了Java中org.eclipse.xtext.xbase.XVariableDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java XVariableDeclaration类的具体用法?Java XVariableDeclaration怎么用?Java XVariableDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XVariableDeclaration类属于org.eclipse.xtext.xbase包,在下文中一共展示了XVariableDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeName
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
public static String getTypeName(JvmIdentifiableElement feature) {
if (feature instanceof JvmFormalParameter) {
return "parameter";
}
if (feature instanceof XVariableDeclaration) {
return "local variable";
}
if (feature instanceof JvmEnumerationLiteral) {
return "enum literal";
}
if (feature instanceof JvmField) {
return "field";
}
if (feature instanceof JvmOperation) {
return "method";
}
if (feature instanceof JvmConstructor) {
return "constructor";
}
if (feature instanceof JvmType) {
return "type";
}
throw new IllegalStateException();
}
示例2: createFeatureCallSerializationScope
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
public IScope createFeatureCallSerializationScope(EObject context) {
if (!(context instanceof XAbstractFeatureCall)) {
return IScope.NULLSCOPE;
}
XAbstractFeatureCall call = (XAbstractFeatureCall) context;
JvmIdentifiableElement feature = call.getFeature();
// this and super - logical container aware FeatureScopes
if (feature instanceof JvmType) {
return getTypeScope(call, (JvmType) feature);
}
if (feature instanceof JvmConstructor) {
return getThisOrSuperScope(call, (JvmConstructor) feature);
}
if (feature instanceof JvmExecutable) {
return getExecutableScope(call, feature);
}
if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) {
return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE);
}
return IScope.NULLSCOPE;
}
示例3: appendVariableTypeAndName
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
protected LightweightTypeReference appendVariableTypeAndName(XVariableDeclaration varDeclaration, ITreeAppendable appendable) {
if (!varDeclaration.isWriteable()) {
appendable.append("final ");
}
LightweightTypeReference type = null;
if (varDeclaration.getType() != null) {
serialize(varDeclaration.getType(), varDeclaration, appendable);
type = getLightweightType((JvmIdentifiableElement) varDeclaration);
} else {
type = getLightweightType(varDeclaration.getRight());
if (type.isAny()) {
type = getTypeForVariableDeclaration(varDeclaration.getRight());
}
appendable.append(type);
}
appendable.append(" ");
appendable.append(appendable.declareVariable(varDeclaration, makeJavaIdentifier(varDeclaration.getName())));
return type;
}
示例4: testXVariableDeclarationCall
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
@Test
public void testXVariableDeclarationCall() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("val foo = 1");
_builder.newLine();
_builder.append("\t");
_builder.append("val bar = foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
XExpression _expression = this.expression(_builder);
final XBlockExpression blockExpression = ((XBlockExpression) _expression);
XExpression _get = blockExpression.getExpressions().get(1);
final XVariableDeclaration variableDeclaration = ((XVariableDeclaration) _get);
this.evaluatesTo(variableDeclaration, Integer.valueOf(1));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例5: createVarFeatures
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
private Collection<? extends IEObjectDescription> createVarFeatures(Resource resource) {
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
if(resource.getContents().size()>0 && resource.getContents().get(0) instanceof RuleModel) {
RuleModel ruleModel = (RuleModel) resource.getContents().get(0);
for(XExpression expr : ruleModel.getVariables()) {
if (expr instanceof XVariableDeclaration) {
XVariableDeclaration var = (XVariableDeclaration) expr;
if(var.getName()!=null && var.getType()!=null) {
descriptions.add(createLocalVarDescription(var));
}
}
}
}
return descriptions;
}
示例6: typeImpl
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
protected Result<JvmTypeReference> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final XVariableDeclaration e) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<JvmTypeReference> _result_ = applyRuleXVariableDeclarationType(G, _subtrace_, e);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("XVariableDeclarationType") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleXVariableDeclarationType) {
typeThrowException(ruleName("XVariableDeclarationType") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + "JvmTypeReference",
XVARIABLEDECLARATIONTYPE,
e_applyRuleXVariableDeclarationType, e, new ErrorInformation[] {new ErrorInformation(e)});
return null;
}
}
示例7: checkVariableIsNotInferredAsVoid
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
@Check
public void checkVariableIsNotInferredAsVoid(XVariableDeclaration declaration) {
if (declaration.getType() != null)
return;
LightweightTypeReference variableType = typeResolver.resolveTypes(declaration).getActualType((JvmIdentifiableElement) declaration);
// TODO move to type resolver
if (variableType != null && variableType.isPrimitiveVoid()) {
error("void is an invalid type for the variable " + declaration.getName(), declaration,
XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, INVALID_USE_OF_TYPE);
}
}
示例8: checkVariableDeclaration
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
@Check
public void checkVariableDeclaration(XVariableDeclaration declaration) {
if (declaration.getRight() == null) {
if (!declaration.isWriteable())
error("Value must be initialized", Literals.XVARIABLE_DECLARATION__WRITEABLE,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_INITIALIZATION);
if (declaration.getType() == null)
error("Type cannot be derived", Literals.XVARIABLE_DECLARATION__NAME,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_TYPE);
}
}
示例9: checkLocalUsageOfDeclared
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
@Check
public void checkLocalUsageOfDeclared(XVariableDeclaration variableDeclaration) {
if(!isIgnored(UNUSED_LOCAL_VARIABLE) && !isLocallyUsed(variableDeclaration, variableDeclaration.eContainer())){
String message = "The value of the local variable " + variableDeclaration.getName() + " is not used";
addIssueToState(UNUSED_LOCAL_VARIABLE, message, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME);
}
}
示例10: checkAssignment
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) {
if (!(expression instanceof XAbstractFeatureCall)) {
error("The left-hand side of an assignment must be a variable", expression, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
return;
}
XAbstractFeatureCall assignment = (XAbstractFeatureCall) expression;
JvmIdentifiableElement assignmentFeature = assignment.getFeature();
if (assignmentFeature instanceof XVariableDeclaration) {
XVariableDeclaration variableDeclaration = (XVariableDeclaration) assignmentFeature;
if (variableDeclaration.isWriteable()) {
return;
}
error("Assignment to final variable", expression, feature,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
} else if (assignmentFeature instanceof JvmFormalParameter) {
error("Assignment to final parameter", expression, feature,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
} else if (assignmentFeature instanceof JvmField) {
JvmField field = (JvmField) assignmentFeature;
if (!field.isFinal()) {
return;
}
if (simpleAssignment) {
JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(assignment);
// don't issue an error if it's an assignment of a local final field within a constructor.
if (container != null && container instanceof JvmConstructor) {
JvmConstructor constructor = (JvmConstructor) container;
if (field.getDeclaringType() == constructor.getDeclaringType())
return;
}
}
error("Assignment to final field", expression, feature,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
} else if (!simpleAssignment) {
error("The left-hand side of an assignment must be a variable", expression, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
}
}
示例11: getInvalidWritableVariableAccessMessage
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
/**
* Provide the error message for mutable variables that may not be captured in lambdas.
*
* @param variable the writable variable declaration
* @param featureCall the reference to the variable
* @param resolvedTypes type information
*/
protected String getInvalidWritableVariableAccessMessage(XVariableDeclaration variable, XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes) {
// TODO this should be part of a separate validation service
XClosure containingClosure = EcoreUtil2.getContainerOfType(featureCall, XClosure.class);
if (containingClosure != null && !EcoreUtil.isAncestor(containingClosure, variable)) {
return String.format("Cannot %srefer to the non-final variable %s inside a lambda expression", getImplicitlyMessagePart(featureCall), variable.getSimpleName());
}
return null;
}
示例12: mustDiscardRefinement
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
protected boolean mustDiscardRefinement() {
Expression expression = getExpression();
if (expression instanceof XAssignment) {
JvmIdentifiableElement feature = getFeature();
if (feature instanceof XVariableDeclaration) {
return ((XVariableDeclaration) feature).isWriteable();
}
if (feature instanceof JvmField) {
return !((JvmField) feature).isFinal();
}
}
return false;
}
示例13: getSimpleName
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
public /* @Nullable */ String getSimpleName(JvmIdentifiableElement element) {
if (element == null || element.eIsProxy()) {
return null;
}
if (element instanceof JvmFeature) {
return ((JvmFeature) element).getSimpleName();
}
if (element instanceof JvmFormalParameter) {
return ((JvmFormalParameter) element).getName();
}
if (element instanceof XVariableDeclaration) {
return ((XVariableDeclaration) element).getName();
}
return element.getSimpleName();
}
示例14: _toJavaStatement
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
/**
* @param isReferenced unused in this context but necessary for dispatch signature
*/
protected void _toJavaStatement(XVariableDeclaration varDeclaration, ITreeAppendable b, boolean isReferenced) {
if (varDeclaration.getRight() != null) {
internalToJavaStatement(varDeclaration.getRight(), b, true);
}
b.newLine();
LightweightTypeReference type = appendVariableTypeAndName(varDeclaration, b);
b.append(" = ");
if (varDeclaration.getRight() != null) {
internalToConvertedExpression(varDeclaration.getRight(), b, type);
} else {
appendDefaultLiteral(b, type);
}
b.append(";");
}
示例15: _doEvaluate
import org.eclipse.xtext.xbase.XVariableDeclaration; //导入依赖的package包/类
protected Object _doEvaluate(XVariableDeclaration variableDecl, IEvaluationContext context, CancelIndicator indicator) {
Object initialValue = null;
if (variableDecl.getRight()!=null) {
initialValue = internalEvaluate(variableDecl.getRight(), context, indicator);
} else {
if (services.getPrimitives().isPrimitive(variableDecl.getType())) {
Primitive primitiveKind = services.getPrimitives().primitiveKind((JvmPrimitiveType) variableDecl.getType().getType());
switch(primitiveKind) {
case Boolean:
initialValue = Boolean.FALSE; break;
case Char:
initialValue = Character.valueOf((char) 0); break;
case Double:
initialValue = Double.valueOf(0d); break;
case Byte:
initialValue = Byte.valueOf((byte) 0); break;
case Float:
initialValue = Float.valueOf(0f); break;
case Int:
initialValue = Integer.valueOf(0); break;
case Long:
initialValue = Long.valueOf(0L); break;
case Short:
initialValue = Short.valueOf((short) 0); break;
case Void:
throw new IllegalStateException("Void is not a valid variable type.");
default:
throw new IllegalStateException("Unknown primitive type " + primitiveKind);
}
}
}
context.newValue(QualifiedName.create(variableDecl.getName()), initialValue);
return null;
}