org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding. 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: AnnotationProcessorManager.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) {
  if (!isLastRound && suppressRegularRounds) {
    return;
  }

  if (isLastRound && suppressLastRound) {
    return;
  }

  RoundEnvImpl roundEnv = new _RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv);
  if (_isFirstRound) {
    _isFirstRound = false;
  }
  PrintWriter traceProcessorInfo = _printProcessorInfo ? _out : null;
  PrintWriter traceRounds = _printRounds ? _out : null;
  if (traceRounds != null) {
    traceRounds.println("Round " + ++_round + ':'); //$NON-NLS-1$
  }
  RoundDispatcher dispatcher = new RoundDispatcher(this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds);
  dispatcher.round();
}
 
Example #2
Source File: Sorting.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static int sort(ReferenceBinding[] input, int i,
						ReferenceBinding[] output, int o)
{
	if (input[i] == null)
		return o;

	ReferenceBinding superclass = input[i].superclass();
	o = sortSuper(superclass, input, output, o);

	ReferenceBinding[] superInterfaces = input[i].superInterfaces();
	for (int j=0; j<superInterfaces.length; j++) {
		o = sortSuper(superInterfaces[j], input, output, o);
	}

	// done with supers, now input[i] can safely be transferred:
	output[o++] = input[i];
	input[i] = null;

	return o;
}
 
Example #3
Source File: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean hides(Element hidden)
{
	if (!(hidden instanceof TypeElementImpl)) {
		return false;
	}
	ReferenceBinding hiddenBinding = (ReferenceBinding)((TypeElementImpl)hidden)._binding;
	if (hiddenBinding.isPrivate()) {
		return false;
	}
	ReferenceBinding hiderBinding = (ReferenceBinding)_binding;
	if (TypeBinding.equalsEquals(hiddenBinding, hiderBinding)) {
		return false;
	}
	if (!hiddenBinding.isMemberType() || !hiderBinding.isMemberType()) {
		return false;
	}
	if (!CharOperation.equals(hiddenBinding.sourceName, hiderBinding.sourceName)) {
		return false;
	}
	return null != hiderBinding.enclosingType().findSuperTypeOriginatingFrom(hiddenBinding.enclosingType()); 
}
 
Example #4
Source File: AnnotationBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IMemberValuePairBinding[] getDeclaredMemberValuePairs() {
	ReferenceBinding typeBinding = this.binding.getAnnotationType();
	if (typeBinding == null || ((typeBinding.tagBits & TagBits.HasMissingType) != 0)) {
		return MemberValuePairBinding.NoPair;
	}
	ElementValuePair[] internalPairs = this.binding.getElementValuePairs();
	int length = internalPairs.length;
	IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length];
	int counter = 0;
	for (int i = 0; i < length; i++) {
		ElementValuePair valuePair = internalPairs[i];
		if (valuePair.binding == null) continue;
		pairs[counter++] = this.bindingResolver.getMemberValuePairBinding(valuePair);
	}
	if (counter == 0) return MemberValuePairBinding.NoPair;
	if (counter != length) {
		// resize
		System.arraycopy(pairs, 0, (pairs = new MemberValuePairBinding[counter]), 0, counter);
	}
	return pairs;
}
 
Example #5
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private AnnotationMirrorImpl createAnnotationMirror(String annoTypeName, AnnotationBinding annoInstance) {
	ReferenceBinding binding = annoInstance.getAnnotationType();
	if (binding != null && binding.isAnnotationType() ) {
		char[] qName;
		if (binding.isMemberType()) {
			annoTypeName = annoTypeName.replace('$', '.');
			qName = CharOperation.concatWith(binding.enclosingType().compoundName, binding.sourceName, '.');
			CharOperation.replace(qName, '$', '.');
		} else {
			qName = CharOperation.concatWith(binding.compoundName, '.');
		}
		if(annoTypeName.equals(new String(qName)) ){
			return (AnnotationMirrorImpl)_env.getFactory().newAnnotationMirror(annoInstance);
		}
	}
	return null;
}
 
Example #6
Source File: HashtableOfType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ReferenceBinding put(char[] key, ReferenceBinding value) {
	int length = this.keyTable.length,
		index = CharOperation.hashCode(key) % length;
	int keyLength = key.length;
	char[] currentKey;
	while ((currentKey = this.keyTable[index]) != null) {
		if (currentKey.length == keyLength && CharOperation.equals(currentKey, key))
			return this.valueTable[index] = value;
		if (++index == length) {
			index = 0;
		}
	}
	this.keyTable[index] = key;
	this.valueTable[index] = value;

	// assumes the threshold is never equal to the size of the table
	if (++this.elementSize > this.threshold)
		rehash();
	return value;
}
 
