本文整理汇总了Java中org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isEnum方法的典型用法代码示例。如果您正苦于以下问题:Java TypeBinding.isEnum方法的具体用法?Java TypeBinding.isEnum怎么用?Java TypeBinding.isEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.lookup.TypeBinding
的用法示例。
在下文中一共展示了TypeBinding.isEnum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getApplicableExtensionMethods
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
List<Extension> extensions = new ArrayList<Extension>();
if ((typeNode != null) && (ann != null) && (receiverType != null)) {
BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
EclipseNode annotationNode = typeNode.getNodeFor(ann);
AnnotationValues<ExtensionMethod> annotation = createAnnotation(ExtensionMethod.class, annotationNode);
boolean suppressBaseMethods = false;
try {
suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
} catch (AnnotationValueDecodeFail fail) {
fail.owner.setError(fail.getMessage(), fail.idx);
}
for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
if (extensionMethodProvider instanceof ClassLiteralAccess) {
TypeBinding binding = ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
if (binding == null) continue;
if (!binding.isClass() && !binding.isEnum()) continue;
Extension e = new Extension();
e.extensionMethods = getApplicableExtensionMethodsDefinedInProvider(typeNode, (ReferenceBinding) binding, receiverType);
e.suppressBaseMethods = suppressBaseMethods;
extensions.add(e);
}
}
}
return extensions;
}
示例2: checkFieldAccess
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Check and/or redirect the field access to the delegate receiver if any
*/
public TypeBinding checkFieldAccess(BlockScope scope) {
FieldBinding fieldBinding = (FieldBinding) this.binding;
MethodScope methodScope = scope.methodScope();
TypeBinding declaringClass = fieldBinding.original().declaringClass;
// check for forward references
if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum())
&& TypeBinding.equalsEquals(methodScope.enclosingSourceType(), declaringClass)
&& methodScope.lastVisibleFieldID >= 0
&& fieldBinding.id >= methodScope.lastVisibleFieldID
&& (!fieldBinding.isStatic() || methodScope.isStatic)) {
scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
}
this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
this.bits |= Binding.FIELD;
return getOtherFieldBindings(scope);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:CodeSnippetQualifiedNameReference.java
示例3: checkFieldAccess
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Check and/or redirect the field access to the delegate receiver if any
*/
public TypeBinding checkFieldAccess(BlockScope scope) {
FieldBinding fieldBinding = (FieldBinding) this.binding;
MethodScope methodScope = scope.methodScope();
TypeBinding declaringClass = fieldBinding.original().declaringClass;
// check for forward references
if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum())
&& methodScope.enclosingSourceType() == declaringClass
&& methodScope.lastVisibleFieldID >= 0
&& fieldBinding.id >= methodScope.lastVisibleFieldID
&& (!fieldBinding.isStatic() || methodScope.isStatic)) {
scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
}
this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
this.bits |= Binding.FIELD;
return getOtherFieldBindings(scope);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:20,代码来源:CodeSnippetQualifiedNameReference.java
示例4: incorrectSwitchType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void incorrectSwitchType(Expression expression, TypeBinding testType) {
if (this.options.sourceLevel < ClassFileConstants.JDK1_7) {
if (testType.id == TypeIds.T_JavaLangString) {
this.handle(
IProblem.SwitchOnStringsNotBelow17,
new String[] {new String(testType.readableName())},
new String[] {new String(testType.shortReadableName())},
expression.sourceStart,
expression.sourceEnd);
} else {
if (this.options.sourceLevel < ClassFileConstants.JDK1_5 && testType.isEnum()) {
this.handle(
IProblem.SwitchOnEnumNotBelow15,
new String[] {new String(testType.readableName())},
new String[] {new String(testType.shortReadableName())},
expression.sourceStart,
expression.sourceEnd);
} else {
this.handle(
IProblem.IncorrectSwitchType,
new String[] {new String(testType.readableName())},
new String[] {new String(testType.shortReadableName())},
expression.sourceStart,
expression.sourceEnd);
}
}
} else {
this.handle(
IProblem.IncorrectSwitchType17,
new String[] {new String(testType.readableName())},
new String[] {new String(testType.shortReadableName())},
expression.sourceStart,
expression.sourceEnd);
}
}
示例5: convertJDTValueToReflectionType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Convert a JDT annotation value as obtained from ElementValuePair.getValue()
* (e.g., IntConstant, FieldBinding, etc.) to the type expected by a reflective
* method invocation (e.g., int, an enum constant, etc.).
* @return a value of type {@code expectedType}, or a dummy value of that type if
* the actual value cannot be converted.
*/
private Object convertJDTValueToReflectionType(Object jdtValue, TypeBinding actualType, Class<?> expectedType) {
if (expectedType.isPrimitive() || String.class.equals(expectedType)) {
if (jdtValue instanceof Constant) {
if (boolean.class.equals(expectedType)) {
return ((Constant)jdtValue).booleanValue();
}
else if (byte.class.equals(expectedType)) {
return ((Constant)jdtValue).byteValue();
}
else if (char.class.equals(expectedType)) {
return ((Constant)jdtValue).charValue();
}
else if (double.class.equals(expectedType)) {
return ((Constant)jdtValue).doubleValue();
}
else if (float.class.equals(expectedType)) {
return ((Constant)jdtValue).floatValue();
}
else if (int.class.equals(expectedType)) {
return ((Constant)jdtValue).intValue();
}
else if (long.class.equals(expectedType)) {
return ((Constant)jdtValue).longValue();
}
else if (short.class.equals(expectedType)) {
return ((Constant)jdtValue).shortValue();
}
else if (String.class.equals(expectedType)) {
return ((Constant)jdtValue).stringValue();
}
}
// Primitive or string is expected, but our actual value cannot be coerced into one.
// TODO: if the actual value is an array of primitives, should we unpack the first one?
return Factory.getMatchingDummyValue(expectedType);
}
else if (expectedType.isEnum()) {
Object returnVal = null;
if (actualType != null && actualType.isEnum() && jdtValue instanceof FieldBinding) {
FieldBinding binding = (FieldBinding)jdtValue;
try {
Field returnedField = null;
returnedField = expectedType.getField( new String(binding.name) );
if (null != returnedField) {
returnVal = returnedField.get(null);
}
}
catch (NoSuchFieldException nsfe) {
// return null
}
catch (IllegalAccessException iae) {
// return null
}
}
return null == returnVal ? Factory.getMatchingDummyValue(expectedType) : returnVal;
}
else if (expectedType.isAnnotation()) {
// member value is expected to be an annotation type. Wrap it in an Annotation proxy.
if (actualType.isAnnotationType() && jdtValue instanceof AnnotationBinding) {
AnnotationMirrorImpl annoMirror =
(AnnotationMirrorImpl)_env.getFactory().newAnnotationMirror((AnnotationBinding)jdtValue);
return Proxy.newProxyInstance(expectedType.getClassLoader(),
new Class[]{ expectedType }, annoMirror );
}
else {
// No way to cast a non-annotation value to an annotation type; return null to caller
return null;
}
}
else {
return Factory.getMatchingDummyValue(expectedType);
}
}
示例6: resolveStatements
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void resolveStatements() {
super.resolveStatements();
if (this.arguments != null) {
this.scope.problemReporter().annotationMembersCannotHaveParameters(this);
}
if (this.typeParameters != null) {
this.scope.problemReporter().annotationMembersCannotHaveTypeParameters(this);
}
if (this.extendedDimensions != 0) {
this.scope.problemReporter().illegalExtendedDimensions(this);
}
if (this.binding == null) return;
TypeBinding returnTypeBinding = this.binding.returnType;
if (returnTypeBinding != null) {
// annotation methods can only return base types, String, Class, enum type, annotation types and arrays of these
checkAnnotationMethodType: {
TypeBinding leafReturnType = returnTypeBinding.leafComponentType();
if (returnTypeBinding.dimensions() <= 1) { // only 1-dimensional array permitted
switch (leafReturnType.erasure().id) {
case T_byte :
case T_short :
case T_char :
case T_int :
case T_long :
case T_float :
case T_double :
case T_boolean :
case T_JavaLangString :
case T_JavaLangClass :
break checkAnnotationMethodType;
}
if (leafReturnType.isEnum() || leafReturnType.isAnnotationType())
break checkAnnotationMethodType;
}
this.scope.problemReporter().invalidAnnotationMemberType(this);
}
if (this.defaultValue != null) {
MemberValuePair pair = new MemberValuePair(this.selector, this.sourceStart, this.sourceEnd, this.defaultValue);
pair.binding = this.binding;
pair.resolveTypeExpecting(this.scope, returnTypeBinding);
this.binding.setDefaultValue(org.eclipse.jdt.internal.compiler.lookup.ElementValuePair.getValue(this.defaultValue));
} else { // let it know it does not have a default value so it won't try to find it
this.binding.setDefaultValue(null);
}
}
}
示例7: resolveCase
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Returns the constant intValue or ordinal for enum constants. If constant is NotAConstant, then answers Float.MIN_VALUE
* @see org.eclipse.jdt.internal.compiler.ast.Statement#resolveCase(org.eclipse.jdt.internal.compiler.lookup.BlockScope, org.eclipse.jdt.internal.compiler.lookup.TypeBinding, org.eclipse.jdt.internal.compiler.ast.SwitchStatement)
*/
public Constant resolveCase(BlockScope scope, TypeBinding switchExpressionType, SwitchStatement switchStatement) {
// switchExpressionType maybe null in error case
scope.enclosingCase = this; // record entering in a switch case block
if (this.constantExpression == null) {
// remember the default case into the associated switch statement
if (switchStatement.defaultCase != null)
scope.problemReporter().duplicateDefaultCase(this);
// on error the last default will be the selected one ...
switchStatement.defaultCase = this;
return Constant.NotAConstant;
}
// add into the collection of cases of the associated switch statement
switchStatement.cases[switchStatement.caseCount++] = this;
// tag constant name with enum type for privileged access to its members
if (switchExpressionType != null && switchExpressionType.isEnum() && (this.constantExpression instanceof SingleNameReference)) {
((SingleNameReference) this.constantExpression).setActualReceiverType((ReferenceBinding)switchExpressionType);
}
TypeBinding caseType = this.constantExpression.resolveType(scope);
if (caseType == null || switchExpressionType == null) return Constant.NotAConstant;
if (this.constantExpression.isConstantValueOfTypeAssignableToType(caseType, switchExpressionType)
|| caseType.isCompatibleWith(switchExpressionType)) {
if (caseType.isEnum()) {
if (((this.constantExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) != 0) {
scope.problemReporter().enumConstantsCannotBeSurroundedByParenthesis(this.constantExpression);
}
if (this.constantExpression instanceof NameReference
&& (this.constantExpression.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD) {
NameReference reference = (NameReference) this.constantExpression;
FieldBinding field = reference.fieldBinding();
if ((field.modifiers & ClassFileConstants.AccEnum) == 0) {
scope.problemReporter().enumSwitchCannotTargetField(reference, field);
} else if (reference instanceof QualifiedNameReference) {
scope.problemReporter().cannotUseQualifiedEnumConstantInCaseLabel(reference, field);
}
return IntConstant.fromValue(field.original().id + 1); // (ordinal value + 1) zero should not be returned see bug 141810
}
} else {
return this.constantExpression.constant;
}
} else if (isBoxingCompatible(caseType, switchExpressionType, this.constantExpression, scope)) {
// constantExpression.computeConversion(scope, caseType, switchExpressionType); - do not report boxing/unboxing conversion
return this.constantExpression.constant;
}
scope.problemReporter().typeMismatchError(caseType, switchExpressionType, this.constantExpression, switchStatement.expression);
return Constant.NotAConstant;
}