Java Code Examples for com.intellij.psi.PsiElement#processDeclarations()

The following examples show how to use com.intellij.psi.PsiElement#processDeclarations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSharpLinqQueryBodyImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(PsiElement psiElement : getChildren())
	{
		if(!psiElement.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example 2
Source File: CSharpLinqExpressionImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(PsiElement psiElement : getChildren())
	{
		if(!psiElement.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example 3
Source File: PsiScopesUtilCore.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean walkChildrenScopes(@Nonnull PsiElement thisElement,
                                         @Nonnull PsiScopeProcessor processor,
                                         @Nonnull ResolveState state,
                                         PsiElement lastParent,
                                         PsiElement place) {
  PsiElement child = null;
  if (lastParent != null && lastParent.getParent() == thisElement) {
    child = lastParent.getPrevSibling();
    if (child == null) return true; // first element
  }

  if (child == null) {
    child = thisElement.getLastChild();
  }

  while (child != null) {
    if (!child.processDeclarations(processor, state, null, place)) return false;
    child = child.getPrevSibling();
  }

  return true;
}
 
Example 4
Source File: BashResolveUtil.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
public static boolean processContainerDeclarations(BashPsiElement thisElement, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, final PsiElement lastParent, @NotNull final PsiElement place) {
    if (thisElement == lastParent) {
        return true;
    }

    if (!processor.execute(thisElement, state)) {
        return false;
    }

    //process the current's elements children from first until lastParent is reached, a definition has to be before the use
    List<PsiElement> functions = Lists.newLinkedList();

    //fixme use stubs
    for (PsiElement child = thisElement.getFirstChild(); child != null && child != lastParent; child = child.getNextSibling()) {
        if (child instanceof BashFunctionDef) {
            functions.add(child);
        } else if (!child.processDeclarations(processor, state, lastParent, place)) {
            return false;
        }
    }

    for (PsiElement function : functions) {
        if (!function.processDeclarations(processor, state, lastParent, place)) {
            return false;
        }
    }

    //fixme this is very slow atm
    if (lastParent != null && lastParent.getParent().isEquivalentTo(thisElement) && BashPsiUtils.findNextVarDefFunctionDefScope(place) != null) {
        for (PsiElement sibling = lastParent.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
            if (!sibling.processDeclarations(processor, state, null, place)) {
                return false;
            }
        }
    }

    return true;
}
 
Example 5
Source File: GLSLFile.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (lastParent == null) {
        return true;
    }
    PsiElement child = lastParent.getPrevSibling();
    while (child != null) {
        if (!child.processDeclarations(processor, state, lastParent, place)) return false;
        child = child.getPrevSibling();
    }
    return true;
}
 
Example 6
Source File: CSharpXAccessorImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(ExecuteTargetUtil.canProcess(processor, ExecuteTarget.LOCAL_VARIABLE_OR_PARAMETER_OR_LOCAL_METHOD))
	{
		PsiElement parent = getParent();
		if(!parent.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}

		Kind accessorKind = getAccessorKind();
		if(accessorKind == Kind.SET || accessorKind == Kind.ADD || accessorKind == Kind.REMOVE)
		{
			Pair<DotNetTypeRef, DotNetQualifiedElement> pair = getTypeRefOfParent();
			if(pair.getSecond() == null)
			{
				return true;
			}

			CSharpLightLocalVariableBuilder builder = new CSharpLightLocalVariableBuilder(pair.getSecond()).withName(VALUE).withParent(this)
					.withTypeRef(pair.getFirst());

			builder.putUserData(CSharpResolveUtil.ACCESSOR_VALUE_VARIABLE_OWNER, pair.getSecond());

			if(!processor.execute(builder, state))
			{
				return false;
			}
		}
	}
	return true;
}
 
Example 7
Source File: ResolveUtil.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public static <T extends XQueryPsiElement> boolean processChildren(PsiElement element, PsiScopeProcessor processor,
        ResolveState substitutor, PsiElement lastParent, PsiElement place, Class<T>... childClassesToSkip) {
    PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
    while (run != null) {
        if (!isAnyOf(run, childClassesToSkip) &&PsiTreeUtil.findCommonParent(place, run) != run && !run.processDeclarations(processor, substitutor,
                null, place)) {
            return false;
        }
        run = run.getPrevSibling();
    }

    return true;
}
 
Example 8
Source File: PsiScopesUtilCore.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean treeWalkUp(@Nonnull final PsiScopeProcessor processor,
                                 @Nonnull final PsiElement entrance,
                                 @Nullable final PsiElement maxScope,
                                 @Nonnull final ResolveState state) {
  if (!entrance.isValid()) {
    LOGGER.error(new PsiInvalidElementAccessException(entrance));
  }
  PsiElement prevParent = entrance;
  PsiElement scope = entrance;

  while (scope != null) {
    ProgressIndicatorProvider.checkCanceled();

    if (!scope.processDeclarations(processor, state, prevParent, entrance)) {
      return false; // resolved
    }


    if (scope == maxScope) break;
    prevParent = scope;
    scope = prevParent.getContext();
    if (scope != null && scope != prevParent.getParent() && !scope.isValid()) {
      break;
    }

  }

  return true;
}
 
Example 9
Source File: CSharpResolveUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public static boolean treeWalkUp(@Nonnull final PsiScopeProcessor processor,
		@Nonnull final PsiElement entrance,
		@Nonnull final PsiElement sender,
		@Nullable PsiElement maxScope,
		@Nonnull final ResolveState state)
{
	if(!entrance.isValid())
	{
		CSharpResolveUtil.LOG.error(new PsiInvalidElementAccessException(entrance));
	}

	PsiElement prevParent = entrance;
	PsiElement scope = entrance;

	if(maxScope == null)
	{
		maxScope = sender.getContainingFile();
	}

	while(scope != null)
	{
		ProgressIndicatorProvider.checkCanceled();

		if(entrance != sender && scope instanceof PsiFile)
		{
			break;
		}

		if(!scope.processDeclarations(processor, state, prevParent, entrance))
		{
			return false; // resolved
		}

		if(entrance != sender)
		{
			break;
		}

		if(scope == maxScope)
		{
			break;
		}

		prevParent = scope;
		scope = prevParent.getContext();
		if(scope != null && scope != prevParent.getParent() && !scope.isValid())
		{
			break;
		}
	}

	return true;
}