Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isSynthetic()

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isSynthetic() . 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: SelectionOnReferenceExpressionName.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {
	TypeBinding type = super.resolveType(scope);
	if (type instanceof PolyTypeBinding)
		return type;
	MethodBinding method = getMethodBinding();
	if (method != null && method.isValidBinding() && !method.isSynthetic())
		throw new SelectionNodeFound(this.actualMethodBinding);
	throw new SelectionNodeFound();
}
 
Example 2
Source File: PatchDelegate.java    From EasyMPermission with MIT License 4 votes vote down vote up
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 3
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 4
Source File: InternalExtendedCompletionContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
}