Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeBinding#VOID

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.TypeBinding#VOID . 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: BindingKeyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private TypeBinding getBaseTypeBinding(char[] signature) {
	switch (signature[0]) {
		case 'I' :
			return TypeBinding.INT;
		case 'Z' :
			return TypeBinding.BOOLEAN;
		case 'V' :
			return TypeBinding.VOID;
		case 'C' :
			return TypeBinding.CHAR;
		case 'D' :
			return TypeBinding.DOUBLE;
		case 'B' :
			return TypeBinding.BYTE;
		case 'F' :
			return TypeBinding.FLOAT;
		case 'J' :
			return TypeBinding.LONG;
		case 'S' :
			return TypeBinding.SHORT;
		case 'N':
			return TypeBinding.NULL;
		default :
			return null;
	}
}
 
Example 2
Source File: CodeSnippetReturnStatement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void generateStoreSaveValueIfNecessary(CodeStream codeStream){

	// push receiver
	codeStream.aload_0();

	// push the 2 parameters of "setResult(Object, Class)"
	if (this.expression == null || this.expression.resolvedType == TypeBinding.VOID) { // expressionType == VoidBinding if code snippet is the expression "System.out.println()"
		// push null
		codeStream.aconst_null();

		// void.class
		codeStream.generateClassLiteralAccessForType(TypeBinding.VOID, null);
	} else {
		// swap with expression
		int valueTypeID = this.expression.resolvedType.id;
		if (valueTypeID == T_long || valueTypeID == T_double) {
			codeStream.dup_x2();
			codeStream.pop();
		} else {
			codeStream.swap();
		}

		// generate wrapper if needed
		if (this.expression.resolvedType.isBaseType() && this.expression.resolvedType != TypeBinding.NULL) {
			codeStream.generateBoxingConversion(this.expression.resolvedType.id);
		}

		// generate the expression type
		codeStream.generateClassLiteralAccessForType(this.expression.resolvedType, null);
	}

	// generate the invoke virtual to "setResult(Object,Class)"
	codeStream.invoke(Opcodes.OPC_invokevirtual, this.setResultMethod, null /* default declaringClass */);
}
 
Example 3
Source File: BindingKeyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private TypeBinding getType(char[] type) {
	TypeBinding binding = null;
	int length = type.length;
	switch(length) {
		case 1 :
			switch (type[0]) {
				case 'I' :
					binding = TypeBinding.INT;
					break;
				case 'Z' :
					binding = TypeBinding.BOOLEAN;
					break;
				case 'V' :
					binding = TypeBinding.VOID;
					break;
				case 'C' :
					binding = TypeBinding.CHAR;
					break;
				case 'D' :
					binding = TypeBinding.DOUBLE;
					break;
				case 'B' :
					binding = TypeBinding.BYTE;
					break;
				case 'F' :
					binding = TypeBinding.FLOAT;
					break;
				case 'J' :
					binding = TypeBinding.LONG;
					break;
				case 'S' :
					binding = TypeBinding.SHORT;
					break;
			}
			break;
		default:
			int dimensions = 0;
			int start = 0;
			while (type[start] == '[') {
				start++;
				dimensions++;
			}
			binding = this.environment.getType(CharOperation.splitOn('/', type, start + 1, length - 1));
			if (dimensions != 0) {
				binding = this.environment.createArrayType(binding, dimensions);
			}
	}
	return binding;
}
 
