Home | History | Annotate | Download | only in lint
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
      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 package com.android.ide.eclipse.adt.internal.lint;
     17 
     18 import static com.android.SdkConstants.ANDROID_URI;
     19 
     20 import com.android.ide.eclipse.adt.AdtPlugin;
     21 import com.android.utils.XmlUtils;
     22 
     23 import org.eclipse.core.resources.IMarker;
     24 import org.eclipse.jface.text.BadLocationException;
     25 import org.eclipse.jface.text.IDocument;
     26 import org.eclipse.swt.graphics.Image;
     27 import org.eclipse.ui.ISharedImages;
     28 import org.eclipse.ui.PlatformUI;
     29 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
     30 import org.w3c.dom.Node;
     31 
     32 @SuppressWarnings("restriction") // DOM model
     33 final class AddPrefixFix extends DocumentFix {
     34     private AddPrefixFix(String id, IMarker marker) {
     35         super(id, marker);
     36     }
     37 
     38     @Override
     39     public boolean needsFocus() {
     40         return false;
     41     }
     42 
     43     @Override
     44     public boolean isCancelable() {
     45         return false;
     46     }
     47 
     48     @Override
     49     protected void apply(IDocument document, IStructuredModel model, Node node, int start,
     50             int end) {
     51         String prefix = XmlUtils.lookupNamespacePrefix(node, ANDROID_URI);
     52         try {
     53             document.replace(start, 0, prefix + ':');
     54         } catch (BadLocationException e) {
     55             AdtPlugin.log(e, null);
     56         }
     57     }
     58 
     59     @Override
     60     public String getDisplayString() {
     61         return "Add in an Android namespace prefix";
     62     }
     63 
     64     @Override
     65     public Image getImage() {
     66         ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
     67         return sharedImages.getImage(ISharedImages.IMG_OBJ_ADD);
     68     }
     69 }
     70