use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class IntellijLintUtils method getUastLocation.
/**
* Gets the location of the given element
*
* @param file the file containing the location
* @param element the element to look up the location for
* @return the location of the given element
*/
@NonNull
public static Location getUastLocation(@NonNull File file, @NonNull UElement element) {
//noinspection ConstantConditions
PsiFile containingPsiFile = UastUtils.getContainingFile(element).getPsi();
assert containingPsiFile.getVirtualFile() == null || FileUtil.filesEqual(VfsUtilCore.virtualToIoFile(containingPsiFile.getVirtualFile()), file);
if (element instanceof UClass) {
// Point to the name rather than the beginning of the javadoc
UClass clz = (UClass) element;
UElement nameIdentifier = clz.getUastAnchor();
if (nameIdentifier != null) {
element = nameIdentifier;
}
}
TextRange textRange = null;
PsiElement psi = element.getPsi();
if (psi != null) {
textRange = psi.getTextRange();
} else if (element instanceof UElementWithLocation) {
UElementWithLocation elementWithLocation = (UElementWithLocation) element;
textRange = new TextRange(elementWithLocation.getStartOffset(), elementWithLocation.getEndOffset());
}
if (textRange == null) {
return Location.NONE;
}
Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
return Location.create(file, start, end);
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class DefaultConfiguration method getSeverity.
@Override
@NonNull
public Severity getSeverity(@NonNull Issue issue) {
ensureInitialized();
Severity severity = mSeverity.get(issue.getId());
if (severity == null) {
severity = mSeverity.get(VALUE_ALL);
}
if (severity != null) {
return severity;
}
if (mParent != null) {
return mParent.getSeverity(issue);
}
return getDefaultSeverity(issue);
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class DefaultConfiguration method formatError.
private void formatError(String message, Object... args) {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
message = "Failed to parse `lint.xml` configuration file: " + message;
LintDriver driver = new LintDriver(new IssueRegistry() {
@Override
@NonNull
public List<Issue> getIssues() {
return Collections.emptyList();
}
}, mClient);
mClient.report(new Context(driver, mProject, mProject, mConfigFile), IssueRegistry.LINT_ERROR, mProject.getConfiguration(driver).getSeverity(IssueRegistry.LINT_ERROR), Location.create(mConfigFile), message, TextFormat.RAW);
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class ControlFlowGraph method create.
/**
* Creates a new {@link ControlFlowGraph} and populates it with the flow
* control for the given method. If the optional {@code initial} parameter is
* provided with an existing graph, then the graph is simply populated, not
* created. This allows subclassing of the graph instance, if necessary.
*
* @param initial usually null, but can point to an existing instance of a
* {@link ControlFlowGraph} in which that graph is reused (but
* populated with new edges)
* @param classNode the class containing the method to be analyzed
* @param method the method to be analyzed
* @return a {@link ControlFlowGraph} with nodes for the control flow in the
* given method
* @throws AnalyzerException if the underlying bytecode library is unable to
* analyze the method bytecode
*/
@NonNull
public static ControlFlowGraph create(@Nullable ControlFlowGraph initial, @NonNull ClassNode classNode, @NonNull MethodNode method) throws AnalyzerException {
final ControlFlowGraph graph = initial != null ? initial : new ControlFlowGraph();
final InsnList instructions = method.instructions;
graph.mNodeMap = Maps.newHashMapWithExpectedSize(instructions.size());
graph.mMethod = method;
// Create a flow control graph using ASM5's analyzer. According to the ASM 4 guide
// (download.forge.objectweb.org/asm/asm4-guide.pdf) there are faster ways to construct
// it, but those require a lot more code.
Analyzer analyzer = new Analyzer(new BasicInterpreter()) {
@Override
protected void newControlFlowEdge(int insn, int successor) {
// Update the information as of whether the this object has been
// initialized at the given instruction.
AbstractInsnNode from = instructions.get(insn);
AbstractInsnNode to = instructions.get(successor);
graph.add(from, to);
}
@Override
protected boolean newControlFlowExceptionEdge(int insn, TryCatchBlockNode tcb) {
AbstractInsnNode from = instructions.get(insn);
graph.exception(from, tcb);
return super.newControlFlowExceptionEdge(insn, tcb);
}
@Override
protected boolean newControlFlowExceptionEdge(int insn, int successor) {
AbstractInsnNode from = instructions.get(insn);
AbstractInsnNode to = instructions.get(successor);
graph.exception(from, to);
return super.newControlFlowExceptionEdge(insn, successor);
}
};
analyzer.analyze(classNode.name, method);
return graph;
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class SupportAnnotationDetector method mergeAnnotationPermissions.
@NonNull
private static PermissionHolder mergeAnnotationPermissions(@NonNull PermissionHolder permissions, @Nullable UAnnotation annotation) {
if (annotation != null) {
PermissionRequirement requirement = PermissionRequirement.create(annotation);
permissions = SetPermissionLookup.join(permissions, requirement);
}
return permissions;
}
Aggregations