Fixed: could not access linked resources
authortoshihiro <toshihiro>
Mon, 11 Jun 2007 08:06:04 +0000 (08:06 +0000)
committertoshihiro <toshihiro>
Mon, 11 Jun 2007 08:06:04 +0000 (08:06 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/phpdoc/PHPDocUtil.java

index 9b30f8b..5bf73a7 100644 (file)
@@ -1,8 +1,10 @@
 package net.sourceforge.phpdt.internal.corext.phpdoc;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
@@ -33,9 +35,9 @@ public class PHPDocUtil {
 
                        // read the phpdoc for the function
                        if (location.getPHPDocOffset() >= 0) {
-                               String encoding = getEncoding(filename);
-                               InputStreamReader phpFileReader = new InputStreamReader(
-                                               new FileInputStream(filename), encoding);
+                               InputStreamReader phpFileReader = createReader(filename);
+                               if (phpFileReader == null)
+                                       return;
                                char[] phpDocDeclarationCharArray = new char[location
                                                .getPHPDocLength()];
                                phpFileReader.skip(location.getPHPDocOffset());
@@ -76,9 +78,9 @@ public class PHPDocUtil {
                usage = "";
                try {
 
-                       String encoding = getEncoding(filename);
-                       InputStreamReader phpFileReader = new InputStreamReader(
-                                       new FileInputStream(filename), encoding);
+                       InputStreamReader phpFileReader = createReader(filename);
+                       if (phpFileReader == null)
+                               return "";
                        // read the function declaration
                        if (location.getOffset() >= 0
                                        && (location.isMethod() || location.isConstructor()
@@ -103,13 +105,33 @@ public class PHPDocUtil {
                                        }
                                }
                                usage = new String(functionDeclarationCharArray, 0, length);
+                               // cache the usage string:
+                               location.setUsage(usage);
                        }
                        phpFileReader.close();
+
                } catch (IOException e) {
                        // do nothing
                }
-               // cache the usage string:
-               location.setUsage(usage);
                return usage;
        }
+
+       private static InputStreamReader createReader(String filename) {
+               IFile file = PHPeclipsePlugin.getWorkspace().getRoot()
+                               .getFileForLocation(new Path(filename));
+               if (file != null) {
+                       try {
+                               return new InputStreamReader(new FileInputStream(file
+                                               .getLocation().toString()), file.getCharset());
+                       } catch (UnsupportedEncodingException e) {
+                               // do nothing
+                       } catch (FileNotFoundException e) {
+                               // do nothing
+                       } catch (CoreException e) {
+                               // do nothing
+                       }
+               }
+               return null;
+       }
+
 }