本文整理汇总了Java中org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isArrayType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeBinding.isArrayType方法的具体用法?Java TypeBinding.isArrayType怎么用?Java TypeBinding.isArrayType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.lookup.TypeBinding
的用法示例。
在下文中一共展示了TypeBinding.isArrayType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: areSameTypes
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/** Are both types identical wrt the unannotated type and any null type annotations? Only unstructured types and captures are considered. */
protected static boolean areSameTypes(TypeBinding requiredType, TypeBinding providedType, TypeBinding providedSubstitute) {
if (requiredType == providedType) //$IDENTITY-COMPARISON$ // short cut for really-really-same types
return true;
if (requiredType.isParameterizedType() || requiredType.isArrayType())
return false; // not analysing details here
if (TypeBinding.notEquals(requiredType, providedType)) {
if (requiredType instanceof CaptureBinding) {
// when providing exactly the lower bound of the required type we're definitely fine:
TypeBinding lowerBound = ((CaptureBinding)requiredType).lowerBound;
if (lowerBound != null && areSameTypes(lowerBound, providedType, providedSubstitute))
return true;
} else if (requiredType.kind() == Binding.TYPE_PARAMETER && requiredType == providedSubstitute) { //$IDENTITY-COMPARISON$
return true;
} else if (providedType instanceof CaptureBinding) {
// when requiring exactly the upper bound of the provided type we're fine, too:
TypeBinding upperBound = ((CaptureBinding)providedType).upperBound();
if (upperBound != null && areSameTypes(requiredType, upperBound, providedSubstitute))
return true;
}
return false;
}
return (requiredType.tagBits & TagBits.AnnotationNullMASK) == (providedType.tagBits & TagBits.AnnotationNullMASK);
}
示例2: mergeAnnotationsIntoType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private static TypeBinding mergeAnnotationsIntoType(BlockScope scope, AnnotationBinding[] se8Annotations, long se8nullBits, Annotation se8NullAnnotation,
TypeReference typeRef, TypeBinding existingType)
{
if (existingType == null || !existingType.isValidBinding()) return existingType;
TypeReference unionRef = typeRef.isUnionType() ? ((UnionTypeReference) typeRef).typeReferences[0] : null;
// for arrays: @T X[] SE7 associates @T to the type, but in SE8 it affects the leaf component type
long prevNullBits = existingType.leafComponentType().tagBits & TagBits.AnnotationNullMASK;
if (se8nullBits != 0 && prevNullBits != se8nullBits && ((prevNullBits | se8nullBits) == TagBits.AnnotationNullMASK)) {
scope.problemReporter().contradictoryNullAnnotations(se8NullAnnotation);
}
TypeBinding oldLeafType = (unionRef == null) ? existingType.leafComponentType() : unionRef.resolvedType;
AnnotationBinding [][] goodies = new AnnotationBinding[typeRef.getAnnotatableLevels()][];
goodies[0] = se8Annotations; // @T X.Y.Z local; ==> @T should annotate X
TypeBinding newLeafType = scope.environment().createAnnotatedType(oldLeafType, goodies);
if (unionRef == null) {
typeRef.resolvedType = existingType.isArrayType() ? scope.environment().createArrayType(newLeafType, existingType.dimensions(), existingType.getTypeAnnotations()) : newLeafType;
} else {
unionRef.resolvedType = newLeafType;
unionRef.bits |= HasTypeAnnotations;
}
return typeRef.resolvedType;
}
示例3: resolveType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public TypeBinding resolveType(BlockScope scope) {
this.constant = Constant.NotAConstant;
if (this.receiver instanceof CastExpression // no cast check for ((type[])null)[0]
&& ((CastExpression)this.receiver).innermostCastedExpression() instanceof NullLiteral) {
this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
}
TypeBinding arrayType = this.receiver.resolveType(scope);
if (arrayType != null) {
this.receiver.computeConversion(scope, arrayType, arrayType);
if (arrayType.isArrayType()) {
TypeBinding elementType = ((ArrayBinding) arrayType).elementsType();
this.resolvedType = ((this.bits & ASTNode.IsStrictlyAssigned) == 0) ? elementType.capture(scope, this.sourceEnd) : elementType;
} else {
scope.problemReporter().referenceMustBeArrayTypeAt(arrayType, this);
}
}
TypeBinding positionType = this.position.resolveTypeExpecting(scope, TypeBinding.INT);
if (positionType != null) {
this.position.computeConversion(scope, TypeBinding.INT, positionType);
}
return this.resolvedType;
}
示例4: checkNeedForEnclosingInstanceCast
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Casting an enclosing instance will considered as useful if removing it would actually bind to a different type
*/
public static void checkNeedForEnclosingInstanceCast(BlockScope scope, Expression enclosingInstance, TypeBinding enclosingInstanceType, TypeBinding memberType) {
if (scope.compilerOptions().getSeverity(CompilerOptions.UnnecessaryTypeCheck) == ProblemSeverities.Ignore) return;
TypeBinding castedExpressionType = ((CastExpression)enclosingInstance).expression.resolvedType;
if (castedExpressionType == null) return; // cannot do better
// obvious identity cast
if (TypeBinding.equalsEquals(castedExpressionType, enclosingInstanceType)) {
scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
} else if (castedExpressionType == TypeBinding.NULL){
return; // tolerate null enclosing instance cast
} else {
TypeBinding alternateEnclosingInstanceType = castedExpressionType;
if (castedExpressionType.isBaseType() || castedExpressionType.isArrayType()) return; // error case
if (TypeBinding.equalsEquals(memberType, scope.getMemberType(memberType.sourceName(), (ReferenceBinding) alternateEnclosingInstanceType))) {
scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
}
}
}
示例5: errorNoMethodFor
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
StringBuffer buffer = new StringBuffer();
StringBuffer shortBuffer = new StringBuffer();
for (int i = 0, length = params.length; i < length; i++) {
if (i != 0){
buffer.append(", "); //$NON-NLS-1$
shortBuffer.append(", "); //$NON-NLS-1$
}
buffer.append(new String(params[i].readableName()));
shortBuffer.append(new String(params[i].shortReadableName()));
}
int id = recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType;
this.handle(
id,
new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
messageSend.sourceStart,
messageSend.sourceEnd);
}
示例6: javadocErrorNoMethodFor
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
int severity = computeSeverity(id);
if (severity == ProblemSeverities.Ignore) return;
StringBuffer buffer = new StringBuffer();
StringBuffer shortBuffer = new StringBuffer();
for (int i = 0, length = params.length; i < length; i++) {
if (i != 0){
buffer.append(", "); //$NON-NLS-1$
shortBuffer.append(", "); //$NON-NLS-1$
}
buffer.append(new String(params[i].readableName()));
shortBuffer.append(new String(params[i].shortReadableName()));
}
if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
this.handle(
id,
new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
severity,
messageSend.sourceStart,
messageSend.sourceEnd);
}
}
示例7: generateElementValue
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private void generateElementValue(
Expression defaultValue,
TypeBinding memberValuePairReturnType,
int attributeOffset) {
Constant constant = defaultValue.constant;
TypeBinding defaultValueBinding = defaultValue.resolvedType;
if (defaultValueBinding == null) {
this.contentsOffset = attributeOffset;
} else {
if (memberValuePairReturnType.isArrayType() && !defaultValueBinding.isArrayType()) {
// automatic wrapping
if (this.contentsOffset + 3 >= this.contents.length) {
resizeContents(3);
}
this.contents[this.contentsOffset++] = (byte) '[';
this.contents[this.contentsOffset++] = (byte) 0;
this.contents[this.contentsOffset++] = (byte) 1;
}
if (constant != null && constant != Constant.NotAConstant) {
generateElementValue(attributeOffset, defaultValue, constant, memberValuePairReturnType.leafComponentType());
} else {
generateElementValueForNonConstantExpression(defaultValue, attributeOffset, defaultValueBinding);
}
}
}
示例8: checkNeedForEnclosingInstanceCast
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Casting an enclosing instance will considered as useful if removing it would actually bind to a different type
*/
public static void checkNeedForEnclosingInstanceCast(BlockScope scope, Expression enclosingInstance, TypeBinding enclosingInstanceType, TypeBinding memberType) {
if (scope.compilerOptions().getSeverity(CompilerOptions.UnnecessaryTypeCheck) == ProblemSeverities.Ignore) return;
TypeBinding castedExpressionType = ((CastExpression)enclosingInstance).expression.resolvedType;
if (castedExpressionType == null) return; // cannot do better
// obvious identity cast
if (castedExpressionType == enclosingInstanceType) {
scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
} else if (castedExpressionType == TypeBinding.NULL){
return; // tolerate null enclosing instance cast
} else {
TypeBinding alternateEnclosingInstanceType = castedExpressionType;
if (castedExpressionType.isBaseType() || castedExpressionType.isArrayType()) return; // error case
if (memberType == scope.getMemberType(memberType.sourceName(), (ReferenceBinding) alternateEnclosingInstanceType)) {
scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
}
}
}
示例9: getForEachComponentType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private static TypeBinding getForEachComponentType(Expression collection, BlockScope scope) {
if (collection != null) {
TypeBinding resolved = collection.resolvedType;
if (resolved == null) resolved = resolveForExpression(collection, scope);
if (resolved == null) return null;
if (resolved.isArrayType()) {
resolved = ((ArrayBinding) resolved).elementsType();
return resolved;
} else if (resolved instanceof ReferenceBinding) {
ReferenceBinding iterableType = ((ReferenceBinding)resolved).findSuperTypeOriginatingFrom(TypeIds.T_JavaLangIterable, false);
TypeBinding[] arguments = null;
if (iterableType != null) switch (iterableType.kind()) {
case Binding.GENERIC_TYPE : // for (T t : Iterable<T>) - in case used inside Iterable itself
arguments = iterableType.typeVariables();
break;
case Binding.PARAMETERIZED_TYPE : // for(E e : Iterable<E>)
arguments = ((ParameterizedTypeBinding)iterableType).arguments;
break;
case Binding.RAW_TYPE : // for(Object e : Iterable)
return null;
}
if (arguments != null && arguments.length == 1) {
return arguments[0];
}
}
}
return null;
}
示例10: getForEachComponentType
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private static TypeBinding getForEachComponentType(Expression collection, BlockScope scope) {
if (collection != null) {
TypeBinding resolved = collection.resolvedType;
if (resolved == null) resolved = collection.resolveType(scope);
if (resolved == null) return null;
if (resolved.isArrayType()) {
resolved = ((ArrayBinding) resolved).elementsType();
return resolved;
} else if (resolved instanceof ReferenceBinding) {
ReferenceBinding iterableType = ((ReferenceBinding)resolved).findSuperTypeOriginatingFrom(TypeIds.T_JavaLangIterable, false);
TypeBinding[] arguments = null;
if (iterableType != null) switch (iterableType.kind()) {
case Binding.GENERIC_TYPE : // for (T t : Iterable<T>) - in case used inside Iterable itself
arguments = iterableType.typeVariables();
break;
case Binding.PARAMETERIZED_TYPE : // for(E e : Iterable<E>)
arguments = ((ParameterizedTypeBinding)iterableType).arguments;
break;
case Binding.RAW_TYPE : // for(Object e : Iterable)
return null;
}
if (arguments != null && arguments.length == 1) {
return arguments[0];
}
}
}
return null;
}
示例11: AnnotationValueImpl
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* @param value
* The JDT representation of a compile-time constant. See
* {@link ElementValuePair#getValue()} for possible object types:
* <ul>
* <li>{@link org.eclipse.jdt.internal.compiler.impl.Constant} for member
* of primitive type or String</li>
* <li>{@link TypeBinding} for a member value of type
* {@link java.lang.Class}</li>
* <li>{@link FieldBinding} for an enum constant</li>
* <li>{@link AnnotationBinding} for an annotation instance</li>
* <li><code>Object[]</code> for a member value of array type, where the
* array entries are one of the above</li>
* </ul>
* @param type
* The JDT representation of the type of the constant, as determined
* by the return type of the element. This is needed because the type
* of the value may have been widened (e.g., byte to int) by the compiler
* and we need to call the proper visitor. This is used only for base types.
* If it is null or not a BaseTypeBinding, it is ignored and the type is
* determined from the type of the value.
*/
public AnnotationValueImpl(BaseProcessingEnvImpl env, Object value, TypeBinding type) {
_env = env;
int kind[] = new int[1];
if (type == null) {
_value = convertToMirrorType(value, type, kind);
_kind = kind[0];
} else if (type.isArrayType()) {
List<AnnotationValue> convertedValues = null;
TypeBinding valueType = ((ArrayBinding)type).elementsType();
if (value instanceof Object[]) {
Object[] values = (Object[])value;
convertedValues = new ArrayList<AnnotationValue>(values.length);
for (Object oneValue : values) {
convertedValues.add(new AnnotationValueImpl(_env, oneValue, valueType));
}
} else {
convertedValues = new ArrayList<AnnotationValue>(1);
convertedValues.add(new AnnotationValueImpl(_env, value, valueType));
}
_value = Collections.unmodifiableList(convertedValues);
_kind = T_ArrayType;
} else {
_value = convertToMirrorType(value, type, kind);
_kind = kind[0];
}
}
示例12: generateElementValue
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private void generateElementValue(
Expression defaultValue,
TypeBinding memberValuePairReturnType,
int attributeOffset) {
Constant constant = defaultValue.constant;
TypeBinding defaultValueBinding = defaultValue.resolvedType;
if (defaultValueBinding == null) {
this.contentsOffset = attributeOffset;
} else {
if (defaultValueBinding.isMemberType()) {
this.recordInnerClasses(defaultValueBinding);
}
if (memberValuePairReturnType.isMemberType()) {
this.recordInnerClasses(memberValuePairReturnType);
}
if (memberValuePairReturnType.isArrayType() && !defaultValueBinding.isArrayType()) {
// automatic wrapping
if (this.contentsOffset + 3 >= this.contents.length) {
resizeContents(3);
}
this.contents[this.contentsOffset++] = (byte) '[';
this.contents[this.contentsOffset++] = (byte) 0;
this.contents[this.contentsOffset++] = (byte) 1;
}
if (constant != null && constant != Constant.NotAConstant) {
generateElementValue(attributeOffset, defaultValue, constant, memberValuePairReturnType.leafComponentType());
} else {
generateElementValueForNonConstantExpression(defaultValue, attributeOffset, defaultValueBinding);
}
}
}
示例13: isTypeUseDeprecated
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
if (type.isArrayType()) {
type = ((ArrayBinding) type).leafComponentType;
}
if (type.isBaseType())
return false;
ReferenceBinding refType = (ReferenceBinding) type;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=397888
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
if ((this.bits & ASTNode.InsideJavadoc) == 0 && refType instanceof TypeVariableBinding) {
refType.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
}
// ignore references insing Javadoc comments
if ((this.bits & ASTNode.InsideJavadoc) == 0 && refType.isOrEnclosedByPrivateType() && !scope.isDefinedInType(refType)) {
// ignore cases where type is used from inside itself
((ReferenceBinding)refType.erasure()).modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
}
if (refType.hasRestrictedAccess()) {
AccessRestriction restriction = scope.environment().getAccessRestriction(type.erasure());
if (restriction != null) {
scope.problemReporter().forbiddenReference(type, this, restriction.classpathEntryType,
restriction.classpathEntryName, restriction.getProblemId());
}
}
// force annotations resolution before deciding whether the type may be deprecated
refType.initializeDeprecatedAnnotationTagBits();
if (!refType.isViewedAsDeprecated()) return false;
// inside same unit - no report
if (scope.isDefinedInSameUnit(refType)) return false;
// if context is deprecated, may avoid reporting
if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
return true;
}
示例14: getReflectionValue
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
* Convert an annotation member value from JDT into Reflection, and from whatever its actual type
* is into whatever type the reflective invoker of a method is expecting.
* <p>
* Only certain types are permitted as member values. Specifically, a member must be a constant,
* and must be either a primitive type, String, Class, an enum constant, an annotation, or an
* array of any of those. Multidimensional arrays are not permitted.
*
* @param actualValue the value as represented by {@link ElementValuePair#getValue()}
* @param actualType the return type of the corresponding {@link MethodBinding}
* @param expectedType the type that the reflective method invoker is expecting
* @return an object of the expected type representing the annotation member value,
* or an appropriate dummy value (such as null) if no value is available
*/
private Object getReflectionValue(Object actualValue, TypeBinding actualType, Class<?> expectedType)
{
if (null == expectedType) {
// With no expected type, we can't even guess at a conversion
return null;
}
if (null == actualValue) {
// Return a type-appropriate equivalent of null
return Factory.getMatchingDummyValue(expectedType);
}
if (expectedType.isArray()) {
if (Class.class.equals(expectedType.getComponentType())) {
// package Class[]-valued return as a MirroredTypesException
if (actualType.isArrayType() && actualValue instanceof Object[] &&
((ArrayBinding)actualType).leafComponentType.erasure().id == TypeIds.T_JavaLangClass) {
Object[] bindings = (Object[])actualValue;
List<TypeMirror> mirrors = new ArrayList<TypeMirror>(bindings.length);
for (int i = 0; i < bindings.length; ++i) {
if (bindings[i] instanceof TypeBinding) {
mirrors.add(_env.getFactory().newTypeMirror((TypeBinding)bindings[i]));
}
}
throw new MirroredTypesException(mirrors);
}
// TODO: actual value is not a TypeBinding[]. Should we return a TypeMirror[] around an ErrorType?
return null;
}
// Handle arrays of types other than Class, e.g., int[], MyEnum[], ...
return convertJDTArrayToReflectionArray(actualValue, actualType, expectedType);
}
else if (Class.class.equals(expectedType)) {
// package the Class-valued return as a MirroredTypeException
if (actualValue instanceof TypeBinding) {
TypeMirror mirror = _env.getFactory().newTypeMirror((TypeBinding)actualValue);
throw new MirroredTypeException(mirror);
}
else {
// TODO: actual value is not a TypeBinding. Should we return a TypeMirror around an ErrorType?
return null;
}
}
else {
// Handle unitary values of type other than Class, e.g., int, MyEnum, ...
return convertJDTValueToReflectionType(actualValue, actualType, expectedType);
}
}