Example usage for org.eclipse.jdt.internal.core.util Util isExcluded

List of usage examples for org.eclipse.jdt.internal.core.util Util isExcluded

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Util isExcluded.

Prototype

public final static boolean isExcluded(IPath resourcePath, char[][] inclusionPatterns,
            char[][] exclusionPatterns, boolean isFolderPath) 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

private int elementType(File res, int kind, int parentType, RootInfo rootInfo) {
    Path path = new Path(res.getAbsolutePath());
    switch (parentType) {
    case IJavaElement.JAVA_MODEL:
        // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...)
        return IJavaElement.JAVA_PROJECT;

    case NON_JAVA_RESOURCE:
    case IJavaElement.JAVA_PROJECT:
        if (rootInfo == null) {
            rootInfo = enclosingRootInfo(path, kind);
        }/*  www  . j  av  a2 s . co  m*/
        if (rootInfo != null && rootInfo.isRootOfProject(path)) {
            return IJavaElement.PACKAGE_FRAGMENT_ROOT;
        }
        // not yet in a package fragment root or root of another project
        // or package fragment to be included (see below)
        // $FALL-THROUGH$

    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        if (rootInfo == null) {
            IPath rootPath = externalPath(res);
            rootInfo = enclosingRootInfo(rootPath, kind);
        }
        if (rootInfo == null) {
            return NON_JAVA_RESOURCE;
        }
        if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
            return NON_JAVA_RESOURCE;
        }
        if (res.isDirectory()) {
            if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()),
                    rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
                // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130982)
                return NON_JAVA_RESOURCE;
            }
            String sourceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
            String complianceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) {
                return IJavaElement.PACKAGE_FRAGMENT;
            }
            return NON_JAVA_RESOURCE;
        }
        String fileName = res.getName();
        String sourceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
        String complianceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
        if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.COMPILATION_UNIT;
        } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.CLASS_FILE;
        } else {
            IPath rootPath = externalPath(res);
            if ((rootInfo = rootInfo(rootPath, kind)) != null
                    && rootInfo.project.getProject().getFullPath().isPrefixOf(
                            rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) {
                // case of proj=src=bin and resource is a jar file on the classpath
                return IJavaElement.PACKAGE_FRAGMENT_ROOT;
            } else {
                return NON_JAVA_RESOURCE;
            }
        }

    default:
        return NON_JAVA_RESOURCE;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.AddFolderToIndex.java

License:Open Source License

public boolean execute(IProgressMonitor progressMonitor) {

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled())
        return true;
    //      if (!this.project.isAccessible()) return true; // nothing to do
    //      IResource folder = this.project.getParent().findMember(this.folderPath);

    File folder = new File(folderPath.toOSString());
    if (!folder.exists())
        return true; // nothing to do, source folder was removed

    /* ensure no concurrent write access to index */
    Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
    if (index == null)
        return true;
    ReadWriteMonitor monitor = index.monitor;
    if (monitor == null)
        return true; // index got deleted since acquired

    try {/*from   w  ww .jav  a2 s.c om*/
        monitor.enterRead(); // ask permission to read

        final IPath container = this.containerPath;
        final IndexManager indexManager = this.manager;
        final SourceElementParser parser = indexManager.getSourceElementParser(this.project,
                null/*requestor will be set by indexer*/);
        Path path = FileSystems.getDefault().getPath(folderPath.toOSString());
        if (this.exclusionPatterns == null && this.inclusionPatterns == null) {

            Files.walkFileTree(path, new FileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                        throws IOException {
                    return null;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    if (Util.isJavaLikeFileName(file.toFile().getName()))
                        indexManager.addSource(file, container, parser);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                    return null;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    return null;
                }
            });

            //                folder.accept(
            //               new IResourceProxyVisitor() {
            //                  public boolean visit(IResourceProxy proxy) /* throws CoreException */{
            //                     if (proxy.getType() == IResource.FILE) {
            //
            //                        return false;
            //                     }
            //                     return true;
            //                  }
            //               },
            //               IResource.NONE
            //            );
        } else {
            Files.walkFileTree(path, new FileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                        throws IOException {
                    if (AddFolderToIndex.this.exclusionPatterns != null
                            && AddFolderToIndex.this.inclusionPatterns == null) {
                        // if there are inclusion patterns then we must walk the children
                        if (Util.isExcluded(new org.eclipse.core.runtime.Path(dir.toFile().getPath()),
                                AddFolderToIndex.this.inclusionPatterns,
                                AddFolderToIndex.this.exclusionPatterns, true))
                            return FileVisitResult.SKIP_SUBTREE;
                    }
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    if (Util.isJavaLikeFileName(file.getFileName().toString())) {
                        //                                IResource resource = proxy.requestResource();
                        if (!Util.isExcluded(new org.eclipse.core.runtime.Path(file.toFile().getPath()),
                                AddFolderToIndex.this.inclusionPatterns,
                                AddFolderToIndex.this.exclusionPatterns, false))
                            indexManager.addSource(file, container, parser);
                    }
                    return null;
                }

                @Override
                public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                    return null;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    return null;
                }
            });
            //                folder.accept(
            //               new IResourceProxyVisitor() {
            //                  public boolean visit(IResourceProxy proxy) /* throws CoreException */{
            //                     switch(proxy.getType()) {
            //                        case IResource.FILE :
            //
            //                           return false;
            //                        case IResource.FOLDER :
            //
            //                     }
            //                     return true;
            //                  }
            //               },
            //               IResource.NONE
            //            );
        }
    } catch (IOException e) {
        if (JobManager.VERBOSE) {
            Util.verbose(
                    "-> failed to add " + this.folderPath + " to index because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$
                    System.err);
            e.printStackTrace();
        }
        return false;
    } finally {
        monitor.exitRead(); // free read lock
    }
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.RemoveFolderFromIndex.java

