use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class LintUtils method getStyleAttributes.
/**
* Looks up the resource values for the given attribute given a style. Note that
* this only looks project-level style values, it does not resume into the framework
* styles.
*/
@Nullable
public static List<ResourceValue> getStyleAttributes(@NonNull Project project, @NonNull LintClient client, @NonNull String styleUrl, @NonNull String namespace, @NonNull String attribute) {
if (!client.supportsProjectResources()) {
return null;
}
AbstractResourceRepository resources = client.getProjectResources(project, true);
if (resources == null) {
return null;
}
ResourceUrl style = ResourceUrl.parse(styleUrl);
if (style == null || style.framework) {
return null;
}
List<ResourceValue> result = null;
Queue<ResourceValue> queue = new ArrayDeque<ResourceValue>();
queue.add(new ResourceValue(style.type, style.name, false));
Set<String> seen = Sets.newHashSet();
int count = 0;
boolean isFrameworkAttribute = ANDROID_URI.equals(namespace);
while (count < 30 && !queue.isEmpty()) {
ResourceValue front = queue.remove();
String name = front.getName();
seen.add(name);
List<ResourceItem> items = resources.getResourceItem(front.getResourceType(), name);
if (items != null) {
for (ResourceItem item : items) {
ResourceValue rv = item.getResourceValue(false);
if (rv instanceof StyleResourceValue) {
StyleResourceValue srv = (StyleResourceValue) rv;
ItemResourceValue value = srv.getItem(attribute, isFrameworkAttribute);
if (value != null) {
if (result == null) {
result = Lists.newArrayList();
}
if (!result.contains(value)) {
result.add(value);
}
}
String parent = srv.getParentStyle();
if (parent != null && !parent.startsWith(ANDROID_PREFIX)) {
ResourceUrl p = ResourceUrl.parse(parent);
if (p != null && !p.framework && !seen.contains(p.name)) {
seen.add(p.name);
queue.add(new ResourceValue(ResourceType.STYLE, p.name, false));
}
}
int index = name.lastIndexOf('.');
if (index > 0) {
String parentName = name.substring(0, index);
if (!seen.contains(parentName)) {
seen.add(parentName);
queue.add(new ResourceValue(ResourceType.STYLE, parentName, false));
}
}
}
}
}
count++;
}
return result;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class LintUtils method getCommonParent.
/**
* Computes the closest common parent path between two files.
*
* @param file1 the first file to be compared
* @param file2 the second file to be compared
* @return the closest common ancestor file, or null if the two files have
* no common parent
*/
@Nullable
public static File getCommonParent(@NonNull File file1, @NonNull File file2) {
if (file1.equals(file2)) {
return file1;
} else if (file1.getPath().startsWith(file2.getPath())) {
return file2;
} else if (file2.getPath().startsWith(file1.getPath())) {
return file1;
} else {
// Dumb and simple implementation
File first = file1.getParentFile();
while (first != null) {
File second = file2.getParentFile();
while (second != null) {
if (first.equals(second)) {
return first;
}
second = second.getParentFile();
}
first = first.getParentFile();
}
}
return null;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class JavaPsiVisitor method getInterfaceNames.
@Nullable
private static Set<String> getInterfaceNames(@Nullable Set<String> addTo, @NonNull PsiClass cls) {
for (PsiClass resolvedInterface : cls.getInterfaces()) {
String name = resolvedInterface.getQualifiedName();
if (addTo == null) {
addTo = Sets.newHashSet();
} else if (addTo.contains(name)) {
// more than once.
continue;
}
addTo.add(name);
getInterfaceNames(addTo, resolvedInterface);
}
return addTo;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class JavaVisitor method getInterfaceNames.
@Nullable
private static Set<String> getInterfaceNames(@Nullable Set<String> addTo, @NonNull ResolvedClass cls) {
Iterable<ResolvedClass> interfaces = cls.getInterfaces();
for (ResolvedClass resolvedInterface : interfaces) {
String name = resolvedInterface.getName();
if (addTo == null) {
addTo = Sets.newHashSet();
} else if (addTo.contains(name)) {
// more than once.
continue;
}
addTo.add(name);
getInterfaceNames(addTo, resolvedInterface);
}
return addTo;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class UastLintUtils method findLastValue.
@Nullable
public static Object findLastValue(@NonNull PsiVariable variable, @NonNull UElement call, @NonNull JavaContext context, @NonNull ConstantEvaluator evaluator) {
Object value = null;
if (!variable.hasModifierProperty(PsiModifier.FINAL) && (variable instanceof PsiLocalVariable || variable instanceof PsiParameter)) {
UMethod containingFunction = UastUtils.getContainingUMethod(call);
if (containingFunction != null) {
ConstantEvaluator.LastAssignmentFinder finder = new ConstantEvaluator.LastAssignmentFinder(variable, call, context, evaluator, 1);
containingFunction.getUastBody().accept(finder);
value = finder.getCurrentValue();
}
} else {
UExpression initializer = context.getUastContext().getInitializerBody(variable);
if (initializer != null) {
value = initializer.evaluate();
}
}
return value;
}
Aggregations