private static void parseMetadata(InputSource inputSource, MetadataReader handler) {
   try {
     final SAXParserFactory factory = SAXParserFactory.newInstance();
     final SAXParser parser = factory.newSAXParser();
     //			parser.setProperty("http://xml.org/sax/features/namespaces", new Boolean(true));
     XMLReader reader = parser.getXMLReader();
     reader.setFeature("http://xml.org/sax/features/namespaces", true);
     parser.parse(inputSource, handler);
   } catch (SAXException e) {
     Util.log(e, "error reading oaametadata");
   } catch (IOException e) {
     Util.log(e, "error reading oaametadata");
   } catch (ParserConfigurationException e) {
     Util.log(e, "error reading oaametadata");
   }
 }
 /**
  * Validate the given javaScript unit name for the given source and compliance levels.
  *
  * <p>A javaScript unit name must obey the following rules:
  *
  * <ul>
  *   <li>it must not be null
  *   <li>it must be suffixed by a dot ('.') followed by one of the {@link
  *       JavaScriptCore#getJavaScriptLikeExtensions() JavaScript-like extensions}
  *   <li>its prefix must be a valid identifier
  *   <li>it must not contain any characters or substrings that are not valid on the file system on
  *       which workspace root is located.
  * </ul>
  *
  * @param name the name of a javaScript unit
  * @param sourceLevel the source level
  * @param complianceLevel the compliance level
  * @return a status object with code <code>IStatus.OK</code> if the given name is valid as a
  *     javaScript unit name, otherwise a status object indicating what is wrong with the name
  */
 public static IStatus validateCompilationUnitName(
     String name, String sourceLevel, String complianceLevel) {
   if (name == null) {
     return new Status(
         IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null);
   }
   if (!org.eclipse.wst.jsdt.internal.core.util.Util.isJavaLikeFileName(name)) {
     return new Status(
         IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
   }
   //		String identifier;
   int index;
   index = name.lastIndexOf('.');
   if (index == -1) {
     return new Status(
         IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
   }
   //		identifier = name.substring(0, index);
   // JSR-175 metadata strongly recommends "package-info.js" as the
   // file in which to store package annotations and
   // the package-level spec (replaces package.html)
   //		if (!identifier.equals(PACKAGE_INFO)) {
   //			IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel);
   //			if (!status.isOK()) {
   //				return status;
   //			}
   //		}
   //		IStatus status = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
   //		if (!status.isOK()) {
   //			return status;
   //		}
   return JavaModelStatus.VERIFIED_OK;
 }
 public static LibraryAPIs readAPIsFromFile(String fileName) {
   try {
     FileInputStream file = new FileInputStream(fileName);
     LibraryAPIs apis = readAPIsFromStream(new InputSource(file), fileName);
     apis.fileName = fileName.toCharArray();
     return apis;
   } catch (FileNotFoundException e) {
     Util.log(e, "error reading oaametadata");
   }
   return null;
 }
Example #4
0
  /*
   * Instanciate a method pattern with signatures for generics search
   */
  public MethodPattern(
      boolean findDeclarations,
      boolean findReferences,
      boolean isFunction,
      char[] selector,
      char[] declaringQualification,
      char[] declaringSimpleName,
      String declaringSignature,
      char[] returnQualification,
      char[] returnSimpleName,
      String returnSignature,
      char[][] parameterQualifications,
      char[][] parameterSimpleNames,
      String[] parameterSignatures,
      char[][] arguments,
      int matchRule) {

    this(
        findDeclarations,
        findReferences,
        isFunction,
        selector,
        declaringQualification,
        declaringSimpleName,
        returnQualification,
        returnSimpleName,
        parameterQualifications,
        parameterSimpleNames,
        null,
        matchRule);

    // Store type signature and arguments for declaring type
    if (declaringSignature != null) {
      typeSignatures = Util.splitTypeLevelsSignature(declaringSignature);
      setTypeArguments(Util.getAllTypeArguments(typeSignatures));
    }

    // Store type signatures and arguments for return type
    if (returnSignature != null) {
      returnTypeSignatures = Util.splitTypeLevelsSignature(returnSignature);
      returnTypeArguments = Util.getAllTypeArguments(returnTypeSignatures);
    }

    // Store type signatures and arguments for method parameters type
    if (parameterSignatures != null) {
      int length = parameterSignatures.length;
      if (length > 0) {
        parametersTypeSignatures = new char[length][][];
        parametersTypeArguments = new char[length][][][];
        for (int i = 0; i < length; i++) {
          parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]);
          parametersTypeArguments[i] = Util.getAllTypeArguments(parametersTypeSignatures[i]);
        }
      }
    }

    // Store type signatures and arguments for method
    methodArguments = arguments;
    if (hasMethodArguments()) ((InternalSearchPattern) this).mustResolve = true;
  }
  private void handleInclude(String src) {
    IPath basePath = new Path(this.filePath);
    Path srcPath = new Path(src);
    basePath = basePath.removeLastSegments(1);
    basePath = basePath.append(srcPath);

    String fileName = basePath.toOSString();
    String savePath = this.filePath;
    try {
      FileInputStream file = new FileInputStream(fileName);
      this.filePath = fileName;
      parseMetadata(new InputSource(file), this);
    } catch (FileNotFoundException e) {
      Util.log(e, "error reading oaametadata");
    }
    this.filePath = savePath;
  }
  public void findIndexMatches(
      Index index,
      IndexQueryRequestor requestor,
      SearchParticipant participant,
      IJavaScriptSearchScope scope,
      IProgressMonitor progressMonitor)
      throws IOException {
    if (this.localVariable != null) {

      //    IPackageFragmentRoot root =
      // (IPackageFragmentRoot)this.localVariable.getAncestor(IJavaScriptElement.PACKAGE_FRAGMENT_ROOT);
      String documentPath;
      String relativePath;
      //    if (root.isArchive()) {
      //        IType type = (IType)this.localVariable.getAncestor(IJavaScriptElement.TYPE);
      //        relativePath = (type.getFullyQualifiedName('/')).replace('.', '/') +
      // SuffixConstants.SUFFIX_STRING_java;
      //        documentPath = root.getPath() + IJavaScriptSearchScope.JAR_FILE_ENTRY_SEPARATOR +
      // relativePath;
      //    } else
      {
        IPath path = this.localVariable.getPath();
        documentPath = path.toString();
        relativePath = Util.relativePath(path, 1 /*remove project segment*/);
      }

      if (scope instanceof JavaSearchScope) {
        JavaSearchScope javaSearchScope = (JavaSearchScope) scope;
        // Get document path access restriction from java search scope
        // Note that requestor has to verify if needed whether the document violates the access
        // restriction or not
        AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, index.containerPath);
        if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the path
          if (!requestor.acceptIndexMatch(documentPath, this, participant, access))
            throw new OperationCanceledException();
        }
      } else if (scope.encloses(documentPath)) {
        if (!requestor.acceptIndexMatch(documentPath, this, participant, null))
          throw new OperationCanceledException();
      }
    } else {
      super.findIndexMatches(index, requestor, participant, scope, progressMonitor);
    }
  }
  private void loadMessageBundle() {

    class MessageBundleHandler extends DefaultHandler {
      String currentID;
      StringBuffer text;

      public void startElement(String uri, String localName, String name, Attributes attributes)
          throws SAXException {
        if (TAG_MSG.equals(localName)) {
          currentID = attributes.getValue(ATTRIBUTE_MSG_NAME);
          if (currentID != null && currentID.length() > 0) text = new StringBuffer();
          else currentID = null;
        }
      }

      public void endElement(String uri, String localName, String name) throws SAXException {
        if (currentID != null) {
          messages.put(currentID, text.toString());
        }
        currentID = null;
        text = null;
      }

      public void characters(char[] ch, int start, int length) throws SAXException {
        if (currentID != null && text != null) {
          text.append(ch, start, length);
        }
      }
    }

    final String[] variants = buildVariants();
    for (int i = 0; i < variants.length; i++) {
      // loader==null if we're launched off the Java boot classpath
      File file = new File(variants[i]);
      if (!file.exists()) continue;

      try {
        InputSource inputSource = new InputSource(new FileReader(file));
      } catch (FileNotFoundException e) {
        Util.log(e, "error reading oaametadata");
      }
    }
  }