Example #7
Source File: PatchExtensionMethod.java    From EasyMPermission with MIT License 6 votes vote down vote up
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
	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;
}
 
Example #8
Source File: HashtableOfType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ReferenceBinding getput(char[] key, ReferenceBinding value) {
	ReferenceBinding retVal = null;
	int length = this.keyTable.length,
		index = CharOperation.hashCode(key) % length;
	int keyLength = key.length;
	char[] currentKey;
	while ((currentKey = this.keyTable[index]) != null) {
		if (currentKey.length == keyLength && CharOperation.equals(currentKey, key)) {
			retVal = this.valueTable[index];
			this.valueTable[index] = value;
			return retVal;
		}
		if (++index == length) {
			index = 0;
		}
	}
	this.keyTable[index] = key;
	this.valueTable[index] = value;

	// assumes the threshold is never equal to the size of the table
	if (++this.elementSize > this.threshold)
		rehash();
	return retVal;
}
 
Example #9
Source File: BindingKeyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void consumeAnnotation() {
	int size = this.types.size();
	if (size == 0) return;
	Binding annotationType = ((BindingKeyResolver) this.types.get(size-1)).compilerBinding;
	AnnotationBinding[] annotationBindings;
	if (this.compilerBinding == null && this.typeBinding instanceof ReferenceBinding) {
		annotationBindings = ((ReferenceBinding) this.typeBinding).getAnnotations();
	} else if (this.compilerBinding instanceof MethodBinding) {
		annotationBindings = ((MethodBinding) this.compilerBinding).getAnnotations();
	} else if (this.compilerBinding instanceof VariableBinding) {
		annotationBindings = ((VariableBinding) this.compilerBinding).getAnnotations();
	} else {
		return;
	}
	for (int i = 0, length = annotationBindings.length; i < length; i++) {
		AnnotationBinding binding = annotationBindings[i];
		if (binding.getAnnotationType() == annotationType) {
			this.annotationBinding = binding;
			break;
		}
	}
}
 
Example #10
Source File: TypesImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
 public List<? extends TypeMirror> directSupertypes(TypeMirror t) {
     switch(t.getKind()) {
         case PACKAGE :
         case EXECUTABLE :
             throw new IllegalArgumentException("Invalid type mirror for directSupertypes"); //$NON-NLS-1$
         default:
             break;
     }
     TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) t;
     Binding binding = typeMirrorImpl._binding;
     if (binding instanceof ReferenceBinding) {
     	ReferenceBinding referenceBinding = (ReferenceBinding) binding;
     	ArrayList<TypeMirror> list = new ArrayList<TypeMirror>();
     	ReferenceBinding superclass = referenceBinding.superclass();
if (superclass != null) {
     		list.add(this._env.getFactory().newTypeMirror(superclass));
     	}
for (ReferenceBinding interfaceBinding : referenceBinding.superInterfaces()) {
     		list.add(this._env.getFactory().newTypeMirror(interfaceBinding));
}
return Collections.unmodifiableList(list);
     }
     return Collections.emptyList();
 }
 
Example #11
Source File: BindingKeyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void consumeWildCard(int kind) {
	switch (kind) {
		case Wildcard.EXTENDS:
		case Wildcard.SUPER:
			BindingKeyResolver boundResolver = (BindingKeyResolver) this.types.get(0);
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847, do not allow creation of
			// internally inconsistent wildcards of the form '? super <null>' or '? extends <null>'
			final Binding boundBinding = boundResolver.compilerBinding;
			if (boundBinding instanceof TypeBinding) {
				this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundBinding, null /*no extra bound*/, kind);
			} else {
				this.typeBinding = null;
			}
			break;
		case Wildcard.UNBOUND:
			this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind);
			break;
	}
}
 
