当前位置: 首页>>代码示例>>Java>>正文


Java XInstanceOfExpression类代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.XInstanceOfExpression的典型用法代码示例。如果您正苦于以下问题:Java XInstanceOfExpression类的具体用法?Java XInstanceOfExpression怎么用?Java XInstanceOfExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XInstanceOfExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XInstanceOfExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _computeTypes

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
protected void _computeTypes(XInstanceOfExpression object, ITypeComputationState state) {
	ITypeComputationState expressionState = state.withExpectation(state.getReferenceOwner().newReferenceToObject());
	expressionState.computeTypes(object.getExpression());
	JvmTypeReference type = object.getType();
	if (type != null && type.getType() instanceof JvmTypeParameter) {
		LightweightTypeReference lightweightReference = state.getReferenceOwner().toLightweightTypeReference(type);
		LightweightTypeReference rawTypeRef = lightweightReference.getRawTypeReference();
		state.addDiagnostic(new EObjectDiagnosticImpl(
				Severity.ERROR,
				IssueCodes.INVALID_USE_OF_TYPE_PARAMETER,
				"Cannot perform instanceof check against type parameter "+lightweightReference.getHumanReadableName()+". Use its erasure "+rawTypeRef.getHumanReadableName()+" instead since further generic type information will be erased at runtime.",
				object.getType(),
				null,
				-1,
				new String[] { 
				}));
	}
	LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state);
	state.acceptActualType(bool);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:XbaseTypeComputer.java

示例2: testSerialize_01

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@Test public void testSerialize_01() throws Exception {
	Resource resource = newResource("'foo' as String");
	XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);
	
	XbaseFactory factory = XbaseFactory.eINSTANCE;
	XClosure closure = factory.createXClosure();
	XStringLiteral stringLiteral = factory.createXStringLiteral();
	stringLiteral.setValue("value");
	XBlockExpression blockExpression = factory.createXBlockExpression();
	blockExpression.getExpressions().add(stringLiteral);
	closure.setExpression(blockExpression);
	closure.setExplicitSyntax(true);
	XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
	instanceOfExpression.setExpression(closure);
	instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
	resource.getContents().clear();
	resource.getContents().add(instanceOfExpression);
	ISerializer serializer = get(ISerializer.class);
	String string = serializer.serialize(instanceOfExpression);
	assertEquals("[|\"value\"] instanceof String", string);
	
	XInstanceOfExpression parsedExpression = parseHelper.parse(string);
	assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:25,代码来源:SerializerTest.java

示例3: testSerialize_02

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@Test public void testSerialize_02() throws Exception {
	Resource resource = newResource("'foo' as String");
	XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);
	
	XbaseFactory factory = XbaseFactory.eINSTANCE;
	XIfExpression ifExpression = factory.createXIfExpression();
	ifExpression.setIf(factory.createXBooleanLiteral());
	XStringLiteral stringLiteral = factory.createXStringLiteral();
	stringLiteral.setValue("value");
	ifExpression.setThen(stringLiteral);
	XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
	instanceOfExpression.setExpression(ifExpression);
	instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
	resource.getContents().clear();
	resource.getContents().add(instanceOfExpression);
	ISerializer serializer = get(ISerializer.class);
	String string = serializer.serialize(instanceOfExpression);
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=464846
	assertEquals("( if(false) \"value\" ) instanceof String", string);
	
	XInstanceOfExpression parsedExpression = parseHelper.parse(string);
	assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:SerializerTest.java

