/*
 * Copyright 2011 Jon S Akhtar (Sylvanaar)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sylvanaar.idea.Lua.sdk;

import com.intellij.openapi.vfs.*;
import com.sylvanaar.idea.Lua.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: Jon S Akhtar
 * Date: 2/9/11
 * Time: 3:07 AM
 */
public class StdLibrary {
    public static final String STDLIBRARY    = "stdlibrary";
    public static final String DEBUG_LIBRARY = "remdebug";
    public static final String LISTING_GENERATOR = "listing";
    
    public static VirtualFile getStdFileLocation() {
        VirtualFile dir = LuaFileUtil.getPluginVirtualDirectory();

        if (dir != null) dir = dir.findChild(STDLIBRARY);

        if (dir != null) return dir;

        dir = LuaFileUtil.getPluginVirtualDirectory();

        if (dir != null)
            dir = dir.findChild("classes");
        if (dir != null)
            dir = dir.findChild(STDLIBRARY);

        return dir;
    }

    public static VirtualFile getDebugModuleLocation() {
        VirtualFile dir = LuaFileUtil.getPluginVirtualDirectory();

        if (dir != null) dir = dir.findChild(DEBUG_LIBRARY);

        if (dir != null) return dir;

        return null;
    }

    public static VirtualFile getListingModuleLocation() {
        VirtualFile dir = LuaFileUtil.getPluginVirtualDirectory();

        if (dir != null) dir = dir.findChild(LISTING_GENERATOR);

        if (dir != null) return dir;

        return null;
    }
}

@@ -969,11 +969,11 @@
  = %22
-rem
+mob
 debu
@@ -1044,24 +1044,21 @@
 %22;%0D%0A
-    
 %0D%0A    p
-ublic
+rivate
  sta
@@ -1080,24 +1080,34 @@
  get
-StdFileLocation(
+PluginChild(String ...args
 ) %7B%0D
@@ -1167,32 +1167,65 @@
 alDirectory();%0D%0A
+        for (String arg : args) %7B
 %0D%0A        if (di
@@ -1214,32 +1214,36 @@
  %7B%0D%0A        
+    
 if (dir 
 != null) dir
@@ -1226,33 +1226,33 @@
     if (dir 
-!
+=
 = null) 
 dir = dir.fi
@@ -1243,68 +1243,73 @@
 ll) 
-dir = dir.findChild(STDLIBRARY);%0D%0A%0D%0A        if (dir != null)
+break;%0D%0A            dir = dir.findChild(arg);%0D%0A        %7D%0D%0A       
  ret
@@ -1322,135 +1322,122 @@
 r;%0D%0A
-%0D%0A
     
-    dir = L
+%7D%0D%0A%0D%0A    public static Virt
 ua
+l
 File
-Util.getPluginVirtualDirectory();%0D%0A%0D%0A        if (dir != null)%0D%0A            dir = dir.f
+ getStdFileLocation() %7B%0D%0A        VirtualFile dir = getPlug
 in
-d
 Child(
-%22classes%22
+STDLIBRARY
 );%0D%0A
@@ -1448,25 +1448,25 @@
     if (dir 
-!
+=
 = null)%0D%0A   
@@ -1480,30 +1480,42 @@
   dir = 
-dir.f
+getPlug
 in
-d
 Child(
+%22classes%22, 
 STDLIBRA
@@ -1640,50 +1640,38 @@
 r = 
-LuaFileUtil.getPluginVirtualDirectory();%0D%0A
+getPluginChild(DEBUG_LIBRARY);
 %0D%0A  
@@ -1688,37 +1688,62 @@
 dir 
-!
+=
 = null)
- dir = dir.f
+%0D%0A            dir = getPlug
 in
-d
 Child(
+%22classes%22, 
 DEBU
@@ -1751,34 +1751,32 @@
 _LIBRARY);%0D%0A
-%0D%0A
         
 if (dir != n
@@ -1767,59 +1767,18 @@
     
-if (dir != null) return dir;%0D%0A%0D%0A        return null
+return dir
 ;%0D%0A 
@@ -1875,52 +1875,44 @@
 r = 
-LuaFileUtil.getPluginVirtualDirectory(
+getPluginChild(LISTING_GENERATOR
 );%0D%0A
-%0D%0A
     
@@ -1927,37 +1927,62 @@
 dir 
-!
+=
 = null)
- dir = dir.f
+%0D%0A            dir = getPlug
 in
-d
 Child(
+%22classes%22, 
 LIST
@@ -1998,26 +1998,24 @@
 ATOR);%0D%0A
-%0D%0A
         
 if (dir 
@@ -2010,59 +2010,18 @@
     
-if (dir != null) return dir;%0D%0A%0D%0A        return null
+return dir
 ;%0D%0A 

Simplify library lookup in StdLibrary