Example #12
Source File: ExplicitConstructorCall.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)	{
		// if constructor from parameterized type got found, use the original constructor at codegen time
		MethodBinding codegenBinding = this.binding.original();

		// perform some emulation work in case there is some and we are inside a local type only
		if (this.binding.isPrivate() && this.accessMode != ExplicitConstructorCall.This) {
			ReferenceBinding declaringClass = codegenBinding.declaringClass;
			// from 1.4 on, local type constructor can lose their private flag to ease emulation
			if ((declaringClass.tagBits & TagBits.IsLocalType) != 0 && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
				// constructor will not be dumped as private, no emulation required thus
				codegenBinding.tagBits |= TagBits.ClearPrivateModifier;
			} else {
				this.syntheticAccessor = ((SourceTypeBinding) declaringClass).addSyntheticMethod(codegenBinding, isSuperAccess());
				currentScope.problemReporter().needToEmulateMethodAccess(codegenBinding, this);
			}
		}
	}
}
 
Example #13
Source File: ExceptionHandlingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void recordHandlingException(
		ReferenceBinding exceptionType,
		UnconditionalFlowInfo flowInfo,
		TypeBinding raisedException,
		TypeBinding caughtException,
		ASTNode invocationSite,
		boolean wasAlreadyDefinitelyCaught) {

	int index = this.indexes.get(exceptionType);
	int cacheIndex = index / ExceptionHandlingFlowContext.BitCacheSize;
	int bitMask = 1 << (index % ExceptionHandlingFlowContext.BitCacheSize);
	if (!wasAlreadyDefinitelyCaught) {
		this.isNeeded[cacheIndex] |= bitMask;
	}
	this.isReached[cacheIndex] |= bitMask;
	int catchBlock = this.exceptionToCatchBlockMap != null? this.exceptionToCatchBlockMap[index] : index;
	if (caughtException != null && this.catchArguments != null && this.catchArguments.length > 0 && !wasAlreadyDefinitelyCaught) {
		CatchParameterBinding catchParameter = (CatchParameterBinding) this.catchArguments[catchBlock].binding;
		catchParameter.setPreciseType(caughtException);
	}
	this.initsOnExceptions[catchBlock] =
		(this.initsOnExceptions[catchBlock].tagBits & FlowInfo.UNREACHABLE) == 0 ?
			this.initsOnExceptions[catchBlock].mergedWith(flowInfo):
			flowInfo.unconditionalCopy();
}
 
Example #14
Source File: JavaStatementPostfixContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is a recursive method which performs a depth first search in the inheritance graph of the given {@link TypeBinding}.
 * 
 * @param sb a TypeBinding
 * @param signature a fully qualified type
 * @return true if the given TypeBinding itself or one of its superclass/superinterfaces resolves to the given signature. false otherwise.
 */
private boolean resolvesReferenceBindingTo(TypeBinding sb, String signature) {
	if (sb == null) {
		return false;
	}
	if (new String(sb.readableName()).startsWith(signature) || (sb instanceof ArrayBinding && "array".equals(signature))) {
		return true;
	}
	List<ReferenceBinding> bindings = new ArrayList<>();
	Collections.addAll(bindings, sb.superInterfaces());
	bindings.add(sb.superclass());
	boolean result = false;
	Iterator<ReferenceBinding> it = bindings.iterator();
	while (it.hasNext() && result == false) {
		result = resolvesReferenceBindingTo(it.next(), signature);
	}
	return result;
}
 
Example #15
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public ResolvedField getField(@NonNull String name, boolean includeInherited) {
    if (mBinding instanceof ReferenceBinding) {
        ReferenceBinding cls = (ReferenceBinding) mBinding;
        while (cls != null) {
            FieldBinding[] fields = cls.fields();
            if (fields != null) {
                for (FieldBinding field : fields) {
                    if (sameChars(name, field.name)) {
                        return new EcjResolvedField(field);
                    }
                }
            }
            if (includeInherited) {
                cls = cls.superclass();
            } else {
                break;
            }
        }
    }

    return null;
}
 
Example #16
Source File: PackageElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<? extends Element> getEnclosedElements() {
	PackageBinding binding = (PackageBinding)_binding;
	LookupEnvironment environment = binding.environment;
	char[][][] typeNames = null;
	INameEnvironment nameEnvironment = binding.environment.nameEnvironment;
	if (nameEnvironment instanceof FileSystem) {
		typeNames = ((FileSystem) nameEnvironment).findTypeNames(binding.compoundName);
	}
	HashSet<Element> set = new HashSet<Element>(); 
	if (typeNames != null) {
		for (char[][] typeName : typeNames) {
			ReferenceBinding type = environment.getType(typeName);
			if (type != null && type.isValidBinding()) {
				set.add(_env.getFactory().newElement(type));
			}
		}
	}
	ArrayList<Element> list = new ArrayList<Element>(set.size());
	list.addAll(set);
	return Collections.unmodifiableList(list);
}
 
