Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.IFile


              this.lookupEnvironment.problemReporter,
              result);
          if (containsLocalType)   parsedUnit.bits |= ASTNode.HasAllMethodBodies;
        } else {
          // create parsed unit from file
          IFile file = (IFile) cu.getResource();
          ICompilationUnit sourceUnit = this.builder.createCompilationUnitFromPath(openable, file);
         
          CompilationResult unitResult = new CompilationResult(sourceUnit, i, openablesLength, this.options.maxProblemsPerUnit);
          parsedUnit = parser.dietParse(sourceUnit, unitResult);
        }
View Full Code Here


      boolean isPrimary = workingCopy.isPrimary();

      JavaElementDeltaBuilder deltaBuilder = null;
      PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
      boolean isIncluded = !Util.isExcluded(workingCopy);
      IFile resource = (IFile)workingCopy.getResource();
      IJavaProject project = root.getJavaProject();
      if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)))) {
       
        // force opening so that the delta builder can get the old info
        if (!isPrimary && !primary.isOpen()) {
          primary.open(null);
        }

        // creates the delta builder (this remembers the content of the cu) if:
        // - it is not excluded
        // - and it is not a primary or it is a non-consistent primary
        if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) {
          deltaBuilder = new JavaElementDeltaBuilder(primary);
        }
     
        // save the cu
        IBuffer primaryBuffer = primary.getBuffer();
        if (!isPrimary) {
          if (primaryBuffer == null) return;
          char[] primaryContents = primaryBuffer.getCharacters();
          boolean hasSaved = false;
          try {
            IBuffer workingCopyBuffer = workingCopy.getBuffer();
            if (workingCopyBuffer == null) return;
            primaryBuffer.setContents(workingCopyBuffer.getCharacters());
            primaryBuffer.save(this.progressMonitor, this.force);
            primary.makeConsistent(this);
            hasSaved = true;
          } finally {
            if (!hasSaved){
              // restore original buffer contents since something went wrong
              primaryBuffer.setContents(primaryContents);
            }
          }
        } else {
          // for a primary working copy no need to set the content of the buffer again
          primaryBuffer.save(this.progressMonitor, this.force);
          primary.makeConsistent(this);
        }
      } else {
        // working copy on cu outside classpath OR resource doesn't exist yet
        String encoding = null;
        try {
          encoding = resource.getCharset();
        }
        catch (CoreException ce) {
          // use no encoding
        }
        String contents = workingCopy.getSource();
        if (contents == null) return;
        try {
          byte[] bytes = encoding == null
            ? contents.getBytes()
            : contents.getBytes(encoding);
          ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
          if (resource.exists()) {
            resource.setContents(
              stream,
              this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
              null);
          } else {
            resource.create(
              stream,
              this.force,
              this.progressMonitor);
          }
        } catch (CoreException e) {
View Full Code Here

                public boolean visit(IResourceProxy proxy) {
                  if (isCancelled) return false;
                  switch(proxy.getType()) {
                    case IResource.FILE :
                      if (org.aspectj.org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
                        IFile file = (IFile) proxy.requestResource();
                        if (exclusionPatterns != null || inclusionPatterns != null)
                          if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
                            return false;
                        indexedFileNames.put(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file);
                      }
                      return false;
                    case IResource.FOLDER :
                      if (exclusionPatterns != null && inclusionPatterns == null) {
                        // if there are inclusion patterns then we must walk the children
                        if (Util.isExcluded(proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true))
                            return false;
                      }
                      if (hasOutputs && outputs.contains(proxy.requestFullPath()))
                        return false;
                  }
                  return true;
                }
              },
              IResource.NONE
            );
          } else {
            sourceFolder.accept(
              new IResourceProxyVisitor() {
                public boolean visit(IResourceProxy proxy) throws CoreException {
                  if (isCancelled) return false;
                  switch(proxy.getType()) {
                    case IResource.FILE :
                      if (org.aspectj.org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
                        IFile file = (IFile) proxy.requestResource();
                        URI location = file.getLocationURI();
                        if (location == null) return false;
                        if (exclusionPatterns != null || inclusionPatterns != null)
                          if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
                            return false;
                        String relativePathString = Util.relativePath(file.getFullPath(), 1/*remove project segment*/);
                        indexedFileNames.put(relativePathString,
                          indexedFileNames.get(relativePathString) == null
                              || indexLastModified < EFS.getStore(location).fetchInfo().getLastModified()
                            ? (Object) file
                            : (Object) OK);
View Full Code Here

        this.folder.accept(new IResourceProxyVisitor() {
          public boolean visit(IResourceProxy proxy) {
            if (isCancelled) return false;
            if (proxy.getType() == IResource.FILE) {
              if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) {
                IFile file = (IFile) proxy.requestResource();
                String containerRelativePath = Util.relativePath(file.getFullPath(), containerPath.segmentCount());
                indexedFileNames.put(containerRelativePath, file);
              }
              return false;
            }
            return true;
          }
        }, IResource.NONE);
      } else {
        for (int i = 0; i < max; i++) {
          indexedFileNames.put(paths[i], DELETED);
        }
        final long indexLastModified = index.getIndexFile().lastModified();
        this.folder.accept(
          new IResourceProxyVisitor() {
            public boolean visit(IResourceProxy proxy) throws CoreException {
              if (isCancelled) return false;
              if (proxy.getType() == IResource.FILE) {
                if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) {
                  IFile file = (IFile) proxy.requestResource();
                  URI location = file.getLocationURI();
                  if (location != null) {
                    String containerRelativePath = Util.relativePath(file.getFullPath(), containerPath.segmentCount());
                    indexedFileNames.put(containerRelativePath,
                      indexedFileNames.get(containerRelativePath) == null
                          || indexLastModified <
                          EFS.getStore(location).fetchInfo().getLastModified()
                        ? (Object) file
View Full Code Here

    Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), jarPath, false);
    if (target instanceof IFile) {
      // internal jar: is it on the classpath of its project?
      //  e.g. org.eclipse.swt.win32/ws/win32/swt.jar
      //        is NOT on the classpath of org.eclipse.swt.win32
      IFile jarFile = (IFile)target;
      JavaProject javaProject = (JavaProject) this.javaModel.getJavaProject(jarFile);
      try {
        IClasspathEntry entry = javaProject.getClasspathEntryFor(jarPath);
        if (entry != null) {
          return javaProject.getPackageFragmentRoot(jarFile);
View Full Code Here

      }
    } finally {
      JavaModelManager.getJavaModelManager().closeZipFile(zip);
    }
  } else {
    IFile file = (IFile) getResource();
    return Util.getResourceContentsAsByteArray(file);
  }
}
View Full Code Here

      return null;
    }
  }
  public String getEncoding() {
    // Return the encoding of the associated file
    IFile resource = getFile();
    if (resource != null) {
      try {
        return resource.getCharset();
      }
      catch(CoreException ce) {
        try {
          return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
        } catch (CoreException e) {
View Full Code Here

}

public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String qualifiedPackageName, String qualifiedSourceFileWithoutExtension) {
  SimpleLookupTable dirTable = directoryTable(qualifiedPackageName);
  if (dirTable != null && dirTable.elementSize > 0) {
    IFile file = (IFile) dirTable.get(sourceFileWithoutExtension);
    if (file != null) {
      return new NameEnvironmentAnswer(new ResourceCompilationUnit(file, file.getLocationURI()), null /* no access restriction */);
    }
  }
  return null;
}
View Full Code Here

        // in all cases, refresh the external jars for this project
        addForRefresh(javaProject);
       
        break;
      case IResource.FILE :
        IFile file = (IFile) resource;
        /* classpath file change */
        if (file.getName().equals(JavaProject.CLASSPATH_FILENAME)) {
          this.manager.batchContainerInitializations = true;
          switch (delta.getKind()) {
            case IResourceDelta.CHANGED :
              int flags = delta.getFlags();
              if ((flags & IResourceDelta.CONTENT) == // only consider content change
                && (flags & IResourceDelta.ENCODING) == 0 // and encoding change
                && (flags & IResourceDelta.MOVED_FROM) == 0) {// and also move and overide scenario (see http://dev.eclipse.org/bugs/show_bug.cgi?id=21420)
                break;
              }
            // fall through
            case IResourceDelta.ADDED :
              javaProject = (JavaProject)JavaCore.create(file.getProject());
             
              // force to (re)read the .classpath file
              try {
                javaProject.getPerProjectInfo().readAndCacheClasspath(javaProject);
              } catch (JavaModelException e) {
View Full Code Here

            break;
        }
        break;
      case IResource.FILE :
        /* check classpath or prefs files change */
        IFile file = (IFile) resource;
        String fileName = file.getName();
        if (fileName.equals(JavaProject.CLASSPATH_FILENAME)) {
          JavaProject javaProject = (JavaProject)JavaCore.create(file.getProject());
          this.state.addClasspathValidation(javaProject);
          affectedProjects.add(file.getProject().getFullPath());
        }
        break;
    }
    if (processChildren) {
      IResourceDelta[] children = delta.getAffectedChildren();
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.IFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.