1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tools.lint.client.api; 18 19 import com.android.annotations.NonNull; 20 import com.android.annotations.Nullable; 21 import com.android.tools.lint.detector.api.Context; 22 import com.android.tools.lint.detector.api.JavaContext; 23 import com.android.tools.lint.detector.api.Location; 24 25 import lombok.ast.Node; 26 27 /** 28 * A wrapper for a Java parser. This allows tools integrating lint to map directly 29 * to builtin services, such as already-parsed data structures in Java editors. 30 * <p/> 31 * <b>NOTE: This is not a or final API; if you rely on this be prepared 32 * to adjust your code for the next tools release.</b> 33 */ 34 public interface IJavaParser { 35 /** 36 * Parse the file pointed to by the given context. 37 * 38 * @param context the context pointing to the file to be parsed, typically 39 * via {@link Context#getContents()} but the file handle ( 40 * {@link Context#file} can also be used to map to an existing 41 * editor buffer in the surrounding tool, etc) 42 * @return the compilation unit node for the file 43 */ 44 @Nullable parseJava(@onNull JavaContext context)45 Node parseJava(@NonNull JavaContext context); 46 47 /** 48 * Returns a {@link Location} for the given node 49 * 50 * @param context information about the file being parsed 51 * @param node the node to create a location for 52 * @return a location for the given node 53 */ 54 @NonNull getLocation(@onNull JavaContext context, @NonNull Node node)55 Location getLocation(@NonNull JavaContext context, @NonNull Node node); 56 57 /** 58 * Creates a light-weight handle to a location for the given node. It can be 59 * turned into a full fledged location by 60 * {@link com.android.tools.lint.detector.api.Location.Handle#resolve()}. 61 * 62 * @param context the context providing the node 63 * @param node the node (element or attribute) to create a location handle 64 * for 65 * @return a location handle 66 */ 67 @NonNull createLocationHandle(@onNull JavaContext context, @NonNull Node node)68 Location.Handle createLocationHandle(@NonNull JavaContext context, @NonNull Node node); 69 70 /** 71 * Dispose any data structures held for the given context. 72 * @param context information about the file previously parsed 73 * @param compilationUnit the compilation unit being disposed 74 */ dispose(@onNull JavaContext context, @NonNull Node compilationUnit)75 void dispose(@NonNull JavaContext context, @NonNull Node compilationUnit); 76 } 77