List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isEnum
public boolean isEnum()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeDeclarationLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof TypeBinding)) return IMPOSSIBLE_MATCH; TypeBinding type = (TypeBinding) binding; switch (this.pattern.typeSuffix) { case CLASS_SUFFIX: if (!type.isClass()) return IMPOSSIBLE_MATCH; break;//from w w w .j av a2 s.c o m case CLASS_AND_INTERFACE_SUFFIX: if (!(type.isClass() || (type.isInterface() && !type.isAnnotationType()))) return IMPOSSIBLE_MATCH; break; case CLASS_AND_ENUM_SUFFIX: if (!(type.isClass() || type.isEnum())) return IMPOSSIBLE_MATCH; break; case INTERFACE_SUFFIX: if (!type.isInterface() || type.isAnnotationType()) return IMPOSSIBLE_MATCH; break; case INTERFACE_AND_ANNOTATION_SUFFIX: if (!(type.isInterface() || type.isAnnotationType())) return IMPOSSIBLE_MATCH; break; case ENUM_SUFFIX: if (!type.isEnum()) return IMPOSSIBLE_MATCH; break; case ANNOTATION_TYPE_SUFFIX: if (!type.isAnnotationType()) return IMPOSSIBLE_MATCH; break; case TYPE_SUFFIX: // nothing } // fully qualified name if (this.pattern instanceof QualifiedTypeDeclarationPattern) { QualifiedTypeDeclarationPattern qualifiedPattern = (QualifiedTypeDeclarationPattern) this.pattern; return resolveLevelForType(qualifiedPattern.simpleName, qualifiedPattern.qualification, type); } else { char[] enclosingTypeName = this.pattern.enclosingTypeNames == null ? null : CharOperation.concatWith(this.pattern.enclosingTypeNames, '.'); return resolveLevelForType(this.pattern.simpleName, this.pattern.pkg, enclosingTypeName, type); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected int resolveLevelForType(TypeBinding typeBinding) { if (typeBinding == null || !typeBinding.isValidBinding()) { if (this.pattern.typeSuffix != TYPE_SUFFIX) return INACCURATE_MATCH; } else {/*from ww w . j a v a2 s . co m*/ switch (this.pattern.typeSuffix) { case CLASS_SUFFIX: if (!typeBinding.isClass()) return IMPOSSIBLE_MATCH; break; case CLASS_AND_INTERFACE_SUFFIX: if (!(typeBinding.isClass() || (typeBinding.isInterface() && !typeBinding.isAnnotationType()))) return IMPOSSIBLE_MATCH; break; case CLASS_AND_ENUM_SUFFIX: if (!(typeBinding.isClass() || typeBinding.isEnum())) return IMPOSSIBLE_MATCH; break; case INTERFACE_SUFFIX: if (!typeBinding.isInterface() || typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH; break; case INTERFACE_AND_ANNOTATION_SUFFIX: if (!(typeBinding.isInterface() || typeBinding.isAnnotationType())) return IMPOSSIBLE_MATCH; break; case ENUM_SUFFIX: if (!typeBinding.isEnum()) return IMPOSSIBLE_MATCH; break; case ANNOTATION_TYPE_SUFFIX: if (!typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH; break; case TYPE_SUFFIX: // nothing } } return resolveLevelForType(this.pattern.simpleName, this.pattern.qualification, this.pattern.getTypeArguments(), 0, typeBinding); }
From source file:lombok.eclipse.agent.PatchExtensionMethod.java
License:Open Source License
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {//from w w w. j av a 2 s . co m 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; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTAnnotationNode.java
License:Open Source License
private Expression createExpressionFor(TypeBinding b, Object value) { if (b.isArrayType()) { ListExpression listExpression = new ListExpression(); // FIXASC is it a groovy optimization that if the value is expected to be an array you don't have to // write it as such if (value.getClass().isArray()) { Object[] values = (Object[]) value; for (Object v : values) { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, v)); }/*w w w . j a v a 2 s . c o m*/ } else { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, value)); } return listExpression; } else if (b.isEnum()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode(b)); Expression valueExpression = new PropertyExpression(classExpression, new String(((FieldBinding) value).name)); return valueExpression; } else if (CharOperation.equals(b.signature(), jlString)) { String v = ((StringConstant) value).stringValue(); return new ConstantExpression(v); } else if (b.isBaseType()) { char[] sig = b.signature(); if (CharOperation.equals(sig, baseInt)) { return new ConstantExpression(((IntConstant) value).intValue()); } else { throw new GroovyEclipseBug("NYI for signature " + new String(sig)); } } else if (b.isClass()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode((TypeBinding) value)); return classExpression; } throw new GroovyEclipseBug( "Problem in JDTAnnotatioNode.createExpressionFor(binding=" + b + " value=" + value + ")"); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * This method may wrap a type as an explicitly anchored role type if appropriate. */*from w ww .ja v a2 s . c o m*/ * If wrapping is not applicable, return the typeToWrap unmodified. * * @param scope (NON-NULL) defines the scope determining tthis if applicable. * @param anchorExpr (NON-NULL) * @param typeToWrap * @param typedNode position for error reporting (NON-NULL if problemReporter != null) * @return RoleTypeBinding or ArrayBinding or TypeBinding(original) or null */ public static TypeBinding maybeWrapQualifiedRoleType(final Scope scope, final Expression anchorExpr, TypeBinding typeToWrap, final ASTNode typedNode) { /* invocations: * QualifiedAllocationExpression.resolveType() rec.new R() R * FieldReference.resolveType() rec.r type(r) * maybeWrapQualifiedRoleType(MessageSend,BlockScope) * for MessageSend.resolveType() rec.m() returnType(m) */ if (typeToWrap == null) return null; if (TSuperHelper.isMarkerInterface(typeToWrap)) return typeToWrap; TypeBinding originalType = typeToWrap; // consider arrays: int dimensions = typeToWrap.dimensions(); typeToWrap = typeToWrap.leafComponentType(); // easy problems first: if (!(typeToWrap instanceof ReferenceBinding) || typeToWrap.isEnum()) return originalType; ReferenceBinding refBinding = (ReferenceBinding) typeToWrap; if (scope instanceof BlockScope && avoidWrapRoleType((BlockScope) scope, anchorExpr)) return originalType; if (refBinding instanceof CaptureBinding) return ((CaptureBinding) refBinding).maybeWrapQualifiedRoleType(scope, anchorExpr, typedNode, originalType); TypeBinding wrappedRoleType = internalWrapQualifiedRoleType(scope, anchorExpr, originalType, typedNode, refBinding, dimensions); return wrappedRoleType.maybeWrapRoleType(typedNode, new TypeArgumentUpdater() { public TypeBinding updateArg(ReferenceBinding arg) { if (arg instanceof WildcardBinding) return ((WildcardBinding) arg).maybeWrapQualifiedRoleType(scope, anchorExpr, typedNode); return arg; } }); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
public static TypeBinding maybeWrapUnqualifiedRoleType(final Scope scope, final ReferenceBinding site, TypeBinding typeToWrap, final ASTNode typedNode, ProblemReporter problemReporter) { assert (!(site == null)); if (typeToWrap == null) return null; if (!typeToWrap.isValidBinding()) return typeToWrap; // don't tamper with already broken type if (TSuperHelper.isMarkerInterface(typeToWrap)) return typeToWrap; final TypeBinding originalType = typeToWrap; // consider arrays: int dimensions = typeToWrap.dimensions(); typeToWrap = typeToWrap.leafComponentType(); // consider parameterized: TypeBinding[] arguments = null;/* w w w . ja va 2 s . c o m*/ if (typeToWrap.isParameterizedType()) arguments = ((ParameterizedTypeBinding) typeToWrap).arguments; // easy problems first: if (!(typeToWrap instanceof ReferenceBinding) || typeToWrap.isEnum()) return originalType; if (typeToWrap instanceof UnresolvedReferenceBinding) { // defer wrapping until resolve(): final UnresolvedReferenceBinding rawUnresolved = (UnresolvedReferenceBinding) typeToWrap; final ProblemReporter originalReporter = problemReporter; return new UnresolvedReferenceBinding(rawUnresolved.compoundName, rawUnresolved.getPackage()) { @Override public ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericToRawType) { ReferenceBinding type = rawUnresolved.resolve(environment, convertGenericToRawType); return (ReferenceBinding) maybeWrapUnqualifiedRoleType(scope, site, type, typedNode, originalReporter); } @Override public boolean hasTypeAnnotations() { return rawUnresolved.hasTypeAnnotations(); } @Override public boolean hasNullTypeAnnotations() { return rawUnresolved.hasNullTypeAnnotations(); } @Override public AnnotationBinding[] getAnnotations() { return rawUnresolved.getAnnotations(); } { this.tagBits = rawUnresolved.tagBits; } }; } if (typeToWrap instanceof IntersectionTypeBinding18) { // FIXME (recurse?) return originalType; } ReferenceBinding refBinding = (ReferenceBinding) typeToWrap; if (!refBinding.isDirectRole()) { final ProblemReporter reporter = problemReporter; return originalType.maybeWrapRoleType(typedNode, new TypeArgumentUpdater() { public TypeBinding updateArg(ReferenceBinding arg) { return maybeWrapUnqualifiedRoleType(scope, site, arg, typedNode, reporter); } }); } // already wrapped: if (typeToWrap instanceof RoleTypeBinding) { RoleTypeBinding roleType = (RoleTypeBinding) typeToWrap; if (!(roleType._teamAnchor instanceof TThisBinding)) { return originalType; // cannot improve } else { // do handle tthis RoleTypeBindings, too, because we might need to // set a new anchor // (but don't report errors, if this type is already acceptable). if (TeamModel.findEnclosingTeamContainingRole(site, roleType) != null) problemReporter = null; } } VariableBinding variableBinding = null; ReferenceBinding teamBinding = TeamModel.findEnclosingTeamContainingRole(site, refBinding); if (teamBinding != null) variableBinding = TThisBinding.getTThisForRole(refBinding, teamBinding); if (variableBinding == null) variableBinding = cannotWrapType(refBinding, problemReporter, typedNode); // handle problems (reported ones and yet unreported ones): assert (variableBinding != null); if (variableBinding == RoleTypeBinding.NoAnchor) { return originalType; } else if (!variableBinding.isFinal()) { if (problemReporter != null) problemReporter.anchorPathNotFinal(null, variableBinding, refBinding.sourceName()); // TODO return null; } else if (!(variableBinding instanceof TThisBinding) && !refBinding.isPublic()) { if (problemReporter != null) problemReporter.externalizingNonPublicRole(typedNode, refBinding); return null; } // delegate to the principal function: return getAnchoredType(scope, typedNode, variableBinding, refBinding, arguments, dimensions); }