Example #17
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isSubclassOf(@NonNull String name, boolean strict) {
    if (mBinding instanceof ReferenceBinding) {
        ReferenceBinding cls = (ReferenceBinding) mBinding;
        if (strict) {
            cls = cls.superclass();
        }
        for (; cls != null; cls = cls.superclass()) {
            if (sameChars(name, cls.readableName())) {
                return true;
            }
        }
    }

    return false;
}
 
Example #18
Source File: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<? extends TypeMirror> getInterfaces() {
	ReferenceBinding binding = (ReferenceBinding)_binding;
	if (null == binding.superInterfaces() || binding.superInterfaces().length == 0) {
		return Collections.emptyList();
	}
	List<TypeMirror> interfaces = new ArrayList<TypeMirror>(binding.superInterfaces().length);
	for (ReferenceBinding interfaceBinding : binding.superInterfaces()) {
		TypeMirror interfaceType = _env.getFactory().newTypeMirror(interfaceBinding);
		if (interfaceType.getKind() == TypeKind.ERROR) {
			if (this._env.getSourceVersion().compareTo(SourceVersion.RELEASE_6) > 0) {
				// for jdk 7 and above, add error types
				interfaces.add(interfaceType);
			}
		} else {
			interfaces.add(interfaceType);
		}
	}
	return Collections.unmodifiableList(interfaces);
}
 
Example #19
Source File: SelectionOnMessageSend.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private MethodBinding findNonDefaultAbstractMethod(MethodBinding methodBinding) {

		ReferenceBinding[] itsInterfaces = methodBinding.declaringClass.superInterfaces();
		if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
			ReferenceBinding[] interfacesToVisit = itsInterfaces;
			int nextPosition = interfacesToVisit.length;

			for (int i = 0; i < nextPosition; i++) {
				ReferenceBinding currentType = interfacesToVisit[i];
				MethodBinding[] methods = currentType.getMethods(methodBinding.selector);
				if(methods != null) {
					for (int k = 0; k < methods.length; k++) {
						if(methodBinding.areParametersEqual(methods[k]))
							return methods[k];
					}
				}

				if ((itsInterfaces = currentType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
					int itsLength = itsInterfaces.length;
					if (nextPosition + itsLength >= interfacesToVisit.length)
						System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
					nextInterface : for (int a = 0; a < itsLength; a++) {
						ReferenceBinding next = itsInterfaces[a];
						for (int b = 0; b < nextPosition; b++)
							if (TypeBinding.equalsEquals(next, interfacesToVisit[b])) continue nextInterface;
						interfacesToVisit[nextPosition++] = next;
					}
				}
			}
		}
		return methodBinding;
	}
 
Example #20
Source File: RoundEnvImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * For every type in types that is a class and that is annotated with anno, either directly or by inheritance,
 * add that type to result.  Recursively descend on each types's child classes as well.
 * @param anno the compiler binding for an annotation type
 * @param type a type, not necessarily a class
 * @param result must be a modifiable Set; will accumulate annotated classes
 */
private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, Set<Element> result) {
	if (type.isClass()) {
		if (inheritsAnno(type, anno)) {
			result.add(_factory.newElement(type));
		}
	}
	for (ReferenceBinding element : type.memberTypes()) {
		addAnnotatedElements(anno, element, result);
	}
}
 
Example #21
Source File: ExceptionHandlingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ExceptionHandlingFlowContext(
			FlowContext parent,
			ASTNode associatedNode,
			ReferenceBinding[] handledExceptions,
			FlowContext initializationParent,
			BlockScope scope,
			UnconditionalFlowInfo flowInfo) {
	this(parent, associatedNode, handledExceptions, null, NO_ARGUMENTS, initializationParent, scope, flowInfo);
}
 
Example #22
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isMember() {
	if (isClass() || isInterface() || isEnum()) {
		ReferenceBinding referenceBinding = (ReferenceBinding) this.binding;
		return referenceBinding.isMemberType();
	}
	return false;
}
 
