List of usage examples for org.eclipse.jdt.core.dom IMethodBinding getParameterTypes
public ITypeBinding[] getParameterTypes();
From source file:astview.Binding.java
License:Open Source License
@Override public Object[] getChildren() { try {//from ww w .j a v a 2 s . co m if (fBinding != null) { fBinding.getKey(); } } catch (RuntimeException e) { return new Object[] { new Error(this, "BrokenBinding: " + fBinding, null) }; } if (fBinding != null) { ArrayList<ASTAttribute> res = new ArrayList<>(); res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true)); //$NON-NLS-1$ switch (fBinding.getKind()) { case IBinding.VARIABLE: IVariableBinding variableBinding = (IVariableBinding) fBinding; res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$ true)); res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$ res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ //$NON-NLS-2$ res.add(new BindingProperty(this, "IS EFFECTIVELY FINAL", variableBinding.isEffectivelyFinal(), //$NON-NLS-1$ true)); break; case IBinding.PACKAGE: IPackageBinding packageBinding = (IPackageBinding) fBinding; res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ break; case IBinding.TYPE: ITypeBinding typeBinding = (ITypeBinding) fBinding; res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$ int typeKind = getTypeKind(typeBinding); boolean isRefType = isType(typeKind, REF_TYPE); final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE); StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$ if (typeBinding.isArray()) kinds.append(" isArray"); //$NON-NLS-1$ if (typeBinding.isCapture()) kinds.append(" isCapture"); //$NON-NLS-1$ if (typeBinding.isNullType()) kinds.append(" isNullType"); //$NON-NLS-1$ if (typeBinding.isPrimitive()) kinds.append(" isPrimitive"); //$NON-NLS-1$ if (typeBinding.isTypeVariable()) kinds.append(" isTypeVariable"); //$NON-NLS-1$ if (typeBinding.isWildcardType()) kinds.append(" isWildcardType"); //$NON-NLS-1$ // ref types if (typeBinding.isAnnotation()) kinds.append(" isAnnotation"); //$NON-NLS-1$ if (typeBinding.isClass()) kinds.append(" isClass"); //$NON-NLS-1$ if (typeBinding.isInterface()) kinds.append(" isInterface"); //$NON-NLS-1$ if (typeBinding.isEnum()) kinds.append(" isEnum"); //$NON-NLS-1$ res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$ StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (typeBinding.isRawType()) generics.append(" isRawType"); //$NON-NLS-1$ if (typeBinding.isGenericType()) generics.append(" isGenericType"); //$NON-NLS-1$ if (typeBinding.isParameterizedType()) generics.append(" isParameterizedType"); //$NON-NLS-1$ if (!isType(typeKind, GENERIC | PARAMETRIZED)) { generics.append(" (non-generic, non-parameterized)"); } res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); final String createArrayTypeLabel = "CREATE ARRAY TYPE (+1)"; try { ITypeBinding arrayType = typeBinding.createArrayType(1); res.add(new Binding(this, createArrayTypeLabel, arrayType, true)); } catch (RuntimeException e) { String msg = e.getClass().getName() + ": " + e.getLocalizedMessage(); boolean isRelevant = !typeBinding.getName().equals(PrimitiveType.VOID.toString()) && !typeBinding.isRecovered(); if (isRelevant) { res.add(new Error(this, createArrayTypeLabel + ": " + msg, e)); } else { res.add(new BindingProperty(this, createArrayTypeLabel, msg, false)); } } StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$ if (typeBinding.isTopLevel()) origin.append(" isTopLevel"); //$NON-NLS-1$ if (typeBinding.isNested()) origin.append(" isNested"); //$NON-NLS-1$ if (typeBinding.isLocal()) origin.append(" isLocal"); //$NON-NLS-1$ if (typeBinding.isMember()) origin.append(" isMember"); //$NON-NLS-1$ if (typeBinding.isAnonymous()) origin.append(" isAnonymous"); //$NON-NLS-1$ res.add(new BindingProperty(this, origin, isRefType)); res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); // res.add(new Binding(this, "DECLARING MEMBER", typeBinding.getDeclaringMember(), typeBinding.isLocal())); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$ isRefType)); res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$ String isTypeDeclaration = typeBinding == typeBinding.getTypeDeclaration() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "TYPE DECLARATION" + isTypeDeclaration, typeBinding.getTypeDeclaration(), //$NON-NLS-1$ true)); String isErasure = typeBinding == typeBinding.getErasure() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "ERASURE" + isErasure, typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$ isType(typeKind, GENERIC))); res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$ isType(typeKind, PARAMETRIZED))); res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$ isType(typeKind, VARIABLE_TYPE | WILDCARD_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$ isType(typeKind, WILDCARD_TYPE))); res.add(new Binding(this, "GENERIC TYPE OF WILDCARD TYPE", //$NON-NLS-1$ typeBinding.getGenericTypeOfWildcardType(), isType(typeKind, WILDCARD_TYPE))); res.add(new BindingProperty(this, "RANK", typeBinding.getRank(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "FUNCTIONAL INTERFACE METHOD", typeBinding.getFunctionalInterfaceMethod(), //$NON-NLS-1$ typeBinding.isInterface())); res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ANNOTATIONS", typeBinding.getTypeAnnotations(), true)); //$NON-NLS-1$ break; case IBinding.METHOD: IMethodBinding methodBinding = (IMethodBinding) fBinding; res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$ true)); res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$ // res.add(new Binding(this, "DECLARING MEMBER", methodBinding.getDeclaringMember(), methodBinding.getDeclaringMember() != null)); //$NON-NLS-1$ res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), true), //$NON-NLS-1$ true)); res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$ StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (methodBinding.isRawMethod()) genericsM.append(" isRawMethod"); //$NON-NLS-1$ if (methodBinding.isGenericMethod()) genericsM.append(" isGenericMethod"); //$NON-NLS-1$ if (methodBinding.isParameterizedMethod()) genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$ res.add(new BindingProperty(this, genericsM, true)); String isMethodDeclaration = methodBinding == methodBinding.getMethodDeclaration() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "METHOD DECLARATION" + isMethodDeclaration, //$NON-NLS-1$ methodBinding.getMethodDeclaration(), true)); res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$ true)); res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue())); int parameterCount = methodBinding.getParameterTypes().length; BindingProperty[] parametersAnnotations = new BindingProperty[parameterCount]; for (int i = 0; i < parameterCount; i++) { parametersAnnotations[i] = new BindingProperty(this, "Parameter " + String.valueOf(i), methodBinding.getParameterAnnotations(i), true); } res.add(new BindingProperty(this, "PARAMETER ANNOTATIONS", parametersAnnotations, true)); break; case IBinding.ANNOTATION: IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding; res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true)); res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS", annotationBinding.getDeclaredMemberValuePairs(), true)); res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS", annotationBinding.getAllMemberValuePairs(), true)); break; case IBinding.MEMBER_VALUE_PAIR: IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding; res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true)); res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true)); res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue())); break; } try { IAnnotationBinding[] annotations = fBinding.getAnnotations(); res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$ } catch (RuntimeException e) { String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\""; res.add(new Error(this, label, e)); } try { IJavaElement javaElement = fBinding.getJavaElement(); } catch (RuntimeException e) { String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ res.add(new Error(this, label, e)); } return res.toArray(); } return EMPTY; }
From source file:astview.Binding.java
License:Open Source License
@Override public String getLabel() { StringBuffer buf = new StringBuffer(fLabel); buf.append(": "); //$NON-NLS-1$ if (fBinding != null) { switch (fBinding.getKind()) { case IBinding.VARIABLE: IVariableBinding variableBinding = (IVariableBinding) fBinding; if (!variableBinding.isField()) { buf.append(variableBinding.getName()); } else { if (variableBinding.getDeclaringClass() == null) { buf.append("<some array type>"); //$NON-NLS-1$ } else { buf.append(variableBinding.getDeclaringClass().getName()); }//from w ww . j a v a 2 s . co m buf.append('.'); buf.append(variableBinding.getName()); } break; case IBinding.PACKAGE: IPackageBinding packageBinding = (IPackageBinding) fBinding; buf.append(packageBinding.getName()); break; case IBinding.TYPE: ITypeBinding typeBinding = (ITypeBinding) fBinding; appendAnnotatedQualifiedName(buf, typeBinding); break; case IBinding.METHOD: IMethodBinding methodBinding = (IMethodBinding) fBinding; buf.append(methodBinding.getDeclaringClass().getName()); buf.append('.'); buf.append(methodBinding.getName()); buf.append('('); ITypeBinding[] parameters = methodBinding.getParameterTypes(); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); //$NON-NLS-1$ } ITypeBinding parameter = parameters[i]; buf.append(parameter.getName()); } buf.append(')'); break; case IBinding.ANNOTATION: case IBinding.MEMBER_VALUE_PAIR: buf.append(fBinding.toString()); break; } } else { buf.append("null"); //$NON-NLS-1$ } return buf.toString(); }
From source file:br.com.objectos.way.core.code.jdt.ITypeBindingWrapperTest.java
License:Apache License
public void to_parameter_info() { IMethodBinding method = IMethodBindingFake.ENTITY_IFACE_TESTABLE_IS_EQUAL; ITypeBinding binding = method.getParameterTypes()[0]; ParameterInfo res = ITypeBindingWrapper.wrapperOf(binding).toParameterInfo(0); assertThat(res, isEqualTo(ParameterInfoFake.ENTITY_ARG)); }
From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java
License:Open Source License
/** * Gets the soot method sub signature.// w w w . ja va2s . co m * * @return the soot method sub signature */ public String getSootMethodSubSignature() { IMethodBinding methodBinding = methodDeclaration.resolveBinding(); ITypeBinding[] argumentsBinding = methodBinding.getParameterTypes(); ITypeBinding returnBinding = methodBinding.getReturnType(); StringBuilder stringMethodBuilder = new StringBuilder(); stringMethodBuilder.append(returnBinding.getQualifiedName()); stringMethodBuilder.append(" "); if (methodDeclaration.isConstructor()) { stringMethodBuilder.append("<init>"); } else { stringMethodBuilder.append(methodBinding.getName()); } stringMethodBuilder.append("("); for (int index = 0; index < argumentsBinding.length; index++) { stringMethodBuilder.append(argumentsBinding[index].getQualifiedName()); if (!(index == argumentsBinding.length - 1)) { stringMethodBuilder.append(","); } } stringMethodBuilder.append(")"); return stringMethodBuilder.toString(); }
From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java
License:Open Source License
/** * Gets the soot method signature./* ww w .ja va 2s .c o m*/ * * @return the soot method signature */ public String getSootMethodSignature() { IMethodBinding methodBinding = methodDeclaration.resolveBinding(); ITypeBinding[] argumentsBinding = methodBinding.getParameterTypes(); ITypeBinding declaringTypeBinding = methodBinding.getDeclaringClass(); ITypeBinding returnBinding = methodBinding.getReturnType(); StringBuilder stringMethodBuilder = new StringBuilder("<"); stringMethodBuilder.append(declaringTypeBinding.getQualifiedName()); stringMethodBuilder.append(": "); stringMethodBuilder.append(returnBinding.getQualifiedName()); stringMethodBuilder.append(" "); stringMethodBuilder.append(methodBinding.getName()); stringMethodBuilder.append("("); for (int index = 0; index < argumentsBinding.length; index++) { stringMethodBuilder.append(argumentsBinding[index].getQualifiedName()); if (!(index == argumentsBinding.length - 1)) { stringMethodBuilder.append(","); } } stringMethodBuilder.append(")>"); return stringMethodBuilder.toString(); }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private void validateLifeCycleMethod(Annotation annotation, String methodName, MethodDeclaration method, Collection<DSAnnotationProblem> problems) { if (errorLevel.isNone()) return;//from www . ja v a 2 s . c o m IMethodBinding methodBinding = method.resolveBinding(); if (methodBinding == null) { if (debug.isDebugging()) debug.trace(String.format("Unable to resolve binding for method: %s", method)); //$NON-NLS-1$ return; } String returnTypeName = methodBinding.getReturnType().getName(); if (!Void.TYPE.getName().equals(returnTypeName)) reportProblem(annotation, methodName, problems, NLS.bind(Messages.AnnotationProcessor_invalidLifeCycleMethodReturnType, methodName, returnTypeName), returnTypeName); ITypeBinding[] paramTypeBindings = methodBinding.getParameterTypes(); if (paramTypeBindings.length == 0) // no-arg method return; // every argument must be either Map, ComponentContext, or BundleContext boolean hasMap = false; boolean hasCompCtx = false; boolean hasBundleCtx = false; boolean hasInt = false; for (ITypeBinding paramTypeBinding : paramTypeBindings) { String paramTypeName = paramTypeBinding.getErasure().getQualifiedName(); boolean isDuplicate = false; if (Map.class.getName().equals(paramTypeName)) { if (hasMap) isDuplicate = true; else hasMap = true; } else if (ComponentContext.class.getName().equals(paramTypeName)) { if (hasCompCtx) isDuplicate = true; else hasCompCtx = true; } else if (BundleContext.class.getName().equals(paramTypeName)) { if (hasBundleCtx) isDuplicate = true; else hasBundleCtx = true; } else if ("deactivate".equals(methodName) //$NON-NLS-1$ && (Integer.class.getName().equals(paramTypeName) || Integer.TYPE.getName().equals(paramTypeName))) { if (hasInt) isDuplicate = true; else hasInt = true; } else { reportProblem(annotation, methodName, problems, NLS.bind(Messages.AnnotationProcessor_invalidLifeCycleMethodParameterType, methodName, paramTypeName), paramTypeName); } if (isDuplicate) reportProblem(annotation, methodName, problems, NLS.bind(Messages.AnnotationProcessor_duplicateLifeCycleMethodParameterType, methodName, paramTypeName), paramTypeName); } }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private boolean processReference(MethodDeclaration method, IMethodBinding methodBinding, Annotation annotation, IAnnotationBinding annotationBinding, IDSDocumentFactory factory, Collection<IDSReference> collector, Map<String, Annotation> names, Collection<DSAnnotationProblem> problems) { HashMap<String, Object> params = new HashMap<String, Object>(); for (IMemberValuePairBinding pair : annotationBinding.getDeclaredMemberValuePairs()) { params.put(pair.getName(), pair.getValue()); }/*w ww.ja va 2 s . c o m*/ boolean requiresV12 = false; ITypeBinding[] argTypes = methodBinding.getParameterTypes(); ITypeBinding serviceType; Object value; if ((value = params.get("service")) instanceof ITypeBinding) { //$NON-NLS-1$ serviceType = (ITypeBinding) value; if (!errorLevel.isNone() && argTypes.length > 0) { ITypeBinding[] typeArgs; if (!(ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName()) && ((typeArgs = argTypes[0].getTypeArguments()).length == 0 || serviceType.isAssignmentCompatible(typeArgs[0]))) && !serviceType.isAssignmentCompatible(argTypes[0])) reportProblem(annotation, "service", problems, //$NON-NLS-1$ NLS.bind(Messages.AnnotationProcessor_invalidReferenceService, argTypes[0].getName(), serviceType.getName()), serviceType.getName()); } } else if (argTypes.length > 0) { if (ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName())) { ITypeBinding[] typeArgs = argTypes[0].getTypeArguments(); if (typeArgs.length > 0) serviceType = typeArgs[0]; else serviceType = null; } else { serviceType = argTypes[0].isPrimitive() ? getObjectType(method.getAST(), argTypes[0]) : argTypes[0]; } } else { serviceType = null; } if (serviceType == null) { reportProblem(annotation, null, problems, Messages.AnnotationProcessor_invalidReferenceServiceUnknown); serviceType = method.getAST().resolveWellKnownType(Object.class.getName()); } validateReferenceBindMethod(annotation, serviceType, methodBinding, problems); String service = serviceType == null ? null : serviceType.getBinaryName(); String methodName = methodBinding.getName(); String name; if ((value = params.get("name")) instanceof String) { //$NON-NLS-1$ name = (String) value; } else if (methodName.startsWith("bind")) { //$NON-NLS-1$ name = methodName.substring("bind".length()); //$NON-NLS-1$ } else if (methodName.startsWith("set")) { //$NON-NLS-1$ name = methodName.substring("set".length()); //$NON-NLS-1$ } else if (methodName.startsWith("add")) { //$NON-NLS-1$ name = methodName.substring("add".length()); //$NON-NLS-1$ } else { name = methodName; } if (!errorLevel.isNone()) { if (names.containsKey(name)) { reportProblem(annotation, "name", problems, //$NON-NLS-1$ NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name); Annotation duplicate = names.put(name, null); if (duplicate != null) reportProblem(duplicate, "name", problems, //$NON-NLS-1$ NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name); } else { names.put(name, annotation); } } String cardinality = null; if ((value = params.get("cardinality")) instanceof IVariableBinding) { //$NON-NLS-1$ IVariableBinding cardinalityBinding = (IVariableBinding) value; ReferenceCardinality cardinalityLiteral = ReferenceCardinality.valueOf(cardinalityBinding.getName()); if (cardinalityLiteral != null) cardinality = cardinalityLiteral.toString(); } String policy = null; if ((value = params.get("policy")) instanceof IVariableBinding) { //$NON-NLS-1$ IVariableBinding policyBinding = (IVariableBinding) value; ReferencePolicy policyLiteral = ReferencePolicy.valueOf(policyBinding.getName()); if (policyLiteral != null) policy = policyLiteral.toString(); } String target = null; if ((value = params.get("target")) instanceof String) { //$NON-NLS-1$ target = (String) value; validateReferenceTarget(annotation, target, problems); } String unbind; if ((value = params.get("unbind")) instanceof String) { //$NON-NLS-1$ String unbindValue = (String) value; if ("-".equals(unbindValue)) { //$NON-NLS-1$ unbind = null; } else { unbind = unbindValue; if (!errorLevel.isNone() && serviceType != null) { IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType, unbind); if (unbindMethod == null) reportProblem(annotation, "unbind", problems, //$NON-NLS-1$ NLS.bind(Messages.AnnotationProcessor_invalidReferenceUnbind, unbind), unbind); } } } else if (serviceType != null) { String unbindCandidate; if (methodName.startsWith("add")) { //$NON-NLS-1$ unbindCandidate = "remove" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$ } else { unbindCandidate = "un" + methodName; //$NON-NLS-1$ } IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType, unbindCandidate); if (unbindMethod == null) unbind = null; else unbind = unbindMethod.getName(); } else { unbind = null; } String policyOption = null; if ((value = params.get("policyOption")) instanceof IVariableBinding) { //$NON-NLS-1$ IVariableBinding policyOptionBinding = (IVariableBinding) value; ReferencePolicyOption policyOptionLiteral = ReferencePolicyOption .valueOf(policyOptionBinding.getName()); if (policyOptionLiteral != null) { policyOption = policyOptionLiteral.toString(); requiresV12 = true; } } String updated; if ((value = params.get("updated")) instanceof String) { //$NON-NLS-1$ String updatedValue = (String) value; if ("-".equals(updatedValue)) { //$NON-NLS-1$ updated = null; } else { updated = updatedValue; if (!errorLevel.isNone() && serviceType != null) { IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType, updated); if (updatedMethod == null) reportProblem(annotation, "updated", problems, //$NON-NLS-1$ NLS.bind(Messages.AnnotationProcessor_invalidReferenceUpdated, updated), updated); } } requiresV12 = true; } else if (serviceType != null) { String updatedCandidate; if (methodName.startsWith("bind")) { //$NON-NLS-1$ updatedCandidate = "updated" + methodName.substring("bind".length()); //$NON-NLS-1$ //$NON-NLS-2$ } else if (methodName.startsWith("set")) { //$NON-NLS-1$ updatedCandidate = "updated" + methodName.substring("set".length()); //$NON-NLS-1$ //$NON-NLS-2$ } else if (methodName.startsWith("add")) { //$NON-NLS-1$ updatedCandidate = "updated" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$ } else { updatedCandidate = "updated" + methodName; //$NON-NLS-1$ } IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType, updatedCandidate); if (updatedMethod == null) updated = null; else updated = updatedMethod.getName(); } else { updated = null; } IDSReference reference = factory.createReference(); collector.add(reference); reference.setReferenceBind(methodName); if (name != null) reference.setReferenceName(name); if (service != null) reference.setReferenceInterface(service); if (cardinality != null) reference.setReferenceCardinality(cardinality); if (policy != null) reference.setReferencePolicy(policy); if (target != null) reference.setReferenceTarget(target); if (unbind != null) reference.setReferenceUnbind(unbind); if (policyOption != null) reference.setXMLAttribute("policy-option", policyOption); //$NON-NLS-1$ if (updated != null) reference.setXMLAttribute("updated", updated); //$NON-NLS-1$ return requiresV12; }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private void validateReferenceBindMethod(Annotation annotation, ITypeBinding serviceType, IMethodBinding methodBinding, Collection<DSAnnotationProblem> problems) { if (errorLevel.isNone()) return;//from ww w .ja va 2 s . c om String returnTypeName = methodBinding.getReturnType().getName(); if (!Void.TYPE.getName().equals(returnTypeName)) reportProblem(annotation, null, problems, NLS.bind(Messages.AnnotationProcessor_invalidBindMethodReturnType, returnTypeName), returnTypeName); ITypeBinding[] paramTypeBindings = methodBinding.getParameterTypes(); if (!(paramTypeBindings.length == 1 && (ServiceReference.class.getName().equals(paramTypeBindings[0].getErasure().getQualifiedName()) || serviceType == null || serviceType.isAssignmentCompatible(paramTypeBindings[0]))) && !(paramTypeBindings.length == 2 && (serviceType == null || serviceType.isAssignmentCompatible(paramTypeBindings[0])) && Map.class.getName().equals(paramTypeBindings[1].getErasure().getQualifiedName()))) { String[] params = new String[paramTypeBindings.length]; StringBuilder buf = new StringBuilder(64); buf.append('('); for (int i = 0; i < params.length; ++i) { params[i] = paramTypeBindings[i].getName(); if (buf.length() > 1) buf.append(", "); //$NON-NLS-1$ buf.append(params[i]); } buf.append(')'); reportProblem(annotation, null, problems, NLS.bind(Messages.AnnotationProcessor_invalidBindMethodParameters, buf, serviceType == null ? Messages.AnnotationProcessor_unknownServiceTypeLabel : serviceType.getName()), params); } }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private IMethodBinding findReferenceMethod(ITypeBinding componentClass, ITypeBinding serviceType, String name) { ITypeBinding testedClass = componentClass; IMethodBinding candidate = null;/*from w w w . j a v a 2s . com*/ int priority = 0; // priority: // 0: <assignment-compatible-type>, Map // 1: <exact-type>, Map // 2: <assignment-compatible-type> // 3: <exact-type> do { for (IMethodBinding declaredMethod : testedClass.getDeclaredMethods()) { if (name.equals(declaredMethod.getName()) && Void.TYPE.getName().equals(declaredMethod.getReturnType().getName()) && (testedClass.isEqualTo(componentClass) || Modifier.isPublic(declaredMethod.getModifiers()) || Modifier.isProtected(declaredMethod.getModifiers()) || (!Modifier.isPrivate(declaredMethod.getModifiers()) && testedClass.getPackage().isEqualTo(componentClass.getPackage())))) { ITypeBinding[] paramTypes = declaredMethod.getParameterTypes(); if (paramTypes.length == 1) { if (ServiceReference.class.getName().equals(paramTypes[0].getErasure().getQualifiedName())) // we have the winner return declaredMethod; if (priority < 3 && serviceType.isEqualTo(paramTypes[0])) priority = 3; else if (priority < 2 && serviceType.isAssignmentCompatible(paramTypes[0])) priority = 2; else continue; // we have a (better) candidate candidate = declaredMethod; } else if (paramTypes.length == 2) { if (priority < 1 && serviceType.isEqualTo(paramTypes[0]) && Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName())) priority = 1; else if (candidate != null || !serviceType.isAssignmentCompatible(paramTypes[0]) || !Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName())) continue; // we have a candidate candidate = declaredMethod; } } } } while ((testedClass = testedClass.getSuperclass()) != null); return candidate; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
/** * Converts a method binding to a method element. * //from w ww . j av a 2 s. c o m * @param pBinding * The binding to covert. Cannot be null. * @return A method element corresponding to pBinding. Never null. */ private static IElement convertBinding(final IMethodBinding pBinding) { ASTCrawler.checkForNull(pBinding); String lReturn = null; try { lReturn = ASTCrawler.convertBinding(pBinding.getDeclaringClass()).getId() + "."; } catch (final NullPointerException E) { E.printStackTrace(); throw E; } if (pBinding.isConstructor()) lReturn += "<init>"; else lReturn += pBinding.getName(); lReturn += "("; final ITypeBinding lParamBindings[] = pBinding.getParameterTypes(); for (int i = 0; i < lParamBindings.length - 1; i++) { lReturn += ASTCrawler.convertParameterTypeBinding(lParamBindings[i]).getId(); lReturn += ","; } if (lParamBindings.length > 0) lReturn += ASTCrawler.convertParameterTypeBinding(lParamBindings[lParamBindings.length - 1]).getId(); lReturn += ")"; return FlyweightElementFactory.getElement(Category.METHOD, lReturn); }