當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiElement.getContext方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiElement.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiElement.getContext方法的具體用法?Java PsiElement.getContext怎麽用?Java PsiElement.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiElement的用法示例。


在下文中一共展示了PsiElement.getContext方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMaxLocalScopeForTargetOrReference

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Nullable
public static PsiElement getMaxLocalScopeForTargetOrReference(PsiElement element) {
  if (element == null) {
    return null;
  }
  PsiElement currentScope;
  if (element instanceof AppleScriptTargetVariable
          || element instanceof AppleScriptReferenceElement) {
    //local scope: handler definition, current file, object declaration
    currentScope = element.getContext();
    boolean roofReached = false;
    while (!roofReached && currentScope != null) {
      IElementType elementType = currentScope.getNode().getElementType();
      roofReached = HANDLER_DEFINITIONS.contains(elementType)
              || elementType == AppleScriptParserDefinition.FILE
              || element == AppleScriptTypes.OBJECT_TARGET_PROPERTY_DECLARATION;//todo to check this
      currentScope = roofReached ? currentScope : currentScope.getContext();
    }
    return currentScope;
  }
  return null;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:23,代碼來源:ScopeUtil.java

示例2: isFunctionParameter

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
private static boolean isFunctionParameter(PsiElement psiElement, int parameterIndex, String... funcName) {
    PsiElement variableContext = psiElement.getContext();
    if(!(variableContext instanceof ParameterList)) {
        return false;
    } else {
        ParameterList parameterList = (ParameterList) variableContext;
        PsiElement context = parameterList.getContext();
        if(!(context instanceof FunctionReference)) {
            return false;
        } else {
            FunctionReference methodReference = (FunctionReference) context;
            String name = methodReference.getName();

            return (name != null && Arrays.asList(funcName).contains(name) && getParameterIndex(parameterList, psiElement) == parameterIndex);
        }
    }
}
 
開發者ID:adelf,項目名稱:idea-php-dotenv-plugin,代碼行數:18,代碼來源:PsiUtil.java

示例3: applyFix

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement item = descriptor.getPsiElement();

    PsiElement context = item.getContext();
    if (context instanceof ArrayCreationExpression) {
        ArrayCreationExpression params = (ArrayCreationExpression) item.getParent();

        PsiUtil.deleteArrayElement(item);

        if (!params.getHashElements().iterator().hasNext()) {
            if (params.getPrevSibling() instanceof PsiWhiteSpace) {
                params.getPrevSibling().delete();
            }
            params.getPrevSibling().delete();
            params.delete();
        }
    }
    if (context instanceof ParameterList && context.getParent() instanceof FunctionReference) {
        FunctionReference functionReference = (FunctionReference) context.getParent();
        if (functionReference.getName() != null && functionReference.getName().equals("compact")) {
            PsiUtil.deleteFunctionParam(item);

            if (functionReference.getParameters().length == 0) {
                PsiUtil.deleteFunctionParam(functionReference);
            }
        }
    }
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:30,代碼來源:UnusedParameterLocalQuickFix.java

示例4: getHandlerDefinitionScope

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Nullable
private PsiElement getHandlerDefinitionScope(PsiElement scopeElement) {
  PsiElement currentScope = scopeElement;
  while (currentScope != null) {
    IElementType elementType = currentScope.getNode().getElementType();
    if (HANDLER_DEFINITIONS.contains(elementType)) {
      return currentScope;
    }
    currentScope = currentScope.getContext();
  }
  return null;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:13,代碼來源:AppleScriptComponentScopeResolver.java

示例5: isInsideHandlerDefinition

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
private boolean isInsideHandlerDefinition(PsiElement context) {
  while (context != null) {
    IElementType elementType = context.getNode().getElementType();
    if (HANDLER_DEFINITIONS.contains(elementType)) {
      return true;
    }
    context = context.getContext();
  }
  return false;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:11,代碼來源:AppleScriptComponentScopeResolver.java

示例6: findDeclarationsAt

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public void findDeclarationsAt(@NotNull PsiElement element, int offsetInElement, Consumer<PomTarget> consumer) {
  if (element instanceof AppleScriptSelectorId) {
    AppleScriptHandlerInterleavedParameters handler;
    final PsiElement contextElement = element.getContext() != null ? element.getContext().getContext() : null;
    if (contextElement instanceof AppleScriptHandlerInterleavedParameters) {
      handler = (AppleScriptHandlerInterleavedParameters) contextElement;
      consumer.consume(handler);
    }
  }
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:12,代碼來源:AppleScriptHandlerDeclarationSearcher.java

示例7: getUsageType

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Nullable
@Override
public UsageType getUsageType(PsiElement element) {
  if (!(element instanceof AppleScriptPsiElement)) return null;

  //todo make better psi
  if (element instanceof AppleScriptLabeledParameterDeclarationPart
          || element.getContext() instanceof AppleScriptFormalParameterList
          || element.getContext() instanceof AppleScriptHandlerInterleavedParametersSelectorPart) {
    return UsageType.CLASS_METHOD_PARAMETER_DECLARATION;
  }

  return null;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:15,代碼來源:AppleScriptUsageTypeProvider.java

示例8: processDeclarationsImpl

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static boolean processDeclarationsImpl(@Nullable PsiElement context, PsiScopeProcessor processor,
                                              ResolveState state, @Nullable PsiElement lastParent,
                                              @Nullable final PsiElement referencingElement) {
  if (context == null) {
    return true;
  }
  final PsiElement[] children = context.getChildren();
  final Set<AppleScriptPsiElement> result = new THashSet<>();
  for (PsiElement child : children) {
    if (child == lastParent && child instanceof AppleScriptBlockBody)//todo extract condition=>"stop at last parent"
      continue;

    //not components first
    if (child instanceof AppleScriptVarDeclarationList) {
      final AppleScriptVarDeclarationList varList = (AppleScriptVarDeclarationList) child;
      result.add(varList.getVarAccessDeclaration());
      result.addAll(varList.getVarDeclarationListPartList());
    } else if (child instanceof AppleScriptFormalParameterList) {
      AppleScriptFormalParameterList parameterList = (AppleScriptFormalParameterList) child;
      List<AppleScriptComponent> cmList = parameterList.getFormalParameters();
      if (!cmList.isEmpty()) {
        result.addAll(cmList);
      }
    } else if (child instanceof AppleScriptHandlerSelectorPart) {//todo to think if it make sense to make at as
      // todo component...
      AppleScriptHandlerSelectorPart parameterSelector = (AppleScriptHandlerSelectorPart) child;
      result.addAll(parameterSelector.findParameters());
    } else if (child instanceof AppleScriptLabeledParameterDeclarationList) {
      AppleScriptLabeledParameterDeclarationList params = (AppleScriptLabeledParameterDeclarationList) child;
      result.addAll(params.getComponentList());
    } else if (child instanceof AppleScriptObjectTargetPropertyDeclaration
        && (child.getContext() instanceof AppleScriptHandlerLabeledParametersDefinition//+ why not in handlers??
        || child.getContext() instanceof AppleScriptHandler)) {
      //this is in target list/record literals
      AppleScriptObjectTargetPropertyDeclaration prop = (AppleScriptObjectTargetPropertyDeclaration) child;
      AppleScriptTargetVariable var = prop.getTargetVariable();
      if (var != null) {
        result.add(var);
      }
    } else if (child instanceof AppleScriptAssignmentStatement) {
      AppleScriptAssignmentStatement assignmentStmt = (AppleScriptAssignmentStatement) child;
      result.addAll(assignmentStmt.getTargets());
    } else if (child instanceof AppleScriptComponent) {
      result.add((AppleScriptComponent) child);
    }
    //dictionary components
    else if (child instanceof AppleScriptUseStatement) { //is before is also checked lower
      AppleScriptUseStatement useStatement = (AppleScriptUseStatement) child;
      result.add(useStatement);
    }
  }
  //because of a scope of tell statements
  if (referencingElement != null) {
    if (context instanceof ApplicationDictionaryDeclarator && !(context instanceof AppleScriptUseStatement)) {
      result.add((ApplicationDictionaryDeclarator) context);
    }
  }

  for (AppleScriptPsiElement component : result) {
    if (referencingElement == null || canBeReferenced(referencingElement, component)) {//do not process
      if (!processor.execute(component, state)) {
        return false;
      }
    }
  }
  return true;
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:68,代碼來源:AppleScriptPsiElementImpl.java

示例9: addCompletions

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
    Stream<LookupElementBuilder> stream = null;
    PsiElement position = completionParameters.getPosition();

    // No completion on ordinary YAML files
    if (!isConfigFile(position)) {
        return;
    }

    // Completion for YAML keys
    if (isKey(position)) {
        stream = KEY_COMPLETION_PROVIDER.resolve(resolvePath(position), position)
                .map(prev -> LookupElementBuilder.create(prev.getLookupString() + ": ")
                        .withPresentableText(prev.getLookupString())
                );
    }
    // Completion for YAML values
    else if (isValue(position)) {
        YAMLScalar yamlScalar = (YAMLScalar) position.getContext();
        if (yamlScalar != null) {
            int cursorOffset = calculateCursorOffset(completionParameters, position, yamlScalar);
            List<MacroResolver.Match> matches = new MacroResolver().resolve(yamlScalar.getTextValue().substring(0, cursorOffset));
            if (!matches.isEmpty()) {
                MacroResolver.Match closestMatch = findClosestMatch(matches, cursorOffset);
                if (closestMatch != null) {
                    MacroInfo macroInfo = resolveMacroInfo(closestMatch, completionResultSet, cursorOffset);
                    completionResultSet = macroInfo.completionResultSet;
                    stream = KEY_COMPLETION_PROVIDER.resolve(macroInfo.path, position);
                }
            } else {
                stream = VALUE_COMPLETION_PROVIDER.resolve(resolvePath(position), position);
            }
        }
    }

    // Add lookup elements to completion results
    if (stream != null) {
        stream.forEach(completionResultSet::addElement);
    }
}
 
開發者ID:seedstack,項目名稱:intellij-plugin,代碼行數:42,代碼來源:CoffigCompletionContributor.java

示例10: isValue

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
private boolean isValue(PsiElement position) {
    return position != null && position.getContext() instanceof YAMLScalar;
}
 
開發者ID:seedstack,項目名稱:intellij-plugin,代碼行數:4,代碼來源:CoffigCompletionContributor.java


注:本文中的com.intellij.psi.PsiElement.getContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。