Exemplo n.º 1
0
  /**
   * Deletes this file from PDOM. Only uncommitted files can be safely deleted.
   *
   * @throws CoreException
   */
  public void delete() throws CoreException {
    Database db = fLinkage.getDB();
    long locRecord = db.getRecPtr(record + LOCATION_REPRESENTATION);
    if (locRecord != 0) db.getString(locRecord).delete();
    locRecord = db.getRecPtr(record + SIGNIFICANT_MACROS);
    if (locRecord != 0) db.getString(locRecord).delete();
    locRecord = db.getRecPtr(record + REPLACEMENT_HEADER);
    if (locRecord != 0) db.getString(locRecord).delete();

    db.free(record);
  }
Exemplo n.º 2
0
 /**
  * Directly changes this record's internal location string. The format of this string is
  * unspecified in general and is determined by the associated IIndexLocationConverter. This method
  * should not be called on PDOMFile objects that are referenced by the file index.
  *
  * @param internalLocation
  * @throws CoreException
  */
 public void setInternalLocation(String internalLocation) throws CoreException {
   Database db = fLinkage.getDB();
   long oldRecord = db.getRecPtr(record + LOCATION_REPRESENTATION);
   if (oldRecord != 0) db.getString(oldRecord).delete();
   db.putRecPtr(record + LOCATION_REPRESENTATION, db.newString(internalLocation).getRecord());
   location = null;
 }
 @Override
 public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
   if (newBinding instanceof ICPPTemplateTemplateParameter) {
     final Database db = getDB();
     ICPPTemplateTemplateParameter ttp = (ICPPTemplateTemplateParameter) newBinding;
     updateName(newBinding.getNameCharArray());
     IType newDefault = null;
     try {
       newDefault = ttp.getDefault();
     } catch (DOMException e) {
       // ignore
     }
     if (newDefault != null) {
       linkage.storeType(record + DEFAULT_TYPE, newDefault);
     }
     long oldRec = db.getRecPtr(record + PARAMETERS);
     IPDOMCPPTemplateParameter[] oldParams = getTemplateParameters();
     try {
       params =
           PDOMTemplateParameterArray.createPDOMTemplateParameters(
               getLinkage(), this, ttp.getTemplateParameters());
       long newRec = PDOMTemplateParameterArray.putArray(db, params);
       db.putRecPtr(record + PARAMETERS, newRec);
       if (oldRec != 0) db.free(oldRec);
       for (IPDOMCPPTemplateParameter opar : oldParams) {
         opar.forceDelete(linkage);
       }
     } catch (DOMException e) {
     }
   }
 }
Exemplo n.º 4
0
 @Override
 public void setReplacementHeader(String replacementHeader) throws CoreException {
   Database db = fLinkage.getDB();
   long oldRecord = db.getRecPtr(record + REPLACEMENT_HEADER);
   if (oldRecord != 0) db.getString(oldRecord).delete();
   long newRecord = replacementHeader == null ? 0 : db.newString(replacementHeader).getRecord();
   db.putRecPtr(record + REPLACEMENT_HEADER, newRecord);
 }
Exemplo n.º 5
0
 @Override
 public ISignificantMacros getSignificantMacros() throws CoreException {
   if (sigMacros == null) {
     Database db = fLinkage.getDB();
     final IString encoded = db.getString(db.getRecPtr(record + SIGNIFICANT_MACROS));
     sigMacros =
         encoded == null ? ISignificantMacros.NONE : new SignificantMacros(encoded.getChars());
   }
   return sigMacros;
 }