License:Open Source License

public boolean execute(IProgressMonitor progressMonitor) {

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled())
        return true;

    /* ensure no concurrent write access to index */
    Index index = this.manager.getIndex(this.containerPath, true,
            /*reuse index file*/ false /*create if none*/);
    if (index == null)
        return true;
    ReadWriteMonitor monitor = index.monitor;
    if (monitor == null)
        return true; // index got deleted since acquired

    try {//from w w  w  . j  a v a2 s  . co m
        monitor.enterRead(); // ask permission to read
        String containerRelativePath = Util.relativePath(this.folderPath, this.containerPath.segmentCount());
        String[] paths = index.queryDocumentNames(containerRelativePath);
        // all file names belonging to the folder or its subfolders and that are not excluded (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32607)
        if (paths != null) {
            if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
                for (int i = 0, max = paths.length; i < max; i++) {
                    this.manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
                }
            } else {
                for (int i = 0, max = paths.length; i < max; i++) {
                    String documentPath = this.containerPath.toString() + '/' + paths[i];
                    if (!Util.isExcluded(new Path(documentPath), this.inclusionPatterns, this.exclusionPatterns,
                            false))
                        this.manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
                }
            }
        }
    } catch (IOException e) {
        if (JobManager.VERBOSE) {
            Util.verbose("-> failed to remove " + this.folderPath //$NON-NLS-1$
                    + " from index because of the following exception:", System.err); //$NON-NLS-1$
            e.printStackTrace();
        }
        return false;
    } finally {
        monitor.exitRead(); // free read lock
    }
    return true;
}

From source file:com.google.appengine.eclipse.core.orm.enhancement.AutoEnhancer.java

License:Open Source License

/**
 * Answers whether the class file for a particular Java source file should be
 * enhanced. Right now we just check the Java file path against the defined
 * ORM inclusion patterns, but in the future we could possibly look at ORM
 * annotations in the file, or use some other more specific heuristic.
 *//* w ww.j  a v  a  2 s . c  om*/
private boolean shouldEnhanceClass(IPath javaFilePath) {
    if (javaFilePath == null) {
        // If we can't find a Java source file, go ahead and enhance anyway
        return true;
    }

    // NOTE: inclusionPatterns cannot be null, or this method will automatically
    // return false and cause us to include *all* classes, instead of none.
    boolean shouldEnhance = !Util.isExcluded(javaFilePath.removeFirstSegments(1).makeRelative(),
            inclusionPatterns, null, false);
    return shouldEnhance;
}

From source file:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

