Search in sources :

Example 1 with LinkedHashSet

use of java.util.LinkedHashSet in project webmagic by code4craft.

the class ClassUtils method getFieldsIncludeSuperClass.

public static Set<Field> getFieldsIncludeSuperClass(Class clazz) {
    Set<Field> fields = new LinkedHashSet<Field>();
    Class current = clazz;
    while (current != null) {
        Field[] currentFields = current.getDeclaredFields();
        for (Field currentField : currentFields) {
            fields.add(currentField);
        }
        current = current.getSuperclass();
    }
    return fields;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Field(java.lang.reflect.Field)

Example 2 with LinkedHashSet

use of java.util.LinkedHashSet in project cogtool by cogtool.

the class FramePropertiesPane method update.

public void update(Frame frame) {
    Object pathObj = frame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
    if (NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
        imagePath.setVisible(false);
        imagePathText.setVisible(false);
    } else {
        String imgPath = (String) pathObj;
        imagePath.setVisible(true);
        imagePathText.setVisible(true);
        imagePathText.setText(imgPath);
        imagePathText.setSelection(imgPath.length());
    }
    Set<TransitionSource> children = new LinkedHashSet<TransitionSource>();
    children.addAll(frame.getWidgets());
    children.addAll(frame.getInputDevices());
    widgetUpdater.updateTree(children.iterator());
    if (eltGroupTreeLabel != null) {
        Set<FrameElementGroup> grps = frame.getEltGroups();
        if (!CogToolPref.NESTED_GROUPS_SHOWN_AT_TOP_LEVEL.getBoolean()) {
            grps = filterNestedGroups(grps);
        }
        eltGroupUpdater.updateTree(grps.iterator());
        Set<SimpleWidgetGroup> implicitGroups = new HashSet<SimpleWidgetGroup>();
        for (IWidget w : frame.getWidgets()) {
            SimpleWidgetGroup g = w.getParentGroup();
            if (g != null) {
                implicitGroups.add(g);
            }
        }
        implicitGroupUpdater.updateTree(implicitGroups.iterator());
    }
    setFrameName(frame);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with LinkedHashSet

use of java.util.LinkedHashSet in project jetty.project by eclipse.

the class OSGiWebInfConfiguration method configure.

/* ------------------------------------------------------------ */
/** 
     * Allow fragments to supply some resources that are added to the baseResource of the webapp.
     * 
     * The resources can be either prepended or appended to the baseResource.
     * 
     * @see org.eclipse.jetty.webapp.WebInfConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
     */
@Override
public void configure(WebAppContext context) throws Exception {
    TreeMap<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>();
    TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>();
    Bundle bundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
    if (bundle != null) {
        Set<Bundle> fragments = (Set<Bundle>) context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
        if (fragments != null && !fragments.isEmpty()) {
            // looked up.
            for (Bundle frag : fragments) {
                String path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_FRAGMENT_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_FRAGMENT_RESOURCE_PATH, frag.getHeaders());
                convertFragmentPathToResource(path, frag, appendedResourcesPath);
                path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_PREPEND_FRAGMENT_RESOURCE_PATH, frag.getHeaders());
                convertFragmentPathToResource(path, frag, prependedResourcesPath);
            }
            if (!appendedResourcesPath.isEmpty()) {
                LinkedHashSet<Resource> resources = new LinkedHashSet<Resource>();
                //Add in any existing setting of extra resource dirs
                Set<Resource> resourceDirs = (Set<Resource>) context.getAttribute(WebInfConfiguration.RESOURCE_DIRS);
                if (resourceDirs != null && !resourceDirs.isEmpty())
                    resources.addAll(resourceDirs);
                //Then append the values from JETTY_WAR_FRAGMENT_FOLDER_PATH
                resources.addAll(appendedResourcesPath.values());
                context.setAttribute(WebInfConfiguration.RESOURCE_DIRS, resources);
            }
        }
    }
    super.configure(context);
    // place the prepended resources at the beginning of the contexts's resource base
    if (!prependedResourcesPath.isEmpty()) {
        Resource[] resources = new Resource[1 + prependedResourcesPath.size()];
        System.arraycopy(prependedResourcesPath.values().toArray(new Resource[prependedResourcesPath.size()]), 0, resources, 0, prependedResourcesPath.size());
        resources[resources.length - 1] = context.getBaseResource();
        context.setBaseResource(new ResourceCollection(resources));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Bundle(org.osgi.framework.Bundle) Resource(org.eclipse.jetty.util.resource.Resource) TreeMap(java.util.TreeMap) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 4 with LinkedHashSet

use of java.util.LinkedHashSet in project che by eclipse.

the class CheArtifactResolver method resolve.

// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
    Artifact rootArtifact = request.getArtifact();
    Set<Artifact> artifacts = request.getArtifactDependencies();
    Map<String, Artifact> managedVersions = request.getManagedVersionMap();
    List<ResolutionListener> listeners = request.getListeners();
    ArtifactFilter collectionFilter = request.getCollectionFilter();
    ArtifactFilter resolutionFilter = request.getResolutionFilter();
    RepositorySystemSession session = getSession(request.getLocalRepository());
    //TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
    if (source == null) {
        try {
            source = container.lookup(ArtifactMetadataSource.class);
        } catch (ComponentLookupException e) {
        // won't happen
        }
    }
    if (listeners == null) {
        listeners = new ArrayList<ResolutionListener>();
        if (logger.isDebugEnabled()) {
            listeners.add(new DebugResolutionListener(logger));
        }
        listeners.add(new WarningResolutionListener(logger));
    }
    ArtifactResolutionResult result = new ArtifactResolutionResult();
    if (request.isResolveRoot()) /* && rootArtifact.getFile() == null */
    {
        try {
            resolve(rootArtifact, request.getRemoteRepositories(), session);
        } catch (ArtifactResolutionException e) {
            result.addErrorArtifactException(e);
            return result;
        } catch (ArtifactNotFoundException e) {
            result.addMissingArtifact(request.getArtifact());
            return result;
        }
    }
    ArtifactResolutionRequest collectionRequest = request;
    if (request.isResolveTransitively()) {
        MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request);
        metadataRequest.setArtifact(rootArtifact);
        metadataRequest.setResolveManagedVersions(managedVersions == null);
        try {
            ResolutionGroup resolutionGroup = source.retrieve(metadataRequest);
            if (managedVersions == null) {
                managedVersions = resolutionGroup.getManagedVersions();
            }
            Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
            if (artifacts == null || artifacts.isEmpty()) {
                artifacts = directArtifacts;
            } else {
                List<Artifact> allArtifacts = new ArrayList<Artifact>();
                allArtifacts.addAll(artifacts);
                allArtifacts.addAll(directArtifacts);
                Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
                for (Artifact artifact : allArtifacts) {
                    String conflictId = artifact.getDependencyConflictId();
                    if (!mergedArtifacts.containsKey(conflictId)) {
                        mergedArtifacts.put(conflictId, artifact);
                    }
                }
                artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values());
            }
            collectionRequest = new ArtifactResolutionRequest(request);
            collectionRequest.setServers(request.getServers());
            collectionRequest.setMirrors(request.getMirrors());
            collectionRequest.setProxies(request.getProxies());
            collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories());
        } catch (ArtifactMetadataRetrievalException e) {
            ArtifactResolutionException are = new ArtifactResolutionException("Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e);
            result.addMetadataResolutionException(are);
            return result;
        }
    }
    if (artifacts == null || artifacts.isEmpty()) {
        if (request.isResolveRoot()) {
            result.addArtifact(rootArtifact);
        }
        return result;
    }
    // After the collection we will have the artifact object in the result but they will not be resolved yet.
    result = artifactCollector.collect(artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null);
    if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) {
        return result;
    }
    if (result.getArtifactResolutionNodes() != null) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size());
        for (ResolutionNode node : result.getArtifactResolutionNodes()) {
            Artifact artifact = node.getArtifact();
            if (resolutionFilter == null || resolutionFilter.include(artifact)) {
                executor.execute(new ResolveTask(classLoader, latch, artifact, session, node.getRemoteRepositories(), result));
            } else {
                latch.countDown();
            }
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            result.addErrorArtifactException(new ArtifactResolutionException("Resolution interrupted", rootArtifact, e));
        }
    }
    // have been resolved.
    if (request.isResolveRoot()) {
        // Add the root artifact (as the first artifact to retain logical order of class path!)
        Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
        allArtifacts.add(rootArtifact);
        allArtifacts.addAll(result.getArtifacts());
        result.setArtifacts(allArtifacts);
    }
    return result;
}
Also used : DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) MetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ResolutionListener(org.apache.maven.artifact.resolver.ResolutionListener) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ResolutionNode(org.apache.maven.artifact.resolver.ResolutionNode) ResolutionGroup(org.apache.maven.artifact.metadata.ResolutionGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource)

