Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.Binding#VARIABLE

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.Binding#VARIABLE . 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: TypeMirrorImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public TypeKind getKind() {
	switch (_binding.kind()) {
	// case Binding.TYPE: 
	// case Binding.RAW_TYPE:
	// case Binding.GENERIC_TYPE:
	// case Binding.PARAMETERIZED_TYPE:
	// handled by DeclaredTypeImpl, etc.
	// case Binding.BASE_TYPE: handled by PrimitiveTypeImpl
	// case Binding.METHOD: handled by ExecutableTypeImpl
	// case Binding.PACKAGE: handled by NoTypeImpl
	// case Binding.WILDCARD_TYPE: handled by WildcardTypeImpl
	// case Binding.ARRAY_TYPE: handled by ArrayTypeImpl
	// case Binding.TYPE_PARAMETER: handled by TypeVariableImpl
	// TODO: fill in the rest of these
	case Binding.FIELD:
	case Binding.LOCAL:
	case Binding.VARIABLE:
	case Binding.IMPORT:
		throw new IllegalArgumentException("Invalid binding kind: " + _binding.kind()); //$NON-NLS-1$
	}
	return null;
}
 
Example 2
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new element that knows what kind it is even if the binding is unresolved.
 */
public Element newElement(Binding binding, ElementKind kindHint) {
	if (binding == null)
		return null;
	switch (binding.kind()) {
	case Binding.FIELD:
	case Binding.LOCAL:
	case Binding.VARIABLE:
		return new VariableElementImpl(_env, (VariableBinding) binding);
	case Binding.TYPE:
	case Binding.GENERIC_TYPE:
		ReferenceBinding referenceBinding = (ReferenceBinding)binding;
		if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) {
			return new ErrorTypeElement(this._env, referenceBinding);
		}
		if (CharOperation.equals(referenceBinding.sourceName, TypeConstants.PACKAGE_INFO_NAME)) {
			return new PackageElementImpl(_env, referenceBinding.fPackage);
		}
		return new TypeElementImpl(_env, referenceBinding, kindHint);
	case Binding.METHOD:
		return new ExecutableElementImpl(_env, (MethodBinding)binding);
	case Binding.RAW_TYPE:
	case Binding.PARAMETERIZED_TYPE:
		return new TypeElementImpl(_env, ((ParameterizedTypeBinding)binding).genericType(), kindHint);
	case Binding.PACKAGE:
		return new PackageElementImpl(_env, (PackageBinding)binding);
	case Binding.TYPE_PARAMETER:
		return new TypeParameterElementImpl(_env, (TypeVariableBinding)binding);
		// TODO: fill in the rest of these
	case Binding.IMPORT:
	case Binding.ARRAY_TYPE:
	case Binding.BASE_TYPE:
	case Binding.WILDCARD_TYPE:
	case Binding.INTERSECTION_TYPE:
		throw new UnsupportedOperationException("NYI: binding type " + binding.kind()); //$NON-NLS-1$
	}
	return null;
}
 
Example 3
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Given a binding of uncertain type, try to create the right sort of TypeMirror for it.
 */
public TypeMirror newTypeMirror(Binding binding) {
	switch (binding.kind()) {
	case Binding.FIELD:
	case Binding.LOCAL:
	case Binding.VARIABLE:
		// For variables, return the type of the variable
		return newTypeMirror(((VariableBinding)binding).type);
		
	case Binding.PACKAGE:
		return getNoType(TypeKind.PACKAGE);
		
	case Binding.IMPORT:
		throw new UnsupportedOperationException("NYI: import type " + binding.kind()); //$NON-NLS-1$

	case Binding.METHOD:
		return new ExecutableTypeImpl(_env, (MethodBinding) binding);
		
	case Binding.TYPE:
	case Binding.RAW_TYPE:
	case Binding.GENERIC_TYPE:
	case Binding.PARAMETERIZED_TYPE:
		ReferenceBinding referenceBinding = (ReferenceBinding) binding;
		if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) {
			return getErrorType(referenceBinding);
		}
		return new DeclaredTypeImpl(_env, (ReferenceBinding)binding);
		
	case Binding.ARRAY_TYPE:
		return new ArrayTypeImpl(_env, (ArrayBinding)binding);
		
	case Binding.BASE_TYPE:
		BaseTypeBinding btb = (BaseTypeBinding)binding;
		switch (btb.id) {
			case TypeIds.T_void:
				return getNoType(TypeKind.VOID);
			case TypeIds.T_null:
				return getNullType();
			default:
				return getPrimitiveType(btb);
		}

	case Binding.WILDCARD_TYPE:
	case Binding.INTERSECTION_TYPE: // TODO compatible, but shouldn't it really be an intersection type?
		return new WildcardTypeImpl(_env, (WildcardBinding) binding);

	case Binding.TYPE_PARAMETER:
		return new TypeVariableImpl(_env, (TypeVariableBinding) binding);
	}
	return null;
}
 
Example 4
Source File: CodeSnippetQualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
	int pc = codeStream.position;
	if ((this.bits & Binding.VARIABLE) == 0) { // nothing to do if type ref
		codeStream.recordPositionsFrom(pc, this.sourceStart);
		return;
	}
	FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1];
	if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) {
		super.generateCode(currentScope, codeStream, valueRequired);
		return;
	}
	lastFieldBinding = generateReadSequence(currentScope, codeStream);
	if (lastFieldBinding != null) {
		boolean isStatic = lastFieldBinding.isStatic();
		Constant fieldConstant = lastFieldBinding.constant();
		if (fieldConstant != Constant.NotAConstant) {
			if (!isStatic){
				codeStream.invokeObjectGetClass();
				codeStream.pop();
			}
			if (valueRequired) { // inline the last field constant
				codeStream.generateConstant(fieldConstant, this.implicitConversion);
			}
		} else {
			boolean isFirst = lastFieldBinding == this.binding
											&& (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType()))
											&& this.otherBindings == null; // could be dup: next.next.next
			TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
			if (valueRequired
					|| (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
					|| ((this.implicitConversion & TypeIds.UNBOXING) != 0)
					|| requiredGenericCast != null) {
				int lastFieldPc = codeStream.position;
				if (lastFieldBinding.declaringClass == null) { // array length
					codeStream.arraylength();
					if (valueRequired) {
						codeStream.generateImplicitConversion(this.implicitConversion);
					} else {
						// could occur if !valueRequired but compliance >= 1.4
						codeStream.pop();
					}
				} else {
					codeStream.generateEmulatedReadAccessForField(lastFieldBinding);
					if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
					if (valueRequired) {
						codeStream.generateImplicitConversion(this.implicitConversion);
					} else {
						boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
						// conversion only generated if unboxing
						if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
						switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) {
							case T_long :
							case T_double :
								codeStream.pop2();
								break;
							default :
								codeStream.pop();
						}
					}
				}

				int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32);
				codeStream.recordPositionsFrom(lastFieldPc, fieldPosition);
			} else {
				if (!isStatic){
					codeStream.invokeObjectGetClass(); // perform null check
					codeStream.pop();
				}
			}
		}
	}
	codeStream.recordPositionsFrom(pc, this.sourceStart);
}