示例4: checkInstanceOf

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@Check
public void checkInstanceOf(XInstanceOfExpression instanceOfExpression) {
	LightweightTypeReference leftType = getActualType(instanceOfExpression.getExpression());
	final LightweightTypeReference rightType = toLightweightTypeReference(instanceOfExpression.getType(), true);
	if (leftType == null || rightType == null || rightType.getType() == null || rightType.getType().eIsProxy()) {
		return;
	}
	if (containsTypeArgs(rightType)) {
		error("Cannot perform instanceof check against parameterized type " + getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
		return;
	}
	if (leftType.isAny() || leftType.isUnknown()) {
		return; // null / unknown is ok
	}
	if (rightType.isPrimitive()) {
		error("Cannot perform instanceof check against primitive type " + this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
		return;
	}
	if (leftType.isPrimitive() 
		|| rightType.isArray() && !(leftType.isArray() || leftType.isType(Object.class) || leftType.isType(Cloneable.class) || leftType.isType(Serializable.class))
		|| isFinal(rightType) && !memberOfTypeHierarchy(rightType, leftType)
		|| isFinal(leftType) && !memberOfTypeHierarchy(leftType, rightType)) {
		error("Incompatible conditional operand types " + this.getNameOfTypes(leftType)+" and "+this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
		return;
	}
	if (!isIgnored(OBSOLETE_INSTANCEOF) && rightType.isAssignableFrom(leftType, new TypeConformanceComputationArgument(false, false, true, true, false, false))) {
		addIssueToState(OBSOLETE_INSTANCEOF, "The expression of type " + getNameOfTypes(leftType)
				+ " is already of type " + canonicalName(rightType), null);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:31,代码来源:XbaseValidator.java

示例5: reassignCheckedType

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
/**
 * If the condition is a {@link XInstanceOfExpression type check}, the checked expression
 * will be automatically casted in the returned state.
 */
protected ITypeComputationState reassignCheckedType(XExpression condition, /* @Nullable */ XExpression guardedExpression, ITypeComputationState state) {
	if (condition instanceof XInstanceOfExpression) {
		XInstanceOfExpression instanceOfExpression = (XInstanceOfExpression) condition;
		JvmTypeReference castedType = instanceOfExpression.getType();
		if (castedType != null) {
			state = state.withTypeCheckpoint(guardedExpression);
			JvmIdentifiableElement refinable = getRefinableCandidate(instanceOfExpression.getExpression(), state);
			if (refinable != null) {
				state.reassignType(refinable, state.getReferenceOwner().toLightweightTypeReference(castedType));
			}
		}
	}
	return state;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:XbaseTypeComputer.java

示例6: internalToConvertedExpression

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:35,代码来源:XbaseCompiler.java

示例7: _toJavaExpression

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
protected void _toJavaExpression(XInstanceOfExpression expr, ITreeAppendable b) {
	b.append("(");
	internalToJavaExpression(expr.getExpression(), b);
	b.append(" instanceof ");
	serialize(expr.getType(), expr, b);
	b.append(")");
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:XbaseCompiler.java

示例8: _doEvaluate

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
protected Object _doEvaluate(XInstanceOfExpression instanceOf, IEvaluationContext context, CancelIndicator indicator) {
	Object instance = internalEvaluate(instanceOf.getExpression(), context, indicator);
	if (instance == null)
		return Boolean.FALSE;

	Class<?> expectedType = null;
	String className = instanceOf.getType().getType().getQualifiedName();
	try {
		expectedType = classFinder.forName(className);
	} catch (ClassNotFoundException cnfe) {
		throw new EvaluationException(new NoClassDefFoundError(className));
	}
	return expectedType.isInstance(instance);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:XbaseInterpreter.java

示例9: _format

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
protected void _format(final XInstanceOfExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  doc.surround(this.textRegionExtensions.regionFor(expr).keyword("instanceof"), _function);
  doc.<XExpression>format(expr.getExpression());
  doc.<JvmTypeReference>format(expr.getType());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseFormatter.java

示例10: sequence_XRelationalExpression

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
/**
 * Constraint:
 *     (expression=XRelationalExpression_XInstanceOfExpression_1_0_0_0_0 type=JvmTypeReference)
 */
protected void sequence_XRelationalExpression(EObject context, XInstanceOfExpression semanticObject) {
	if(errorAcceptor != null) {
		if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XINSTANCE_OF_EXPRESSION__TYPE) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XINSTANCE_OF_EXPRESSION__TYPE));
		if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XINSTANCE_OF_EXPRESSION__EXPRESSION) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XINSTANCE_OF_EXPRESSION__EXPRESSION));
	}
	INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
	SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
	feeder.accept(grammarAccess.getXRelationalExpressionAccess().getXInstanceOfExpressionExpressionAction_1_0_0_0_0(), semanticObject.getExpression());
	feeder.accept(grammarAccess.getXRelationalExpressionAccess().getTypeJvmTypeReferenceParserRuleCall_1_0_1_0(), semanticObject.getType());
	feeder.finish();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:18,代码来源:AbstractCheckSemanticSequencer.java

示例11: sequence_XRelationalExpression

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@Deprecated
protected void sequence_XRelationalExpression(EObject context, XInstanceOfExpression semanticObject) {
	sequence_XRelationalExpression(createContext(context, semanticObject), semanticObject);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:5,代码来源:AbstractXbaseSemanticSequencer.java

示例12: checkInstanceOfOrder

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@Check
public void checkInstanceOfOrder(XIfExpression expression) {
	if (isIgnored(IssueCodes.UNREACHABLE_IF_BLOCK)) {
		return;
	}
	if (expression.eContainer() instanceof XIfExpression) {
		XIfExpression container = (XIfExpression) expression.eContainer();
		if (container.getElse() == expression) {
			return;
		}
	}
	List<XExpression> ifParts = collectIfParts(expression, new ArrayList<XExpression>());
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
	Multimap<JvmIdentifiableElement, LightweightTypeReference> previousTypeReferences = HashMultimap.create();
	for (XExpression ifPart : ifParts) {
		if (!(ifPart instanceof XInstanceOfExpression)) {
			continue;
		}
		XInstanceOfExpression instanceOfExpression = (XInstanceOfExpression) ifPart;
		if (!(instanceOfExpression.getExpression() instanceof XAbstractFeatureCall)) {
			continue;
		}
		XAbstractFeatureCall featureCall = (XAbstractFeatureCall) instanceOfExpression.getExpression();
		JvmIdentifiableElement feature = featureCall.getFeature();
		if (!(feature instanceof XVariableDeclaration)
				&& !(feature instanceof JvmField)
				&& !(feature instanceof JvmFormalParameter)) {
			continue;
		}
		JvmTypeReference type = instanceOfExpression.getType();
		LightweightTypeReference actualType = owner.toLightweightTypeReference(type);
		if (actualType == null) {
			continue;
		}
		if (isHandled(actualType, previousTypeReferences.get(feature))) {
			addIssue("Unreachable code: The if condition can never match. It is already handled by a previous condition.", type, IssueCodes.UNREACHABLE_IF_BLOCK);
			continue;
		}
		previousTypeReferences.put(feature, actualType);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:42,代码来源:XbaseValidator.java

示例13: computeTypes

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:57,代码来源:XbaseTypeComputer.java

示例14: doInternalToJavaStatement

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:43,代码来源:XbaseCompiler.java

示例15: _toJavaStatement

import org.eclipse.xtext.xbase.XInstanceOfExpression; //导入依赖的package包/类
/**
 * @param isReferenced unused in this context but necessary for dispatch signature 
 */
protected void _toJavaStatement(XInstanceOfExpression expr, ITreeAppendable b, boolean isReferenced) {
	internalToJavaStatement(expr.getExpression(), b, true);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:7,代码来源:XbaseCompiler.java


注:本文中的org.eclipse.xtext.xbase.XInstanceOfExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。