Example 4
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, final FlowInfo flowInfo) {
	
	if (this.ignoreFurtherInvestigation) 
		return flowInfo;
	
	FlowInfo lambdaInfo = flowInfo.copy(); // what happens in vegas, stays in vegas ...
	ExceptionHandlingFlowContext methodContext =
			new ExceptionHandlingFlowContext(
					flowContext,
					this,
					this.binding.thrownExceptions,
					null,
					this.scope,
					FlowInfo.DEAD_END);

	// nullity and mark as assigned
	MethodBinding methodWithParameterDeclaration = argumentsTypeElided() ? this.descriptor : this.binding;
	AbstractMethodDeclaration.analyseArguments18(lambdaInfo, this.arguments, methodWithParameterDeclaration);

	if (this.arguments != null) {
		for (int i = 0, count = this.arguments.length; i < count; i++) {
			this.bits |= (this.arguments[i].bits & ASTNode.HasTypeAnnotations);
		}
	}
	
	lambdaInfo = this.body.analyseCode(this.scope, methodContext, lambdaInfo);
	
	// check for missing returning path for block body's ...
	if (this.body instanceof Block) {
		TypeBinding returnTypeBinding = expectedResultType();
		if ((returnTypeBinding == TypeBinding.VOID)) {
			if ((lambdaInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0 || ((Block) this.body).statements == null) {
				this.bits |= ASTNode.NeedFreeReturn;
			}
		} else {
			if (lambdaInfo != FlowInfo.DEAD_END) {
				this.scope.problemReporter().shouldReturn(returnTypeBinding, this);
			}
		}
	} else { // Expression
		if (currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled 
				&& lambdaInfo.reachMode() == FlowInfo.REACHABLE)
		{
			Expression expression = (Expression)this.body;
			checkAgainstNullAnnotation(flowContext, expression, expression.nullStatus(lambdaInfo, flowContext));
		}
	}
	return flowInfo;
}
 
Example 5
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get a resolved copy of this lambda for use by type inference, as to avoid spilling any premature
 * type results into the original lambda.
 * 
 * @param targetType the target functional type against which inference is attempted, must be a non-null valid functional type 
 * @return a resolved copy of 'this' or null if significant errors where encountered
 */
public LambdaExpression getResolvedCopyForInferenceTargeting(TypeBinding targetType) {
	// note: this is essentially a simplified extract from isCompatibleWith(TypeBinding,Scope).
	if (this.shapeAnalysisComplete && this.binding != null)
		return this;
	
	targetType = targetType.uncapture(this.enclosingScope);
	// TODO: caching
	IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
	final CompilerOptions compilerOptions = this.enclosingScope.compilerOptions();
	boolean analyzeNPE = compilerOptions.isAnnotationBasedNullAnalysisEnabled;
	final LambdaExpression copy = copy();
	if (copy == null) {
		return null;
	}
	try {
		compilerOptions.isAnnotationBasedNullAnalysisEnabled = false;
		copy.setExpressionContext(this.expressionContext);
		copy.setExpectedType(targetType);
		this.hasIgnoredMandatoryErrors = false;
		TypeBinding type = copy.resolveType(this.enclosingScope);
		if (type == null || !type.isValidBinding())
			return null;
		if (this.body instanceof Block) {
			if (copy.returnsVoid) {
				copy.shapeAnalysisComplete = true;
			} else {
				copy.valueCompatible = this.returnsValue;
			}
		} else {
			copy.voidCompatible = ((Expression) this.body).statementExpression();
			TypeBinding resultType = ((Expression) this.body).resolvedType;
			if (resultType == null) // case of a yet-unresolved poly expression?
				copy.valueCompatible = true;
			else
				copy.valueCompatible = (resultType != TypeBinding.VOID);
			copy.shapeAnalysisComplete = true;
		}
		// Do not proceed with data/control flow analysis if resolve encountered errors.
		if (!this.hasIgnoredMandatoryErrors && !enclosingScopesHaveErrors()) {
			// value compatibility of block lambda's is the only open question.
			if (!copy.shapeAnalysisComplete)
				copy.valueCompatible = copy.doesNotCompleteNormally();
		} else {
			if (!copy.returnsVoid)
				copy.valueCompatible = true; // optimistically, TODO: is this OK??
		}
		
		copy.shapeAnalysisComplete = true;
		copy.resultExpressions = this.resultExpressions;
		this.resultExpressions = NO_EXPRESSIONS;
	} finally {
		compilerOptions.isAnnotationBasedNullAnalysisEnabled = analyzeNPE;
		this.hasIgnoredMandatoryErrors = false;
		this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
	}
	return copy;
}