Example #23
Source File: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding getConstructor(ReferenceBinding receiverType, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
	MethodBinding methodBinding = receiverType.getExactConstructor(argumentTypes);
	if (methodBinding != null) {
		if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this)) {
			return methodBinding;
		}
	}
	MethodBinding[] methods = receiverType.getMethods(TypeConstants.INIT);
	if (methods == Binding.NO_METHODS) {
		return new ProblemMethodBinding(TypeConstants.INIT, argumentTypes, ProblemReasons.NotFound);
	}
	MethodBinding[] compatible = new MethodBinding[methods.length];
	int compatibleIndex = 0;
	for (int i = 0, length = methods.length; i < length; i++) {
	    MethodBinding compatibleMethod = computeCompatibleMethod(methods[i], argumentTypes, invocationSite, Scope.APPLICABILITY);
		if (compatibleMethod != null)
			compatible[compatibleIndex++] = compatibleMethod;
	}
	if (compatibleIndex == 0)
		return new ProblemMethodBinding(TypeConstants.INIT, argumentTypes, ProblemReasons.NotFound); // need a more descriptive error... cannot convert from X to Y

	MethodBinding[] visible = new MethodBinding[compatibleIndex];
	int visibleIndex = 0;
	for (int i = 0; i < compatibleIndex; i++) {
		MethodBinding method = compatible[i];
		if (canBeSeenByForCodeSnippet(method, receiverType, invocationSite, this)) {
			visible[visibleIndex++] = method;
		}
	}
	if (visibleIndex == 1) {
		// 1.8: Give inference a chance to perform outstanding tasks (18.5.2):
		return inferInvocationType(invocationSite, visible[0], argumentTypes);
	}
	if (visibleIndex == 0) {
		return new ProblemMethodBinding(compatible[0], TypeConstants.INIT, compatible[0].parameters, ProblemReasons.NotVisible);
	}
	return mostSpecificClassMethodBinding(visible, visibleIndex, invocationSite);
}
 
Example #24
Source File: PackageElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected AnnotationBinding[] getAnnotationBindings()
{
	PackageBinding packageBinding = (PackageBinding) this._binding;
	char[][] compoundName = CharOperation.arrayConcat(packageBinding.compoundName, TypeConstants.PACKAGE_INFO_NAME);
	ReferenceBinding type = this._env.getLookupEnvironment().getType(compoundName);
	AnnotationBinding[] annotations = null;
	if (type != null && type.isValidBinding()) {
		annotations = type.getAnnotations();
	}
	return annotations;
}
 
Example #25
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public TypeElement getTypeElement(CharSequence name) {
	LookupEnvironment le = _env.getLookupEnvironment();
	final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
	ReferenceBinding binding = le.getType(compoundName);
	// If we didn't find the binding, maybe it's a nested type;
	// try finding the top-level type and then working downwards.
	if (null == binding) {
		ReferenceBinding topLevelBinding = null;
		int topLevelSegments = compoundName.length;
		while (--topLevelSegments > 0) {
			char[][] topLevelName = new char[topLevelSegments][];
			for (int i = 0; i < topLevelSegments; ++i) {
				topLevelName[i] = compoundName[i];
			}
			topLevelBinding = le.getType(topLevelName);
			if (null != topLevelBinding) {
				break;
			}
		}
		if (null == topLevelBinding) {
			return null;
		}
		binding = topLevelBinding;
		for (int i = topLevelSegments; null != binding && i < compoundName.length; ++i) {
			binding = binding.getMemberType(compoundName[i]);
		}
	}
	if (null == binding) {
		return null;
	}
	return new TypeElementImpl(_env, binding, null);
}
 
Example #26
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Name getBinaryName(TypeElement type) {
	TypeElementImpl typeElementImpl = (TypeElementImpl) type;
	ReferenceBinding referenceBinding = (ReferenceBinding) typeElementImpl._binding;
	return new NameImpl(
		CharOperation.replaceOnCopy(referenceBinding.constantPoolName(), '/', '.'));
}
 
Example #27
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ReferenceBinding getTypeBinding() {

	if (this.classType != null || this.resolvedType == null)
		return null;
	
	class LambdaTypeBinding extends ReferenceBinding {
		public MethodBinding[] methods() {
			return new MethodBinding [] { getMethodBinding() };
		}
		public char[] sourceName() {
			return TypeConstants.LAMBDA_TYPE;
		}
		public ReferenceBinding superclass() {
			return LambdaExpression.this.scope.getJavaLangObject();
		}
		public ReferenceBinding[] superInterfaces() {
			return new ReferenceBinding[] { (ReferenceBinding) LambdaExpression.this.resolvedType };
		}
		@Override
		public char[] computeUniqueKey() {
			return LambdaExpression.this.descriptor.declaringClass.computeUniqueKey();
		}
		public String toString() {
			StringBuffer output = new StringBuffer("()->{} implements "); //$NON-NLS-1$
			output.append(LambdaExpression.this.descriptor.declaringClass.sourceName());
			output.append('.');
			output.append(LambdaExpression.this.descriptor.toString());
			return output.toString();
		}
	}
	return this.classType = new LambdaTypeBinding();
}
 