Exemplo n.º 6
0
  /**
   * Transfers names, macros and includes from another file to this one and deletes the other file.
   *
   * @param sourceFile the file to transfer the local bindings from.
   * @throws CoreException
   */
  public void replaceContentsFrom(PDOMFile sourceFile) throws CoreException {
    // Delete current content
    clear();

    // Link in the using directives
    setLastUsingDirective(sourceFile.getLastUsingDirectiveRec());

    // Link in the includes, replace the owner.
    PDOMInclude include = sourceFile.getFirstInclude();
    setFirstInclude(include);
    for (; include != null; include = include.getNextInIncludes()) {
      include.setIncludedBy(this);
    }

    // In the unexpected case that there is an included by relation, append it.
    transferIncluders(sourceFile);

    // Link in the macros.
    PDOMMacro macro = sourceFile.getFirstMacro();
    setFirstMacro(macro);
    for (; macro != null; macro = macro.getNextMacro()) {
      macro.setFile(this);
    }

    // Link in macro references
    PDOMMacroReferenceName mref = sourceFile.getFirstMacroReference();
    setFirstMacroReference(mref);
    for (; mref != null; mref = mref.getNextInFile()) {
      mref.setFile(this);
    }

    // Replace all the names in this file
    PDOMName name = sourceFile.getFirstName();
    setFirstName(name);
    for (; name != null; name = name.getNextInFile()) {
      name.setFile(this);
    }

    setTimestamp(sourceFile.getTimestamp());
    setSourceReadTime(sourceFile.getSourceReadTime());
    setSizeAndEncodingHashcode(sourceFile.getSizeAndEncodingHashcode());
    setContentsHash(sourceFile.getContentsHash());

    // Transfer the flags.
    Database db = fLinkage.getDB();
    db.putByte(record + FLAGS, db.getByte(sourceFile.record + FLAGS));

    // Transfer the replacement header.
    db.putRecPtr(record + REPLACEMENT_HEADER, db.getRecPtr(sourceFile.record + REPLACEMENT_HEADER));
    db.putRecPtr(sourceFile.record + REPLACEMENT_HEADER, 0);

    // Delete the source file
    sourceFile.delete();
  }
  @Override
  public void forceDelete(PDOMLinkage linkage) throws CoreException {
    getDBName().delete();
    linkage.storeType(record + DEFAULT_TYPE, null);

    final Database db = getDB();
    long oldRec = db.getRecPtr(record + PARAMETERS);
    IPDOMCPPTemplateParameter[] oldParams = getTemplateParameters();
    if (oldRec != 0) db.free(oldRec);
    for (IPDOMCPPTemplateParameter opar : oldParams) {
      opar.forceDelete(linkage);
    }
  }
Exemplo n.º 8
0
 @Override
 public int compare(long record) throws CoreException {
   IString name = db.getString(db.getRecPtr(record + PDOMFile.LOCATION_REPRESENTATION));
   int cmp = name.compare(rawKey, true);
   if (cmp == 0 && linkageID >= 0) {
     cmp = db.get3ByteUnsignedInt(record + PDOMFile.LINKAGE_ID) - linkageID;
     if (cmp == 0 && rawSignificantMacros != null) {
       IString significantMacrosStr = getString(record + SIGNIFICANT_MACROS);
       if (significantMacrosStr != null) {
         cmp = significantMacrosStr.compare(rawSignificantMacros, true);
       } else {
         cmp = rawSignificantMacros.length > 0 ? -1 : 0;
       }
     }
   }
   return cmp;
 }
Exemplo n.º 9
0
 @Override
 public IIndexFileLocation getLocation() throws CoreException {
   if (location == null) {
     Database db = fLinkage.getDB();
     String raw = db.getString(db.getRecPtr(record + LOCATION_REPRESENTATION)).getString();
     location = fLinkage.getPDOM().getLocationConverter().fromInternalFormat(raw);
     if (location == null) {
       URI uri;
       try {
         int idx = raw.lastIndexOf('>');
         uri = new URI("file", null, raw.substring(idx + 1), null); // $NON-NLS-1$
       } catch (URISyntaxException e) {
         uri = URI.create("file:/unknown-location"); // $NON-NLS-1$
       }
       location = new IndexFileLocation(uri, null);
     }
   }
   return location;
 }
Exemplo n.º 10
0
 @Override
 public int compare(long record1, long record2) throws CoreException {
   IString name1 = db.getString(db.getRecPtr(record1 + LOCATION_REPRESENTATION));
   IString name2 = db.getString(db.getRecPtr(record2 + LOCATION_REPRESENTATION));
   int cmp = name1.compare(name2, true);
   if (cmp == 0) {
     cmp =
         db.get3ByteUnsignedInt(record1 + LINKAGE_ID)
             - db.get3ByteUnsignedInt(record2 + LINKAGE_ID);
     if (cmp == 0) {
       IString sm1 = getString(record1 + SIGNIFICANT_MACROS);
       IString sm2 = getString(record2 + SIGNIFICANT_MACROS);
       if (sm1 == null) {
         cmp = sm2 == null ? 0 : -1;
       } else if (sm2 == null) {
         cmp = 1;
       } else {
         cmp = sm1.compare(sm2, true);
       }
     }
   }
   return cmp;
 }
Exemplo n.º 11
0
 @Override
 public String getReplacementHeader() throws CoreException {
   Database db = fLinkage.getDB();
   long rec = db.getRecPtr(record + REPLACEMENT_HEADER);
   return rec == 0 ? null : db.getString(rec).getString();
 }
Exemplo n.º 12
0
 private IString getString(long offset) throws CoreException {
   long rec = db.getRecPtr(offset);
   return rec != 0 ? db.getString(rec) : null;
 }