return new CommentChecker(context); } else { String source = context.getContents(); if (source == null) { return null;
private static void checkJava(@NonNull JavaContext context) { CharSequence source = context.getContents(); if (source == null) { return;
/** * @deprecated Use {@link #isSuppressedWithComment(PsiElement, Issue)} instead */ @Deprecated public boolean isSuppressedWithComment(@NonNull Node scope, @NonNull Issue issue) { // Check whether there is a comment marker CharSequence contents = getContents(); assert contents != null; // otherwise we wouldn't be here Position position = scope.getPosition(); if (position == null) { return false; } int start = position.getStart(); return isSuppressedWithComment(start, issue); }
@NonNull @Override public Location getRangeLocation( @NonNull JavaContext context, @NonNull Node from, int fromDelta, @NonNull Node to, int toDelta) { CharSequence contents = context.getContents(); int start = Math.max(0, from.getPosition().getStart() + fromDelta); int end = Math.min(contents == null ? Integer.MAX_VALUE : contents.length(), to.getPosition().getEnd() + toDelta); return Location.create(context.file, contents, start, end); }
public boolean isSuppressedWithComment(@NonNull PsiElement scope, @NonNull Issue issue) { // Check whether there is a comment marker CharSequence contents = getContents(); assert contents != null; // otherwise we wouldn't be here TextRange textRange = scope.getTextRange(); if (textRange == null) { return false; } int start = textRange.getStartOffset(); return isSuppressedWithComment(start, issue); }
@Override public Node parseJava(@NonNull JavaContext context) { CharSequence code = context.getContents(); if (code == null) { return null; } CompilationUnitDeclaration unit = getParsedUnit(context, code); try { EcjTreeConverter converter = new EcjTreeConverter(); converter.visit(code.toString(), unit); List<? extends Node> nodes = converter.getAll(); if (nodes != null) { // There could be more than one node when there are errors; pick out the // compilation unit node for (Node node : nodes) { if (node instanceof lombok.ast.CompilationUnit) { return node; } } } return null; } catch (Throwable t) { client.log(t, "Failed converting ECJ parse tree to Lombok for file %1$s", context.file.getPath()); return null; } }
sourceUnits = Maps.newHashMapWithExpectedSize(sources.size()); for (JavaContext context : contexts) { CharSequence contents = context.getContents(); if (contents == null) { continue;
/** * Returns a {@link Location} for the given node range (from the starting offset of the first * node to the ending offset of the second node). * * @param context information about the file being parsed * @param from the AST node to get a starting location from * @param fromDelta Offset delta to apply to the starting offset * @param to the AST node to get a ending location from * @param toDelta Offset delta to apply to the ending offset * @return a location for the given node */ @SuppressWarnings("MethodMayBeStatic") // subclasses may want to override/optimize @NonNull public Location getRangeLocation( @NonNull JavaContext context, @NonNull PsiElement from, int fromDelta, @NonNull PsiElement to, int toDelta) { CharSequence contents = context.getContents(); TextRange fromRange = from.getTextRange(); int start = Math.max(0, fromRange.getStartOffset() + fromDelta); int end = Math.min(contents == null ? Integer.MAX_VALUE : contents.length(), to.getTextRange().getEndOffset() + toDelta); if (end <= start) { // Some AST nodes don't have proper bounds, such as empty parameter lists return Location.create(context.file, contents, start, fromRange.getEndOffset()); } return Location.create(context.file, contents, start, end); }
@NonNull @Override public Location getLocation(@NonNull JavaContext context, @NonNull Node node) { lombok.ast.Position position = node.getPosition(); // Not all ECJ nodes have offsets; in particular, VariableDefinitionEntries while (position == Position.UNPLACED) { node = node.getParent(); //noinspection ConstantConditions if (node == null) { break; } position = node.getPosition(); } return Location.create(context.file, context.getContents(), position.getStart(), position.getEnd()); }
/** * Returns a {@link Location} for the given element * * @param context information about the file being parsed * @param element the element to create a location for * @return a location for the given node */ @SuppressWarnings("MethodMayBeStatic") // subclasses may want to override/optimize @NonNull public Location getLocation(@NonNull JavaContext context, @NonNull PsiElement element) { TextRange range = element.getTextRange(); PsiFile containingFile = element.getContainingFile(); File file = context.file; CharSequence contents = context.getContents(); if (containingFile != context.getJavaFile()) { // Reporting an error in a different file. if (context.getDriver().getScope().size() == 1) { // Don't bother with this error if it's in a different file during single-file analysis return Location.NONE; } File ioFile = getFile(containingFile); if (ioFile == null) { return Location.NONE; } file = ioFile; contents = getFileContents(containingFile); } return Location.create(file, contents, range.getStartOffset(), range.getEndOffset()); }