public static List<? extends CategorizedProblem> validateCompilationUnit(ASTNode ast) {
    CompilationUnit root = (CompilationUnit) ast.getRoot();
    ICompilationUnit cu = (ICompilationUnit) root.getJavaElement();

    // If the compilation unit is not on the build classpath, return an empty
    // list of problems.
    if (!cu.getJavaProject().isOnClasspath(cu)) {
        return Collections.emptyList();
    }//from w  w w  .j a v a2  s. c o  m

    List<IPath> validationExclusionPatterns = GaeProjectProperties
            .getValidationExclusionPatterns(cu.getJavaProject().getProject());
    char[][] exclusionPatterns = null;
    if (!validationExclusionPatterns.isEmpty()) {
        exclusionPatterns = new char[validationExclusionPatterns.size()][];
        for (int i = 0; i < validationExclusionPatterns.size(); ++i) {
            exclusionPatterns[i] = validationExclusionPatterns.get(i).toString().toCharArray();
        }
    }

    // Get the source root relative path, since our exclusion filter does
    // not include the project name, but the compilation unit's path does.
    IPath sourceRelativePath = cu.getPath().removeFirstSegments(1);
    if (Util.isExcluded(sourceRelativePath, null, exclusionPatterns, false)) {
        return Collections.emptyList();
    }

    List<CategorizedProblem> problems = GoogleCloudSqlChecker.check(root, cu.getJavaProject());
    problems.addAll(GaeChecker.check(root, cu.getJavaProject()));

    return problems;
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
    for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        final ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
        final char[][] inclusionPatterns = sourceLocation.inclusionPatterns;
        final boolean isAlsoProject = sourceLocation.sourceFolder.equals(this.javaBuilder.currentProject);
        final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
        final IContainer outputFolder = sourceLocation.binaryFolder;
        final boolean isOutputFolder = sourceLocation.sourceFolder.equals(outputFolder);
        sourceLocation.sourceFolder.accept(new IResourceProxyVisitor() {
            public boolean visit(IResourceProxy proxy) throws CoreException {
                switch (proxy.getType()) {
                case IResource.FILE:
                    if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
                        IResource resource = proxy.requestResource();
                        if (exclusionPatterns != null || inclusionPatterns != null)
                            if (Util.isExcluded(resource.getFullPath(), inclusionPatterns, exclusionPatterns,
                                    false))
                                return false;
                        sourceFiles.add(new SourceFile((IFile) resource, sourceLocation));
                    }/*from   w w w .ja va2s .co  m*/
                    return false;
                case IResource.FOLDER:
                    IPath folderPath = null;
                    if (isAlsoProject)
                        if (isExcludedFromProject(folderPath = proxy.requestFullPath()))
                            return false;
                    if (exclusionPatterns != null) {
                        if (folderPath == null)
                            folderPath = proxy.requestFullPath();
                        if (Util.isExcluded(folderPath, inclusionPatterns, exclusionPatterns, true)) {
                            // must walk children if inclusionPatterns != null, can skip them if == null
                            // but folder is excluded so do not create it in the output folder
                            return inclusionPatterns != null;
                        }
                    }
                    if (!isOutputFolder) {
                        if (folderPath == null)
                            folderPath = proxy.requestFullPath();
                        String packageName = folderPath.lastSegment();
                        if (packageName.length() > 0) {
                            String sourceLevel = AbstractImageBuilder.this.javaBuilder.javaProject
                                    .getOption(JavaCore.COMPILER_SOURCE, true);
                            String complianceLevel = AbstractImageBuilder.this.javaBuilder.javaProject
                                    .getOption(JavaCore.COMPILER_COMPLIANCE, true);
                            if (JavaConventions.validatePackageName(packageName, sourceLevel, complianceLevel)
                                    .getSeverity() != IStatus.ERROR)
                                createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
                        }
                    }
                }
                return true;
            }
        }, IResource.NONE);
        this.notifier.checkCancel();
    }
}

From source file:net.sf.j2s.core.builder.BatchImageBuilder.java

License:Open Source License

protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll = JavaCore.CLEAN
            .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
        if (this.javaBuilder.participants != null)
            for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
                this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

        ArrayList visited = new ArrayList(this.sourceLocations.length);
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            this.notifier.subTask(
                    Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder) {
                IContainer outputFolder = sourceLocation.binaryFolder;
                if (!visited.contains(outputFolder)) {
                    visited.add(outputFolder);
                    IResource[] members = outputFolder.members();
                    for (int j = 0, m = members.length; j < m; j++) {
                        IResource member = members[j];
                        if (!member.isDerived()) {
                            member.accept(new IResourceVisitor() {
                                public boolean visit(IResource resource) throws CoreException {
                                    resource.setDerived(true, null);
                                    return resource.getType() != IResource.FILE;
                                }//from w w w.  ja v  a 2s.  com
                            });
                        }
                        member.delete(IResource.FORCE, null);
                    }
                }
                this.notifier.checkCancel();
                if (copyBack)
                    copyExtraResourcesBack(sourceLocation, true);
            } else {
                boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
                final char[][] exclusionPatterns = isOutputFolder ? sourceLocation.exclusionPatterns : null; // ignore exclusionPatterns if output folder == another source folder... not this one
                final char[][] inclusionPatterns = isOutputFolder ? sourceLocation.inclusionPatterns : null; // ignore inclusionPatterns if output folder == another source folder... not this one
                sourceLocation.binaryFolder.accept(new IResourceProxyVisitor() {
                    public boolean visit(IResourceProxy proxy) throws CoreException {
                        if (proxy.getType() == IResource.FILE) {
                            if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) {
                                IResource resource = proxy.requestResource();
                                if (exclusionPatterns != null || inclusionPatterns != null)
                                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns,
                                            exclusionPatterns, false))
                                        return false;
                                if (!resource.isDerived())
                                    resource.setDerived(true, null);
                                resource.delete(IResource.FORCE, null);
                            }
                            return false;
                        }
                        if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                            if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                                return false;
                        BatchImageBuilder.this.notifier.checkCancel();
                        return true;
                    }
                }, IResource.NONE);
                this.notifier.checkCancel();
            }
            this.notifier.checkCancel();
        }
    } else if (copyBack) {
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder)
                copyExtraResourcesBack(sourceLocation, false);
            this.notifier.checkCancel();
        }
    }
}

From source file:net.sf.j2s.core.builder.BatchImageBuilder.java

License:Open Source License

protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll)
        throws CoreException {
    // When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
    // If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.

    this.notifier.subTask(Messages.build_copyingResources);
    final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
    final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
    final char[][] inclusionPatterns = sourceLocation.inclusionPatterns;
    final IContainer outputFolder = sourceLocation.binaryFolder;
    final boolean isAlsoProject = sourceLocation.sourceFolder.equals(this.javaBuilder.currentProject);
    sourceLocation.sourceFolder.accept(new IResourceProxyVisitor() {
        public boolean visit(IResourceProxy proxy) throws CoreException {
            IResource resource = null;/*from   w w  w .jav  a  2  s. c  o m*/
            switch (proxy.getType()) {
            case IResource.FILE:
                if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())
                        || org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName()))
                    return false;

                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (exclusionPatterns != null || inclusionPatterns != null)
                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                        return false;

                IPath partialPath = resource.getFullPath().removeFirstSegments(segmentCount);
                IResource copiedResource = outputFolder.getFile(partialPath);
                if (copiedResource.exists()) {
                    if (deletedAll) {
                        IResource originalResource = findOriginalResource(partialPath);
                        String id = originalResource.getFullPath().removeFirstSegments(1).toString();
                        createProblemFor(resource, null, Messages.bind(Messages.build_duplicateResource, id),
                                BatchImageBuilder.this.javaBuilder.javaProject
                                        .getOption(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, true));
                        return false;
                    }
                    copiedResource.delete(IResource.FORCE, null); // last one wins
                }
                createFolder(partialPath.removeLastSegments(1), outputFolder); // ensure package folder exists
                copyResource(resource, copiedResource);
                return false;
            case IResource.FOLDER:
                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (isAlsoProject && isExcludedFromProject(resource.getFullPath()))
                    return false; // the sourceFolder == project
                if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                    if (Util.isExcluded(resource.getFullPath(), null, exclusionPatterns, true))
                        return false;
            }
            return true;
        }
    }, IResource.NONE);
}