Example #28
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Recursively depth-first walk the tree of superinterfaces of a type, collecting
 * all the unique superinterface bindings.  (Note that because of generics, a type may
 * have multiple unique superinterface bindings corresponding to the same interface
 * declaration.)
 * @param existing bindings already in this set will not be re-added or recursed into
 * @param newfound newly found bindings will be added to this set
 */
private void collectSuperInterfaces(ReferenceBinding type,
		Set<ReferenceBinding> existing, Set<ReferenceBinding> newfound) {
	for (ReferenceBinding superinterface : type.superInterfaces()) {
		if (!existing.contains(superinterface) && !newfound.contains(superinterface)) {
			newfound.add(superinterface);
			collectSuperInterfaces(superinterface, existing, newfound);
		}
	}
}
 
Example #29
Source File: SuperReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {

		this.constant = Constant.NotAConstant;
		ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType();
		if (!checkAccess(scope, enclosingReceiverType))
			return null;
		if (enclosingReceiverType.id == T_JavaLangObject) {
			scope.problemReporter().cannotUseSuperInJavaLangObject(this);
			return null;
		}
		return this.resolvedType = enclosingReceiverType.superclass();
	}
 
Example #30
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute a list of all the visible entities in this type.  Specifically:
 * <ul>
 * <li>All nested types declared in this type, including interfaces and enums</li>
 * <li>All protected or public nested types declared in this type's superclasses
 * and superinterfaces, that are not hidden by a name collision</li>
 * <li>All methods declared in this type, including constructors but not
 * including static or instance initializers, and including abstract
 * methods and unimplemented methods declared in interfaces</li>
 * <li>All protected or public methods declared in this type's superclasses,
 * that are not overridden by another method, but not including constructors
 * or initializers. Includes abstract methods and methods declared in
 * superinterfaces but not implemented</li>
 * <li>All fields declared in this type, including constants</li>
 * <li>All non-private fields declared in this type's superclasses and
 * superinterfaces, that are not hidden by a name collision.</li>
 * </ul>
 */
@Override
public List<? extends Element> getAllMembers(TypeElement type) {
	if (null == type || !(type instanceof TypeElementImpl)) {
		return Collections.emptyList();
	}
	ReferenceBinding binding = (ReferenceBinding)((TypeElementImpl)type)._binding;
	// Map of element simple name to binding
	Map<String, ReferenceBinding> types = new HashMap<String, ReferenceBinding>();
	// Javac implementation does not take field name collisions into account
	List<FieldBinding> fields = new ArrayList<FieldBinding>();
	// For methods, need to compare parameters, not just names
	Map<String, Set<MethodBinding>> methods = new HashMap<String, Set<MethodBinding>>();
	Set<ReferenceBinding> superinterfaces = new LinkedHashSet<ReferenceBinding>();
	boolean ignoreVisibility = true;
	while (null != binding) {
		addMembers(binding, ignoreVisibility, types, fields, methods);
		Set<ReferenceBinding> newfound = new LinkedHashSet<ReferenceBinding>();
		collectSuperInterfaces(binding, superinterfaces, newfound);
		for (ReferenceBinding superinterface : newfound) {
			addMembers(superinterface, false, types, fields, methods);
		}
		superinterfaces.addAll(newfound);
		binding = binding.superclass();
		ignoreVisibility = false;
	}
	List<Element> allMembers = new ArrayList<Element>();
	for (ReferenceBinding nestedType : types.values()) {
		allMembers.add(_env.getFactory().newElement(nestedType));
	}
	for (FieldBinding field : fields) {
		allMembers.add(_env.getFactory().newElement(field));
	}
	for (Set<MethodBinding> sameNamedMethods : methods.values()) {
		for (MethodBinding method : sameNamedMethods) {
			allMembers.add(_env.getFactory().newElement(method));
		}
	}
	return allMembers;
}