public void dispose() { parser.dispose(); }
@NonNull @Override public CharSequence getFileContents(@NonNull PsiFile file) { if (file instanceof EcjPsiJavaFile) { EcjPsiJavaFile javaFile = (EcjPsiJavaFile) file; return CharBuffer.wrap(javaFile.getFileContents()); } return super.getFileContents(file); }
/** * Returns a {@link Location} for the given node. This attempts to pick a shorter * location range than the entire node; for a class or method for example, it picks * the name node (if found). For statement constructs such as a {@code switch} statement * it will highlight the keyword, etc. * * @param element the AST node to create a location for * @return a location for the given node */ @NonNull public Location getNameLocation(@NonNull PsiElement element) { if (element instanceof PsiSwitchStatement) { // Just use keyword return parser.getRangeLocation(this, element, 0, 6); // 6: "switch".length() } return parser.getNameLocation(this, element); }
@NonNull public Location createLocation(@NonNull PsiElement element) { TextRange range = element.getTextRange(); PsiFile containingFile = element.getContainingFile(); CharSequence contents; File file = getFile(containingFile); if (file == null) { return Location.NONE; } contents = getFileContents(containingFile); return Location.create(file, contents, range.getStartOffset(), range.getEndOffset()); }
void visitFile(@NonNull final JavaContext context) { try { final PsiJavaFile javaFile = parser.parseJavaToPsi(context); if (javaFile == null) { } finally { if (disposeUnitsAfterUse) { parser.dispose(context, javaFile);
/** * Returns a {@link Location} for the given node. This attempts to pick a shorter * location range than the entire node; for a class or method for example, it picks * the name node (if found). For statement constructs such as a {@code switch} statement * it will highlight the keyword, etc. * * @param node the AST node to create a location for * @return a location for the given node */ @NonNull public Location getNameLocation(@NonNull Node node) { return parser.getNameLocation(this, node); }
@NonNull public JavaEvaluator getEvaluator() { return parser.getEvaluator(); }
/** * @deprecated Location handles aren't needed for AST nodes anymore; just use the * {@link PsiElement} from the AST */ @Deprecated @NonNull public Location.Handle createLocationHandle(@NonNull Node node) { return parser.createLocationHandle(this, node); }
/** * @deprecated Use {@link JavaEvaluator#findClass(String)} instead */ @Deprecated @Nullable public ResolvedClass findClass(@NonNull String fullyQualifiedName) { return parser.findClass(this, fullyQualifiedName); }
return super.getCatchTypes(context, catchBlock);
JavaParser parser = client.getJavaParser(project); if (parser != null) { Location secondary = parser.createLocation(usage); secondary.setMessage("Icon used in notification here"); location.setSecondary(secondary);
PsiJavaFile file = javaContext.getJavaFile(); if (file != null) { PsiElement closest = javaContext.getParser().findElementAt(javaContext, i); if (closest == null && file.getClasses().length > 0) { closest = file.getClasses()[0];
/** * 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()); }
@Override @NonNull public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) { // The range on method name identifiers is wrong in the ECJ nodes; just take start of // name + length of name if (node instanceof MethodDeclaration) { MethodDeclaration declaration = (MethodDeclaration) node; Identifier identifier = declaration.astMethodName(); Location location = getLocation(context, identifier); com.android.tools.lint.detector.api.Position start = location.getStart(); com.android.tools.lint.detector.api.Position end = location.getEnd(); int methodNameLength = identifier.astValue().length(); if (start != null && end != null && end.getOffset() - start.getOffset() > methodNameLength) { end = new DefaultPosition(start.getLine(), start.getColumn() + methodNameLength, start.getOffset() + methodNameLength); return Location.create(location.getFile(), start, end); } return location; } return super.getNameLocation(context, node); }