Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isConstructor()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isConstructor() .
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: Extractor.java From javaide with GNU General Public License v3.0 | 6 votes |
@Nullable static MethodItem create(@Nullable String classFqn, @NonNull ClassKind classKind, @NonNull AbstractMethodDeclaration declaration, @Nullable MethodBinding binding) { if (classFqn == null || binding == null) { return null; } String returnType = getReturnType(binding); String methodName = getMethodName(binding); Argument[] arguments = declaration.arguments; boolean isVarargs = arguments != null && arguments.length > 0 && arguments[arguments.length - 1].isVarArgs(); String parameterList = getParameterList(binding, isVarargs); if (returnType == null || methodName == null) { return null; } //noinspection PointlessBooleanExpression,ConstantConditions if (!INCLUDE_TYPE_ARGS) { classFqn = ApiDatabase.getRawClass(classFqn); methodName = ApiDatabase.getRawMethod(methodName); } return new MethodItem(classFqn, classKind, returnType, methodName, parameterList, binding.isConstructor()); }
Example 2
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@Override @NonNull public Iterable<ResolvedMethod> getConstructors() { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; MethodBinding[] methods = cls.getMethods(TypeConstants.INIT); if (methods != null) { int count = methods.length; List<ResolvedMethod> result = Lists.newArrayListWithExpectedSize(count); for (MethodBinding method : methods) { if (method.isConstructor()) { result.add(new EcjResolvedMethod(method)); } } return result; } } return Collections.emptyList(); }
Example 3
Source File: ExecutableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public ElementKind getKind() { MethodBinding binding = (MethodBinding)_binding; if (binding.isConstructor()) { return ElementKind.CONSTRUCTOR; } else if (CharOperation.equals(binding.selector, TypeConstants.CLINIT)) { return ElementKind.STATIC_INIT; } else if (CharOperation.equals(binding.selector, TypeConstants.INIT)) { return ElementKind.INSTANCE_INIT; } else { return ElementKind.METHOD; } }
Example 4
Source File: TypeParameterLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected int matchTypeParameter(TypeVariableBinding variable, boolean matchName) { if (variable == null || variable.declaringElement == null) return INACCURATE_MATCH; if (variable.declaringElement instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) variable.declaringElement; if (matchesName(refBinding.sourceName, this.pattern.declaringMemberName)) { return ACCURATE_MATCH; } } else if (variable.declaringElement instanceof MethodBinding) { MethodBinding methBinding = (MethodBinding) variable.declaringElement; if (matchesName(methBinding.declaringClass.sourceName, this.pattern.methodDeclaringClassName) && (methBinding.isConstructor() || matchesName(methBinding.selector, this.pattern.declaringMemberName))) { int length = this.pattern.methodArgumentTypes==null ? 0 : this.pattern.methodArgumentTypes.length; if (methBinding.parameters == null) { if (length == 0) return ACCURATE_MATCH; } else if (methBinding.parameters.length == length){ for (int i=0; i<length; i++) { if (!matchesName(methBinding.parameters[i].shortReadableName(), this.pattern.methodArgumentTypes[i])) { return IMPOSSIBLE_MATCH; } } return ACCURATE_MATCH; } } } return IMPOSSIBLE_MATCH; }
Example 5
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeMirror getReceiverType(MethodBinding binding) { if (binding != null) { if (binding.receiver != null) { return _env.getFactory().newTypeMirror(binding.receiver); } if (binding.declaringClass != null) { if (!binding.isStatic() && (!binding.isConstructor() || binding.declaringClass.isMemberType())) { return _env.getFactory().newTypeMirror(binding.declaringClass); } } } return NoTypeImpl.NO_TYPE_NONE; }
Example 6
Source File: ConstructorLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected int matchConstructor(MethodBinding constructor) { if (!constructor.isConstructor()) return IMPOSSIBLE_MATCH; // declaring type, simple name has already been matched by matchIndexEntry() int level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, constructor.declaringClass); if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; // parameter types int parameterCount = this.pattern.parameterCount; if (parameterCount > -1) { if (constructor.parameters == null) return INACCURATE_MATCH; if (parameterCount != constructor.parameters.length) return IMPOSSIBLE_MATCH; for (int i = 0; i < parameterCount; i++) { // TODO (frederic) use this call to refine accuracy on parameter types // int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, constructor.parameters[i]); int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], constructor.parameters[i]); if (level > newLevel) { if (newLevel == IMPOSSIBLE_MATCH) { // if (isErasureMatch) { // return ERASURE_MATCH; // } return IMPOSSIBLE_MATCH; } level = newLevel; // can only be downgraded } } } return level; }
Example 7
Source File: FunctionalExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean isPertinentToApplicability(TypeBinding targetType, MethodBinding method) { if (targetType instanceof TypeVariableBinding) { if (method != null) { // when called from type inference if (((TypeVariableBinding)targetType).declaringElement == method) return false; if (method.isConstructor() && ((TypeVariableBinding)targetType).declaringElement == method.declaringClass) return false; } else { // for internal calls TypeVariableBinding typeVariable = (TypeVariableBinding) targetType; if (typeVariable.declaringElement instanceof MethodBinding) return false; } } return true; }
Example 8
Source File: FunctionalExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding invocationTargetType() { if (this.expectedType == null) return null; // when during inference this expression mimics as an invocationSite, // we simulate an *invocation* of this functional expression, // where the expected type of the expression is the return type of the sam: MethodBinding sam = this.expectedType.getSingleAbstractMethod(this.enclosingScope, true); if (sam != null) { if (sam.isConstructor()) return sam.declaringClass; else return sam.returnType; } return null; }
Example 9
Source File: TypeAnnotationCodeStream.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void invoke(byte opcode, MethodBinding methodBinding, TypeBinding declaringClass, TypeReference[] typeArguments) { if (typeArguments != null) { int targetType = methodBinding.isConstructor() ? AnnotationTargetTypeConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT : AnnotationTargetTypeConstants.METHOD_INVOCATION_TYPE_ARGUMENT; for (int i = 0, max = typeArguments.length; i < max; i++) { TypeReference typeArgument = typeArguments[i]; if ((typeArgument.bits & ASTNode.HasTypeAnnotations) != 0) { addAnnotationContext(typeArgument, this.position, i, targetType); } } } super.invoke(opcode, methodBinding, declaringClass, typeArguments); }
Example 10
Source File: ConstantPool.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public int literalIndexForMethodHandle(MethodBinding binding) { boolean isInterface = binding.declaringClass.isInterface(); int referenceKind = isInterface ? binding.isStatic() ? MethodHandleRefKindInvokeStatic : binding.isPrivate() ? MethodHandleRefKindInvokeSpecial : MethodHandleRefKindInvokeInterface : binding.isConstructor() ? MethodHandleRefKindNewInvokeSpecial : binding.isStatic() ? MethodHandleRefKindInvokeStatic : MethodHandleRefKindInvokeVirtual; return literalIndexForMethodHandle(referenceKind, binding.declaringClass, binding.selector, binding.signature(), isInterface); }
Example 11
Source File: Extractor.java From javaide with GNU General Public License v3.0 | 4 votes |
@Nullable static ParameterItem create( AbstractMethodDeclaration methodDeclaration, Argument argument, String classFqn, ClassKind classKind, MethodBinding methodBinding, LocalVariableBinding parameterBinding) { if (classFqn == null || methodBinding == null || parameterBinding == null) { return null; } String methodName = getMethodName(methodBinding); Argument[] arguments = methodDeclaration.arguments; boolean isVarargs = arguments != null && arguments.length > 0 && arguments[arguments.length - 1].isVarArgs(); String parameterList = getParameterList(methodBinding, isVarargs); String returnType = getReturnType(methodBinding); if (methodName == null || returnType == null) { return null; } int index = 0; boolean found = false; if (methodDeclaration.arguments != null) { for (Argument a : methodDeclaration.arguments) { if (a == argument) { found = true; break; } index++; } } if (!found) { return null; } String argNum = Integer.toString(index); //noinspection PointlessBooleanExpression,ConstantConditions if (!INCLUDE_TYPE_ARGS) { classFqn = ApiDatabase.getRawClass(classFqn); methodName = ApiDatabase.getRawMethod(methodName); } return new ParameterItem(classFqn, classKind, returnType, methodName, parameterList, methodBinding.isConstructor(), argNum); }
Example 12
Source File: PatchDelegate.java From EasyMPermission with MIT License | 4 votes |
private static void addAllMethodBindings0(List<BindingTuple> list, TypeBinding binding, Set<String> banList, char[] fieldName, ASTNode responsible) throws DelegateRecursion { if (binding instanceof SourceTypeBinding) ((SourceTypeBinding) binding).scope.environment().globalOptions.storeAnnotations = true; if (binding == null) return; TypeBinding inner; if (binding instanceof ParameterizedTypeBinding) { inner = ((ParameterizedTypeBinding) binding).genericType(); } else { inner = binding; } if (inner instanceof SourceTypeBinding) { ClassScope cs = ((SourceTypeBinding)inner).scope; if (cs != null) { try { Reflection.classScopeBuildFieldsAndMethodsMethod.invoke(cs); } catch (Exception e) { // See 'Reflection' class for why we ignore this exception. } } } if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); FieldBinding[] availableFields = rb.availableFields(); failIfContainsAnnotation(binding, availableMethods); failIfContainsAnnotation(binding, availableFields); MethodBinding[] parameterizedSigs = availableMethods; MethodBinding[] baseSigs = parameterizedSigs; if (binding instanceof ParameterizedTypeBinding) { baseSigs = ((ParameterizedTypeBinding)binding).genericType().availableMethods(); if (baseSigs.length != parameterizedSigs.length) { // The last known state of eclipse source says this can't happen, so we rely on it, // but if this invariant is broken, better to go with 'arg0' naming instead of crashing. baseSigs = parameterizedSigs; } } for (int i = 0; i < parameterizedSigs.length; i++) { MethodBinding mb = parameterizedSigs[i]; String sig = printSig(mb); if (mb.isStatic()) continue; if (mb.isBridge()) continue; if (mb.isConstructor()) continue; if (mb.isDefaultAbstract()) continue; if (!mb.isPublic()) continue; if (mb.isSynthetic()) continue; if (!banList.add(sig)) continue; // If add returns false, it was already in there. BindingTuple pair = new BindingTuple(mb, baseSigs[i], fieldName, responsible); list.add(pair); } addAllMethodBindings0(list, rb.superclass(), banList, fieldName, responsible); ReferenceBinding[] interfaces = rb.superInterfaces(); if (interfaces != null) { for (ReferenceBinding iface : interfaces) addAllMethodBindings0(list, iface, banList, fieldName, responsible); } } }
Example 13
Source File: ElementsImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Add the members of a type to the maps of subtypes, fields, and methods. Add only those * which are non-private and which are not overridden by an already-discovered member. * For fields, add them all; javac implementation does not take field hiding into account. * @param binding the type whose members will be added to the lists * @param ignoreVisibility if true, all members will be added regardless of whether they * are private, overridden, etc. * @param types a map of type simple name to type binding * @param fields a list of field bindings * @param methods a map of method simple name to set of method bindings with that name */ private void addMembers(ReferenceBinding binding, boolean ignoreVisibility, Map<String, ReferenceBinding> types, List<FieldBinding> fields, Map<String, Set<MethodBinding>> methods) { for (ReferenceBinding subtype : binding.memberTypes()) { if (ignoreVisibility || !subtype.isPrivate()) { String name = new String(subtype.sourceName()); if (null == types.get(name)) { types.put(name, subtype); } } } for (FieldBinding field : binding.fields()) { if (ignoreVisibility || !field.isPrivate()) { fields.add(field); } } for (MethodBinding method : binding.methods()) { if (!method.isSynthetic() && (ignoreVisibility || (!method.isPrivate() && !method.isConstructor()))) { String methodName = new String(method.selector); Set<MethodBinding> sameNamedMethods = methods.get(methodName); if (null == sameNamedMethods) { // New method name. Create a set for it and add it to the list. // We don't expect many methods with same name, so only 4 slots: sameNamedMethods = new HashSet<MethodBinding>(4); methods.put(methodName, sameNamedMethods); sameNamedMethods.add(method); } else { // We already have a method with this name. Is this method overridden? boolean unique = true; if (!ignoreVisibility) { for (MethodBinding existing : sameNamedMethods) { MethodVerifier verifier = _env.getLookupEnvironment().methodVerifier(); if (verifier.doesMethodOverride(existing, method)) { unique = false; break; } } } if (unique) { sameNamedMethods.add(method); } } } } }
Example 14
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void searchVisibleLocalMethods( MethodBinding[] methods, ReferenceBinding receiverType, Scope scope, InvocationSite invocationSite, Scope invocationScope, boolean onlyStaticMethods, ObjectVector methodsFound) { ObjectVector newMethodsFound = new ObjectVector(); // Inherited methods which are hidden by subclasses are filtered out // No visibility checks can be performed without the scope & invocationSite next : for (int f = methods.length; --f >= 0;) { MethodBinding method = methods[f]; if (method.isSynthetic()) continue next; if (method.isDefaultAbstract()) continue next; if (method.isConstructor()) continue next; if (onlyStaticMethods && !method.isStatic()) continue next; if (!method.canBeSeenBy(receiverType, invocationSite, scope)) continue next; for (int i = methodsFound.size; --i >= 0;) { MethodBinding otherMethod = (MethodBinding) methodsFound.elementAt(i); if (method == otherMethod) continue next; if (CharOperation.equals(method.selector, otherMethod.selector, true)) { if (this.lookupEnvironment.methodVerifier().isMethodSubsignature(otherMethod, method)) { continue next; } } } newMethodsFound.add(method); } methodsFound.addAll(newMethodsFound); }
Example 15
Source File: CodeSnippetClassFile.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * INTERNAL USE-ONLY * Request the creation of a ClassFile compatible representation of a problematic type * * @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration * @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult */ public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) { SourceTypeBinding typeBinding = typeDeclaration.binding; ClassFile classFile = new CodeSnippetClassFile(typeBinding, null, true); // inner attributes if (typeBinding.hasMemberTypes()) { // see bug 180109 ReferenceBinding[] members = typeBinding.memberTypes; for (int i = 0, l = members.length; i < l; i++) classFile.recordInnerClasses(members[i]); } // TODO (olivier) handle cases where a field cannot be generated (name too long) // TODO (olivier) handle too many methods // inner attributes if (typeBinding.isNestedType()) { classFile.recordInnerClasses(typeBinding); } TypeVariableBinding[] typeVariables = typeBinding.typeVariables(); for (int i = 0, max = typeVariables.length; i < max; i++) { TypeVariableBinding typeVariableBinding = typeVariables[i]; if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, typeVariableBinding); } } // add its fields FieldBinding[] fields = typeBinding.fields(); if ((fields != null) && (fields != Binding.NO_FIELDS)) { classFile.addFieldInfos(); } else { // we have to set the number of fields to be equals to 0 classFile.contents[classFile.contentsOffset++] = 0; classFile.contents[classFile.contentsOffset++] = 0; } // leave some space for the methodCount classFile.setForMethodInfos(); // add its user defined methods int problemsLength; CategorizedProblem[] problems = unitResult.getErrors(); if (problems == null) { problems = new CategorizedProblem[0]; } CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length]; System.arraycopy(problems, 0, problemsCopy, 0, problemsLength); AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods; boolean abstractMethodsOnly = false; if (methodDecls != null) { if (typeBinding.isInterface()) { if (typeBinding.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) abstractMethodsOnly = true; // We generate a clinit which contains all the problems, since we may not be able to generate problem methods (< 1.8) and problem constructors (all levels). classFile.addProblemClinit(problemsCopy); } for (int i = 0, length = methodDecls.length; i < length; i++) { AbstractMethodDeclaration methodDecl = methodDecls[i]; MethodBinding method = methodDecl.binding; if (method == null) continue; if (abstractMethodsOnly) { method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } if (method.isConstructor()) { if (typeBinding.isInterface()) continue; classFile.addProblemConstructor(methodDecl, method, problemsCopy); } else if (method.isAbstract()) { classFile.addAbstractMethod(methodDecl, method); } else { classFile.addProblemMethod(methodDecl, method, problemsCopy); } } // add abstract methods classFile.addDefaultAbstractMethods(); } // propagate generation of (problem) member types if (typeDeclaration.memberTypes != null) { for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) { TypeDeclaration memberType = typeDeclaration.memberTypes[i]; if (memberType.binding != null) { ClassFile.createProblemType(memberType, unitResult); } } } classFile.addAttributes(); unitResult.record(typeBinding.constantPoolName(), classFile); }