Example 5 with LinkedHashSet

use of java.util.LinkedHashSet in project che by eclipse.

the class UnusedCodeFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems, boolean removeUnusedPrivateMethods, boolean removeUnusedPrivateConstructors, boolean removeUnusedPrivateFields, boolean removeUnusedPrivateTypes, boolean removeUnusedLocalVariables, boolean removeUnusedImports, boolean removeUnusedCast) {
    List<CompilationUnitRewriteOperation> result = new ArrayList<CompilationUnitRewriteOperation>();
    Hashtable<ASTNode, List<SimpleName>> variableDeclarations = new Hashtable<ASTNode, List<SimpleName>>();
    LinkedHashSet<CastExpression> unnecessaryCasts = new LinkedHashSet<CastExpression>();
    for (int i = 0; i < problems.length; i++) {
        IProblemLocation problem = problems[i];
        int id = problem.getProblemId();
        if (removeUnusedImports && (id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound)) {
            ImportDeclaration node = UnusedCodeFix.getImportDeclaration(problem, compilationUnit);
            if (node != null) {
                result.add(new RemoveImportOperation(node));
            }
        }
        if ((removeUnusedPrivateMethods && id == IProblem.UnusedPrivateMethod) || (removeUnusedPrivateConstructors && id == IProblem.UnusedPrivateConstructor) || (removeUnusedPrivateTypes && id == IProblem.UnusedPrivateType)) {
            SimpleName name = getUnusedName(compilationUnit, problem);
            if (name != null) {
                IBinding binding = name.resolveBinding();
                if (binding != null) {
                    result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
                }
            }
        }
        if ((removeUnusedLocalVariables && id == IProblem.LocalVariableIsNeverUsed) || (removeUnusedPrivateFields && id == IProblem.UnusedPrivateField)) {
            SimpleName name = getUnusedName(compilationUnit, problem);
            if (name != null) {
                IBinding binding = name.resolveBinding();
                if (binding instanceof IVariableBinding && !isFormalParameterInEnhancedForStatement(name) && (!((IVariableBinding) binding).isField() || isSideEffectFree(name, compilationUnit))) {
                    VariableDeclarationFragment parent = (VariableDeclarationFragment) ASTNodes.getParent(name, VariableDeclarationFragment.class);
                    if (parent != null) {
                        ASTNode varDecl = parent.getParent();
                        if (!variableDeclarations.containsKey(varDecl)) {
                            variableDeclarations.put(varDecl, new ArrayList<SimpleName>());
                        }
                        variableDeclarations.get(varDecl).add(name);
                    } else {
                        result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
                    }
                }
            }
        }
        if (removeUnusedCast && id == IProblem.UnnecessaryCast) {
            ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
            ASTNode curr = selectedNode;
            while (curr instanceof ParenthesizedExpression) {
                curr = ((ParenthesizedExpression) curr).getExpression();
            }
            if (curr instanceof CastExpression) {
                unnecessaryCasts.add((CastExpression) curr);
            }
        }
    }
    for (Iterator<ASTNode> iter = variableDeclarations.keySet().iterator(); iter.hasNext(); ) {
        ASTNode node = iter.next();
        List<SimpleName> names = variableDeclarations.get(node);
        result.add(new RemoveUnusedMemberOperation(names.toArray(new SimpleName[names.size()]), false));
    }
    if (unnecessaryCasts.size() > 0)
        result.add(new RemoveAllCastOperation(unnecessaryCasts));
    if (result.size() == 0)
        return null;
    return new UnusedCodeFix(FixMessages.UnusedCodeFix_change_name, compilationUnit, result.toArray(new CompilationUnitRewriteOperation[result.size()]));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) ArrayList(java.util.ArrayList) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ASTNode(org.eclipse.jdt.core.dom.ASTNode) List(java.util.List) ArrayList(java.util.ArrayList) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) Hashtable(java.util.Hashtable) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ImportDeclaration(org.eclipse.jdt.core.dom.ImportDeclaration) CastExpression(org.eclipse.jdt.core.dom.CastExpression)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3022 ArrayList (java.util.ArrayList)610 Set (java.util.Set)397 HashSet (java.util.HashSet)322 HashMap (java.util.HashMap)300 Map (java.util.Map)269 File (java.io.File)259 List (java.util.List)253 LinkedHashMap (java.util.LinkedHashMap)245 IOException (java.io.IOException)239 Test (org.junit.Test)221 LinkedList (java.util.LinkedList)136 Collection (java.util.Collection)90 URL (java.net.URL)82 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 Iterator (java.util.Iterator)71 TreeSet (java.util.TreeSet)65 TreeMap (java.util.TreeMap)62 Collectors (java.util.stream.Collectors)57