From source file:org.codehaus.groovy.eclipse.wizards.NewClassWizardPage.java

License:Apache License

@Override
protected IStatus typeNameChanged() {
    StatusInfo status = (StatusInfo) super.typeNameChanged();
    IPackageFragment pack = getPackageFragment();
    if (pack == null) {
        return status;
    }//www  .j a v a 2  s . c  o m

    IJavaProject project = pack.getJavaProject();
    try {
        if (!project.getProject().hasNature(GroovyNature.GROOVY_NATURE)) {
            status.setWarning(project.getElementName()
                    + " is not a groovy project.  Groovy Nature will be added to project upon completion.");
        }
    } catch (CoreException e) {
        status.setError("Exception when accessing project natures for " + project.getElementName());
    }

    String typeName = getTypeNameWithoutParameters();
    // must not exist as a .groovy file
    if (!isEnclosingTypeSelected() && (status.getSeverity() < IStatus.ERROR)) {
        if (pack != null) {
            IType type = null;
            try {
                type = project.findType(pack.getElementName(), typeName);
            } catch (JavaModelException e) {
                // can ignore
            }
            if (type != null && type.getPackageFragment().equals(pack)) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
            }
        }
    }

    // lastly, check exclusion filters to see if Groovy files are allowed in
    // the source folder
    if (status.getSeverity() < IStatus.ERROR) {
        try {
            ClasspathEntry entry = (ClasspathEntry) ((IPackageFragmentRoot) pack.getParent())
                    .getRawClasspathEntry();
            if (entry != null) {
                char[][] inclusionPatterns = entry.fullInclusionPatternChars();
                char[][] exclusionPatterns = entry.fullExclusionPatternChars();
                if (Util.isExcluded(pack.getResource().getFullPath().append(getCompilationUnitName(typeName)),
                        inclusionPatterns, exclusionPatterns, false)) {
                    status.setError(
                            "Cannot create Groovy type because of exclusion patterns on the source folder.");
                }

            }
        } catch (JavaModelException e) {
            status.setError(e.getLocalizedMessage());
            GroovyCore.logException("Exception inside new Groovy class wizard", e);
        }
    }

    return status;
}

From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java

License:Open Source License

private int elementType(File res, int kind, int parentType, RootInfo rootInfo) {
    Path path = new Path(res.getAbsolutePath());
    switch (parentType) {
    case IJavaElement.JAVA_MODEL:
        // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...)
        return IJavaElement.JAVA_PROJECT;

    case NON_JAVA_RESOURCE:
    case IJavaElement.JAVA_PROJECT:
        if (rootInfo == null) {
            rootInfo = enclosingRootInfo(path, kind);
        }//from  w  ww  .  j  av  a 2  s. c om
        if (rootInfo != null && rootInfo.isRootOfProject(path)) {
            return IJavaElement.PACKAGE_FRAGMENT_ROOT;
        }
        // not yet in a package fragment root or root of another project
        // or package fragment to be included (see below)
        // $FALL-THROUGH$

    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        if (rootInfo == null) {
            IPath rootPath = externalPath(res);
            rootInfo = enclosingRootInfo(rootPath, kind);
        }
        if (rootInfo == null) {
            return NON_JAVA_RESOURCE;
        }
        if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
            return NON_JAVA_RESOURCE;
        }
        if (res.isDirectory()) {
            if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()),
                    rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
                // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse
                // .org/bugs/show_bug.cgi?id=130982)
                return NON_JAVA_RESOURCE;
            }
            String sourceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
            String complianceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) {
                return IJavaElement.PACKAGE_FRAGMENT;
            }
            return NON_JAVA_RESOURCE;
        }
        String fileName = res.getName();
        String sourceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
        String complianceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
        if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.COMPILATION_UNIT;
        } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.CLASS_FILE;
        } else {
            IPath rootPath = externalPath(res);
            if ((rootInfo = rootInfo(rootPath, kind)) != null
                    && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310)
                                                                                        */) {
                // case of proj=src=bin and resource is a jar file on the classpath
                return IJavaElement.PACKAGE_FRAGMENT_ROOT;
            } else {
                return NON_JAVA_RESOURCE;
            }
        }

    default:
        return NON_JAVA_RESOURCE;
    }
}