public IValue visitSourceLocation(ISourceLocation o) throws IOException {
      append('|');
      append(o.getURI().toString());
      append('|');

      if (o.hasOffsetLength()) {
        append('(');
        append(Integer.toString(o.getOffset()));
        append(',');
        append(Integer.toString(o.getLength()));

        if (o.hasLineColumn()) {
          append(',');
          append('<');
          append(Integer.toString(o.getBeginLine()));
          append(',');
          append(Integer.toString(o.getBeginColumn()));
          append('>');
          append(',');
          append('<');
          append(Integer.toString(o.getEndLine()));
          append(',');
          append(Integer.toString(o.getEndColumn()));
          append('>');
        }
        append(')');
      }
      return o;
    }
Esempio n. 2
0
    @Override
    protected void addForLineNumber(int $line, java.util.List<AbstractAST> $result) {
      if (getLocation().getBeginLine() == $line) {
        $result.add(this);
      }
      ISourceLocation $l;

      $l = constant.getLocation();
      if ($l.hasLineColumn() && $l.getBeginLine() <= $line && $l.getEndLine() >= $line) {
        constant.addForLineNumber($line, $result);
      }
      if ($l.getBeginLine() > $line) {
        return;
      }
    }
Esempio n. 3
0
  public HelpManager(PathConfig pcfg, PrintWriter stdout, PrintWriter stderr) {
    this.pcfg = pcfg;
    this.stdout = stdout;
    this.stderr = stderr;

    ISourceLocation binDir = pcfg.getBoot();
    coursesDir =
        URIUtil.correctLocation(
            binDir.getScheme(), binDir.getAuthority(), binDir.getPath() + "/courses");

    try {
      helpServer = new HelpServer(getPort(), this, coursesDir);
      indexSearcher = makeIndexSearcher();
    } catch (IOException e) {
      System.err.println("HelpManager: " + e.getMessage());
    }
  }
Esempio n. 4
0
 Path copyToTmp(ISourceLocation fromDir) throws IOException {
   Path targetDir = Files.createTempDirectory(URIUtil.getLocationName(fromDir));
   targetDir.toFile().deleteOnExit();
   URIResolverRegistry reg = URIResolverRegistry.getInstance();
   for (ISourceLocation file : reg.list(fromDir)) {
     if (!reg.isDirectory(file)) {
       String p = file.getPath();
       int n = p.lastIndexOf("/");
       String fileName = n >= 0 ? p.substring(n + 1) : p;
       // Only copy _* (index files) and segments* (defines number of segments)
       if (fileName.startsWith("_") || fileName.startsWith("segments")) {
         Path targetFile = targetDir.resolve(fileName);
         // System.out.println("copy " + file + " to " + toDir.resolve(fileName));
         Files.copy(reg.getInputStream(file), targetFile);
         targetFile.toFile().deleteOnExit();
       }
     }
   }
   return targetDir;
 }
Esempio n. 5
0
 private CompletionResult completeLocation(String line, int locationStart) {
   int locationEnd = StringUtils.findRascalLocationEnd(line, locationStart);
   try {
     String locCandidate = line.substring(locationStart + 1, locationEnd + 1);
     if (!locCandidate.contains("://")) {
       return null;
     }
     ISourceLocation directory = VF.sourceLocation(new URI(locCandidate));
     String fileName = "";
     URIResolverRegistry reg = URIResolverRegistry.getInstance();
     if (!reg.isDirectory(directory)) {
       // split filename and directory
       String fullPath = directory.getPath();
       int lastSeparator = fullPath.lastIndexOf('/');
       fileName = fullPath.substring(lastSeparator + 1);
       fullPath = fullPath.substring(0, lastSeparator);
       directory = VF.sourceLocation(directory.getScheme(), directory.getAuthority(), fullPath);
       if (!reg.isDirectory(directory)) {
         return null;
       }
     }
     String[] filesInPath = reg.listEntries(directory);
     URI directoryURI = directory.getURI();
     Set<String> result = new TreeSet<>(); // sort it up
     for (String currentFile : filesInPath) {
       if (currentFile.startsWith(fileName)) {
         URI currentDir = URIUtil.getChildURI(directoryURI, currentFile);
         boolean isDirectory = reg.isDirectory(VF.sourceLocation(currentDir));
         result.add(currentDir.toString() + (isDirectory ? "/" : "|"));
       }
     }
     if (result.size() > 0) {
       return new CompletionResult(locationStart + 1, result);
     }
     return null;
   } catch (URISyntaxException | IOException e) {
     return null;
   }
 }
Esempio n. 6
0
  public ISourceLocation resolveSourceLocation(ISourceLocation loc) {
    String scheme = loc.getScheme();
    int pos;

    ICallableValue resolver = sourceResolvers.get(scheme);
    if (resolver == null) {
      for (char sep : new char[] {'+', ':'}) {
        pos = scheme.indexOf(sep);
        if (pos != -1) {
          scheme = scheme.substring(0, pos);
        }
      }

      resolver = sourceResolvers.get(scheme);
      if (resolver == null) {
        return loc;
      }
    }

    Type[] argTypes = new Type[] {TypeFactory.getInstance().sourceLocationType()};
    IValue[] argValues = new IValue[] {loc};

    return (ISourceLocation) resolver.call(argTypes, argValues, null).getValue();
  }
Esempio n. 7
0
 private String extractClassName(ISourceLocation jarLoc) {
   return jarLoc.getPath().substring(jarLoc.getPath().indexOf("!") + 1);
 }
Esempio n. 8
0
 private String extractJarName(ISourceLocation jarLoc) {
   String tmp = jarLoc.getPath().substring(0, jarLoc.getPath().indexOf("!"));
   return tmp.substring(tmp.lastIndexOf("/") + 1);
 }