use of org.eclipse.jdt.core.dom.IPackageBinding in project j2objc by google.
the class BindingConverter method getElement.
public static Element getElement(IBinding binding) {
if (binding == null) {
return null;
}
JdtElement element = elementCache.get(binding);
if (element != null) {
return element;
}
if (binding instanceof GeneratedMethodBinding) {
return ((GeneratedMethodBinding) binding).asElement();
} else if (binding instanceof GeneratedVariableBinding) {
return ((GeneratedVariableBinding) binding).asElement();
} else if (binding instanceof IMethodBinding) {
element = new JdtExecutableElement((IMethodBinding) binding);
} else if (binding instanceof IPackageBinding) {
element = new JdtPackageElement((IPackageBinding) binding);
} else if (binding instanceof ITypeBinding) {
ITypeBinding typeBinding = (ITypeBinding) binding;
element = typeBinding.isTypeVariable() || typeBinding.isCapture() ? new JdtTypeParameterElement(typeBinding) : new JdtTypeElement(typeBinding);
} else if (binding instanceof IVariableBinding) {
element = JdtVariableElement.create((IVariableBinding) binding);
} else {
throw new AssertionError("unknown element binding: " + binding.getClass().getSimpleName());
}
elementCache.put(binding, element);
return element;
}
use of org.eclipse.jdt.core.dom.IPackageBinding in project AutoRefactor by JnRouvignac.
the class SuperCallRatherThanUselessOverridingRefactoring method isMethodUsedInItsPackage.
/**
* This method is extremely expensive.
*/
private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) {
final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
final SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
methodIsUsedInPackage.set(true);
}
};
try {
final SearchEngine searchEngine = new SearchEngine();
searchEngine.search(createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, ctx.getProgressMonitor());
return methodIsUsedInPackage.get();
} catch (CoreException e) {
throw new UnhandledException(node, e);
}
}
use of org.eclipse.jdt.core.dom.IPackageBinding in project eclipse.jdt.ls by eclipse.
the class RedundantNullnessTypeAnnotationsFilter method getNNBDAnnotation.
// based on org.eclipse.jdt.apt.core.internal.declaration.ASTBasedDeclarationImpl.getAnnotationInstancesFromAST()
private static /* @Nullable */
IAnnotationBinding getNNBDAnnotation(ASTNode astNode, String nonNullByDefaultName) {
List<IExtendedModifier> extendsMods = null;
switch(astNode.getNodeType()) {
case ASTNode.COMPILATION_UNIT:
{
// special case: when reaching the root of the ast, check the package annotations.
PackageDeclaration packageDeclaration = ((CompilationUnit) astNode).getPackage();
if (packageDeclaration != null) {
IPackageBinding packageBinding = packageDeclaration.resolveBinding();
if (packageBinding != null) {
for (IAnnotationBinding annotationBinding : packageBinding.getAnnotations()) {
ITypeBinding annotationType = annotationBinding.getAnnotationType();
if (annotationType != null && annotationType.getQualifiedName().equals(nonNullByDefaultName)) {
return annotationBinding;
}
}
}
}
return null;
}
case ASTNode.TYPE_DECLARATION:
case ASTNode.ANNOTATION_TYPE_DECLARATION:
case ASTNode.ENUM_DECLARATION:
case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
case ASTNode.METHOD_DECLARATION:
case ASTNode.FIELD_DECLARATION:
case ASTNode.ENUM_CONSTANT_DECLARATION:
extendsMods = ((BodyDeclaration) astNode).modifiers();
break;
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
extendsMods = ((VariableDeclarationStatement) astNode).modifiers();
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
extendsMods = ((VariableDeclarationExpression) astNode).modifiers();
break;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
extendsMods = ((SingleVariableDeclaration) astNode).modifiers();
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
final ASTNode parent = ((VariableDeclarationFragment) astNode).getParent();
if (parent instanceof BodyDeclaration) {
extendsMods = ((BodyDeclaration) parent).modifiers();
}
break;
default:
return null;
}
if (extendsMods != null) {
for (IExtendedModifier extMod : extendsMods) {
if (extMod.isAnnotation()) {
Annotation annotation = (Annotation) extMod;
IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
if (annotationBinding != null) {
ITypeBinding annotationType = annotationBinding.getAnnotationType();
if (annotationType != null && annotationType.getQualifiedName().equals(nonNullByDefaultName)) {
return annotationBinding;
}
}
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.IPackageBinding in project flux by eclipse.
the class BindingLabelProvider method getTypeLabel.
private static void getTypeLabel(ITypeBinding binding, long flags, StringBuffer buffer) {
if ((flags & JavaElementLabels.T_FULLY_QUALIFIED) != 0) {
final IPackageBinding pack = binding.getPackage();
if (pack != null && !pack.isUnnamed()) {
buffer.append(pack.getName());
buffer.append('.');
}
}
if ((flags & (JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED)) != 0) {
final ITypeBinding declaring = binding.getDeclaringClass();
if (declaring != null) {
getTypeLabel(declaring, JavaElementLabels.T_CONTAINER_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
buffer.append('.');
}
final IMethodBinding declaringMethod = binding.getDeclaringMethod();
if (declaringMethod != null) {
getMethodLabel(declaringMethod, 0, buffer);
buffer.append('.');
}
}
if (binding.isCapture()) {
getTypeLabel(binding.getWildcard(), flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
} else if (binding.isWildcardType()) {
buffer.append('?');
ITypeBinding bound = binding.getBound();
if (bound != null) {
if (binding.isUpperbound()) {
// $NON-NLS-1$
buffer.append(" extends ");
} else {
// $NON-NLS-1$
buffer.append(" super ");
}
getTypeLabel(bound, flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
}
} else if (binding.isArray()) {
getTypeLabel(binding.getElementType(), flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
appendDimensions(binding.getDimensions(), buffer);
} else {
// type variables, primitive, reftype
String name = binding.getTypeDeclaration().getName();
if (name.length() == 0) {
if (binding.isEnum()) {
buffer.append('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
} else if (binding.isAnonymous()) {
ITypeBinding[] superInterfaces = binding.getInterfaces();
ITypeBinding baseType;
if (superInterfaces.length > 0) {
baseType = superInterfaces[0];
} else {
baseType = binding.getSuperclass();
}
if (baseType != null) {
StringBuffer anonymBaseType = new StringBuffer();
getTypeLabel(baseType, flags & JavaElementLabels.T_TYPE_PARAMETERS, anonymBaseType);
buffer.append(Messages.format(JavaUIMessages.JavaElementLabels_anonym_type, anonymBaseType.toString()));
} else {
buffer.append(JavaUIMessages.JavaElementLabels_anonym);
}
} else {
// $NON-NLS-1$
buffer.append("UNKNOWN");
}
} else {
buffer.append(name);
}
if ((flags & JavaElementLabels.T_TYPE_PARAMETERS) != 0) {
if (binding.isGenericType()) {
getTypeParametersLabel(binding.getTypeParameters(), buffer);
} else if (binding.isParameterizedType()) {
getTypeArgumentsLabel(binding.getTypeArguments(), flags, buffer);
}
}
}
if ((flags & JavaElementLabels.T_POST_QUALIFIED) != 0) {
final IMethodBinding declaringMethod = binding.getDeclaringMethod();
final ITypeBinding declaringType = binding.getDeclaringClass();
if (declaringMethod != null) {
buffer.append(JavaElementLabels.CONCAT_STRING);
getMethodLabel(declaringMethod, JavaElementLabels.T_FULLY_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
} else if (declaringType != null) {
buffer.append(JavaElementLabels.CONCAT_STRING);
getTypeLabel(declaringType, JavaElementLabels.T_FULLY_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
} else {
final IPackageBinding pack = binding.getPackage();
if (pack != null && !pack.isUnnamed()) {
buffer.append(JavaElementLabels.CONCAT_STRING);
buffer.append(pack.getName());
}
}
}
}
use of org.eclipse.jdt.core.dom.IPackageBinding in project AutoRefactor by JnRouvignac.
the class SuperCallRatherThanUselessOverridingCleanUp method isMethodUsedInItsPackage.
/**
* This method is extremely expensive.
*/
private boolean isMethodUsedInItsPackage(final IMethodBinding methodBinding, final MethodDeclaration visited) {
IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(final SearchMatch match) {
methodIsUsedInPackage.lazySet(true);
}
};
try {
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(SearchPattern.createPattern(methodBinding.getJavaElement(), IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, cuRewrite.getProgressMonitor());
return methodIsUsedInPackage.get();
} catch (CoreException e) {
throw new UnhandledException(visited, e);
}
}
Aggregations