Search in sources :

Example 11 with PsiFragment

use of com.intellij.dupLocator.util.PsiFragment in project intellij-community by JetBrains.

the class TreeHasherBase method computeElementHash.

@Override
protected TreeHashResult computeElementHash(@NotNull PsiElement root, PsiFragment upper, NodeSpecificHasher hasher) {
    if (myForIndexing) {
        return TreeHashingUtils.computeElementHashForIndexing(this, myCallBack, root, upper, hasher);
    }
    final List<PsiElement> children = hasher.getNodeChildren(root);
    final int size = children.size();
    final int[] childHashes = new int[size];
    final int[] childCosts = new int[size];
    final PsiFragment fragment = buildFragment(hasher, root, getCost(root));
    if (upper != null) {
        fragment.setParent(upper);
    }
    if (size == 0 && !(root instanceof LeafElement)) {
        // contains only whitespaces and other unmeaning children
        return new TreeHashResult(0, hasher.getNodeCost(root), fragment);
    }
    for (int i = 0; i < size; i++) {
        final TreeHashResult res = this.hash(children.get(i), fragment, hasher);
        childHashes[i] = res.getHash();
        childCosts[i] = res.getCost();
    }
    final int c = hasher.getNodeCost(root) + AbstractTreeHasher.vector(childCosts);
    final int h1 = hasher.getNodeHash(root);
    final int discardCost = getDiscardCost(root);
    for (int i = 0; i < size; i++) {
        if (childCosts[i] <= discardCost && ignoreChildHash(children.get(i))) {
            childHashes[i] = 0;
        }
    }
    int h = h1 + AbstractTreeHasher.vector(childHashes);
    if (shouldBeAnonymized(root, (NodeSpecificHasherBase) hasher)) {
        h = 0;
    }
    if (myCallBack != null) {
        myCallBack.add(h, c, fragment);
    }
    return new TreeHashResult(h, c, fragment);
}
Also used : PsiFragment(com.intellij.dupLocator.util.PsiFragment) PsiElement(com.intellij.psi.PsiElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Aggregations

PsiFragment (com.intellij.dupLocator.util.PsiFragment)11 PsiElement (com.intellij.psi.PsiElement)7 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)2 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1 LightDuplicateProfile (com.intellij.dupLocator.LightDuplicateProfile)1 MultiChildDescriptor (com.intellij.dupLocator.equivalence.MultiChildDescriptor)1 SingleChildDescriptor (com.intellij.dupLocator.equivalence.SingleChildDescriptor)1 FragmentsCollector (com.intellij.dupLocator.treeHash.FragmentsCollector)1 FileASTNode (com.intellij.lang.FileASTNode)1 LighterAST (com.intellij.lang.LighterAST)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 TreeBackedLighterAST (com.intellij.lang.TreeBackedLighterAST)1 PathMacroManager (com.intellij.openapi.components.PathMacroManager)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1