Example #8
0
  /*
   * Instanciate a method pattern with signatures for generics search
   */
  public MethodPattern(
      boolean findDeclarations,
      boolean findReferences,
      boolean isFunction,
      char[] selector,
      char[] declaringQualification,
      char[] declaringSimpleName,
      char[] returnQualification,
      char[] returnSimpleName,
      String returnSignature,
      char[][] parameterQualifications,
      char[][] parameterSimpleNames,
      String[] parameterSignatures,
      IFunction method,
      int matchRule) {

    this(
        findDeclarations,
        findReferences,
        isFunction,
        selector,
        declaringQualification,
        declaringSimpleName,
        returnQualification,
        returnSimpleName,
        parameterQualifications,
        parameterSimpleNames,
        method.getDeclaringType(),
        matchRule);

    // Set flags
    try {
      this.varargs = (method.getFlags() & Flags.AccVarargs) != 0;
    } catch (JavaScriptModelException e) {
      // do nothing
    }

    methodParameters = true;

    if (declaringType != null) {
      // Store type signature and arguments for declaring type
      storeTypeSignaturesAndArguments(declaringType);
    }
    // Store type signatures and arguments for return type
    if (returnSignature != null) {
      returnTypeSignatures = Util.splitTypeLevelsSignature(returnSignature);
      returnTypeArguments = Util.getAllTypeArguments(returnTypeSignatures);
    }

    // Store type signatures and arguments for method parameters type
    if (parameterSignatures != null) {
      int length = parameterSignatures.length;
      if (length > 0) {
        parametersTypeSignatures = new char[length][][];
        parametersTypeArguments = new char[length][][][];
        for (int i = 0; i < length; i++) {
          parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]);
          parametersTypeArguments[i] = Util.getAllTypeArguments(parametersTypeSignatures[i]);
        }
      }
    }

    // Store type signatures and arguments for method
    methodArguments = extractMethodArguments(method);
    if (hasMethodArguments()) ((InternalSearchPattern) this).mustResolve = true;
  }