Home | History | Annotate | Download | only in ddms
      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.ide.eclipse.ddms;
     18 
     19 import org.eclipse.core.runtime.CoreException;
     20 import org.eclipse.core.runtime.IConfigurationElement;
     21 
     22 import java.util.ArrayList;
     23 import java.util.List;
     24 
     25 public class JavaSourceRevealer {
     26     private static final String SOURCE_REVEALER_EXTENSION_ID =
     27             "com.android.ide.eclipse.ddms.sourceRevealer"; //$NON-NLS-1$
     28 
     29     private static List<ISourceRevealer> sSourceRevealers = instantiateSourceRevealers();
     30 
     31     /** Instantiate all providers of the {@link #SOURCE_REVEALER_EXTENSION_ID} extension. */
     32     private static List<ISourceRevealer> instantiateSourceRevealers() {
     33         IConfigurationElement[] configElements =
     34                 DdmsPlugin.getDefault().findConfigElements(SOURCE_REVEALER_EXTENSION_ID);
     35 
     36         List<ISourceRevealer> providers = new ArrayList<ISourceRevealer>();
     37 
     38         for (IConfigurationElement configElement : configElements) {
     39             // instantiate the class
     40             Object obj = null;
     41             try {
     42                 obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$
     43             } catch (CoreException e) {
     44                 // ignore exception while instantiating this class.
     45             }
     46 
     47             if (obj instanceof ISourceRevealer) {
     48                 providers.add((ISourceRevealer) obj);
     49             }
     50         }
     51 
     52         return providers;
     53     }
     54 
     55     public static boolean reveal(String applicationName, String className, int line) {
     56         for (ISourceRevealer revealer : sSourceRevealers) {
     57             try {
     58                 if (revealer.reveal(applicationName, className, line)) {
     59                     return true;
     60                 }
     61             } catch (Throwable t) {
     62                 // ignore, we'll just not use this implementation.
     63             }
     64         }
     65 
     66         return false;
     67     }
     68 
     69     public static boolean revealMethod(String fqmn, String fileName, int linenumber,
     70             String perspective) {
     71         for (ISourceRevealer revealer : sSourceRevealers) {
     72             try {
     73                 if (revealer.revealMethod(fqmn, fileName, linenumber, perspective)) {
     74                     return true;
     75                 }
     76             } catch (Throwable t) {
     77                 // ignore, we'll just not use this implementation.
     78             }
     79         }
     80 
     81         return false;
     82     }
     83 }
     84