Coverage Report - org.seasar.eclipse.common.util.AdaptableUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
AdaptableUtil
0%
0/26
0%
0/16
3.667
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 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, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.eclipse.common.util;
 17  
 
 18  
 import org.eclipse.core.resources.IProject;
 19  
 import org.eclipse.core.resources.IResource;
 20  
 import org.eclipse.core.runtime.IAdaptable;
 21  
 import org.eclipse.ui.texteditor.ITextEditor;
 22  
 
 23  
 /**
 24  
  * @author taichi
 25  
  * 
 26  
  */
 27  0
 public class AdaptableUtil {
 28  
 
 29  
     public static ITextEditor toTextEditor(Object adaptable) {
 30  0
         ITextEditor result = null;
 31  0
         if (adaptable instanceof ITextEditor) {
 32  0
             result = (ITextEditor) adaptable;
 33  0
         } else if (adaptable instanceof IAdaptable) {
 34  0
             IAdaptable a = (IAdaptable) adaptable;
 35  0
             result = (ITextEditor) a.getAdapter(ITextEditor.class);
 36  
         }
 37  0
         return result;
 38  
     }
 39  
 
 40  
     public static IResource toResource(Object adaptable) {
 41  0
         IResource result = null;
 42  0
         if (adaptable instanceof IResource) {
 43  0
             result = (IResource) adaptable;
 44  0
         } else if (adaptable instanceof IAdaptable) {
 45  0
             IAdaptable a = (IAdaptable) adaptable;
 46  0
             result = (IResource) a.getAdapter(IResource.class);
 47  
         }
 48  0
         return result;
 49  
     }
 50  
 
 51  
     public static IProject toProject(Object adaptable) {
 52  0
         IProject result = null;
 53  0
         if (adaptable instanceof IProject) {
 54  0
             result = (IProject) adaptable;
 55  0
         } else if (adaptable instanceof IAdaptable) {
 56  0
             IAdaptable a = (IAdaptable) adaptable;
 57  0
             result = (IProject) a.getAdapter(IProject.class);
 58  
         }
 59  0
         if (result == null) {
 60  0
             IResource r = toResource(adaptable);
 61  0
             if (r != null) {
 62  0
                 result = r.getProject();
 63  
             }
 64  
         }
 65  0
         return result;
 66  
     }
 67  
 }