com.intellij.util.ProcessingContext Java Examples

The following examples show how to use com.intellij.util.ProcessingContext. 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: LatexReferenceContributor.java    From idea-latex with MIT License 6 votes vote down vote up
/**
 * Returns references for given @{link PsiElement}.
 *
 * @param psiElement        current element
 * @param processingContext context
 * @return {@link PsiReference} list
 */
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
    if (psiElement instanceof LatexInstruction) {
        LatexInstructionExtImpl instruction = (LatexInstructionExtImpl) psiElement;
        String identifier = instruction.getIdentifier().getText();
        if (Arrays.asList(IDENTIFIERS).contains(identifier)) {
            LatexArgument arg = instruction.getArgument();
            if (arg != null && arg.getValue() != null) {
                return new FileReferenceSet(arg.getValue(), instruction, arg.getStartOffsetInParent() + 1, this, true).getAllReferences();
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example #2
Source File: BuckIdentifierReferenceContributor.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {

  registrar.registerReferenceProvider(
      PlatformPatterns.psiElement(BuckIdentifier.class),
      new PsiReferenceProvider() {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(
            @NotNull PsiElement element, @NotNull ProcessingContext context) {
          if (element instanceof BuckIdentifier) {
            BuckIdentifier identifier = (BuckIdentifier) element;
            return new PsiReference[] {new BuckIdentifierReference(identifier)};
          } else {
            return new PsiReference[0];
          }
        }
      });
}
 
Example #3
Source File: TwigTemplateCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
        return;
    }

    // move this stuff to pattern fixed event stopping by phpstorm
    PsiElement currElement = parameters.getPosition().getOriginalElement();
    PsiElement prevElement = currElement.getPrevSibling();
    if ((prevElement != null) && ((prevElement instanceof PsiWhiteSpace))) prevElement = prevElement.getPrevSibling();

    if ((prevElement != null) && (prevElement.getNode().getElementType() == TwigTokenTypes.FILTER)) {
        for(Map.Entry<String, TwigExtension> entry : TwigExtensionParser.getFilters(parameters.getPosition().getProject()).entrySet()) {
            resultSet.addElement(new TwigExtensionLookupElement(currElement.getProject(), entry.getKey(), entry.getValue()));
        }
    }
}
 
Example #4
Source File: StepCompletionProvider.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    resultSet.stopHere();
    final String prefix = getPrefix(parameters);

    resultSet = resultSet.withPrefixMatcher(new GaugePrefixMatcher(prefix));
    Module moduleForPsiElement = GaugeUtil.moduleForPsiElement(parameters.getPosition());
    if (moduleForPsiElement == null) {
        return;
    }
    for (Type item : getStepsInModule(moduleForPsiElement)) {
        LookupElementBuilder element = LookupElementBuilder.create(item.getText()).withTypeText(item.getType(), true);
        element = element.withInsertHandler((InsertionContext context1, LookupElement item1) -> {
            if (context1.getCompletionChar() == '\t') {
                context1.getDocument().insertString(context1.getEditor().getCaretModel().getOffset(), "\n");
                PsiDocumentManager.getInstance(context1.getProject()).commitDocument(context1.getDocument());
            }
            PsiElement stepElement = context1.getFile().findElementAt(context1.getStartOffset()).getParent();
            final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(stepElement);
            replaceStepParamElements(prefix, context1, stepElement, templateBuilder);
            templateBuilder.run(context1.getEditor(), false);
        });
        resultSet.addElement(element);
    }
}
 
Example #5
Source File: RenameInputValidatorRegistry.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public static Function<String, String> getInputErrorValidator(final PsiElement element) {
  for(final RenameInputValidator validator: Extensions.getExtensions(RenameInputValidator.EP_NAME)) {
    if (!(validator instanceof RenameInputValidatorEx)) continue;
    final ProcessingContext context = new ProcessingContext();
    if (validator.getPattern().accepts(element, context)) {
      return new Function<String, String>() {
        @Override
        public String fun(String newName) {
          return ((RenameInputValidatorEx)validator).getErrorMessage(newName, element.getProject());
        }
      };
    }
  }
  return null;
}
 
Example #6
Source File: CamelPropertyPlaceholderSmartCompletionExtension.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
    Project project = parameters.getOriginalFile().getManager().getProject();

    List<VirtualFile> resourceRoots = ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
    resourceRoots.addAll(ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.TESTS));
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (final VirtualFile sourceRoot : resourceRoots) {
        if (sourceRoot.isValid() && sourceRoot.getCanonicalFile() != null) {
            VfsUtil.processFilesRecursively(sourceRoot.getCanonicalFile(), virtualFile -> {
                propertyCompletionProviders.stream()
                    .filter(p -> p.isValidExtension(virtualFile.getCanonicalPath()) && !projectFileIndex.isExcluded(sourceRoot))
                    .forEach(p -> p.buildResultSet(resultSet, virtualFile));
                return true;
            });
        }
    }
}
 
Example #7
Source File: PsiElementPattern.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Self afterLeafSkipping(@Nonnull final ElementPattern skip, @Nonnull final ElementPattern pattern) {
  return with(new PatternCondition<T>("afterLeafSkipping") {
    @Override
    public boolean accepts(@Nonnull T t, final ProcessingContext context) {
      PsiElement element = t;
      while (true) {
        element = PsiTreeUtil.prevLeaf(element);
        if (element != null && element.getTextLength() == 0) {
          continue;
        }

        if (!skip.getCondition().accepts(element, context)) {
          return pattern.getCondition().accepts(element, context);
        }
      }
    }

  });
}
 
Example #8
Source File: LiftShorterItemsClassifier.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addElement(@Nonnull LookupElement added, @Nonnull ProcessingContext context) {
  myCount++;

  for (String string : CompletionUtil.iterateLookupStrings(added)) {
    if (string.length() == 0) continue;

    myElements.putValue(string, added);
    mySortedStrings.add(string);
    final NavigableSet<String> after = mySortedStrings.tailSet(string, false);
    for (String s : after) {
      if (!s.startsWith(string)) {
        break;
      }
      for (LookupElement longer : myElements.get(s)) {
        updateLongerItem(added, longer);
      }
    }
  }
  super.addElement(added, context);

  calculateToLift(added);
}
 
Example #9
Source File: RequirejsPsiReferenceProvider.java    From WebStormRequireJsPlugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
    RequirejsProjectComponent projectComponent = psiElement.getProject().getComponent(RequirejsProjectComponent.class);

    if (!projectComponent.isEnabled()) {
        return PsiReference.EMPTY_ARRAY;
    }

    String path = psiElement.getText();
    if (isRequireCall(psiElement) || isDefineFirstCollection(psiElement)) {
        PsiReference ref = new RequirejsReference(psiElement, new TextRange(1, path.length() - 1));
        return new PsiReference[] {ref};
    }

    return new PsiReference[0];
}
 
Example #10
Source File: AnnotationPropertyValueReferenceContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
    PhpClass phpClass = getValidAnnotationClass(psiElement);
    if(phpClass == null) {
        return new PsiReference[0];
    }

    PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(psiElement, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER));
    if(propertyName == null) {
        return new PsiReference[0];
    }

    AnnotationPropertyParameter annotationPropertyParameter = new AnnotationPropertyParameter(psiElement, phpClass, propertyName.getText(), AnnotationPropertyParameter.Type.PROPERTY_VALUE);
    return addPsiReferences(psiElement, processingContext, annotationPropertyParameter);

}
 
Example #11
Source File: CamelJavaBeanReferenceSmartCompletion.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
    final PsiElement element = completionParameters.getPosition();
    final PsiClass psiClass = getCamelIdeaUtils().getBean(element);

    if (psiClass != null) {
        Collection<PsiMethod> methods = getJavaMethodUtils().getMethods(psiClass);

        List<LookupElement> answer = getJavaMethodUtils().getBeanAccessibleMethods(methods)
            .stream()
            .map(method -> buildLookupElement(method, getJavaMethodUtils().getPresentableMethodWithParameters(method)))
            .collect(toList());

        // are there any results then add them
        if (!answer.isEmpty()) {
            String hackVal = element.getText();
            hackVal = hackVal.substring(1, hackVal.indexOf(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED));
            completionResultSet.withPrefixMatcher(hackVal).addAllElements(answer);
            completionResultSet.stopHere();
        }
    }
}
 
Example #12
Source File: SimpleCompletionExtension.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context,
                    @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
    PsiElement element = parameters.getPosition();
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
        return;
    }

    List<LookupElement> results = findResults(element, getQueryAtPosition(query));
    if (!results.isEmpty()) {
        resultSet
            .withRelevanceSorter(CompletionSorter.emptySorter())
            .addAllElements(results);
        resultSet.stopHere();
    }
}
 
Example #13
Source File: WorkspaceTypeCompletionContributor.java    From intellij with Apache License 2.0 6 votes vote down vote up
public WorkspaceTypeCompletionContributor() {
  extend(
      CompletionType.BASIC,
      psiElement()
          .withLanguage(ProjectViewLanguage.INSTANCE)
          .inside(ProjectViewPsiScalarSection.class)
          .afterLeaf(psiElement().withText(":").afterLeaf(WorkspaceTypeSection.KEY.getName())),
      new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(
            CompletionParameters parameters,
            ProcessingContext context,
            CompletionResultSet result) {
          for (WorkspaceType type : WorkspaceType.values()) {
            result.addElement(LookupElementBuilder.create(type.getName()));
          }
        }
      });
}
 
Example #14
Source File: AssetCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet resultSet) {
    Project project = parameters.getPosition().getProject();

    if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
        return;
    }

    for (AssetFile assetFile : assetParser.getAssetFiles(project)) {
        resultSet.addElement(new AssetLookupElement(assetFile, project));
    }

    if(includeCustom) {
        TwigNamedAssetsServiceParser twigPathServiceParser = ServiceXmlParserFactory.getInstance(project, TwigNamedAssetsServiceParser.class);
        for (String s : twigPathServiceParser.getNamedAssets().keySet()) {
            resultSet.addElement(LookupElementBuilder.create("@" + s).withIcon(PlatformIcons.FOLDER_ICON).withTypeText("Custom Assets", true));
        }
    }
}
 
Example #15
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public boolean accepts(@NotNull PsiFile psiFile, ProcessingContext processingContext) {
    if (psiFile.getFileType() != YAMLFileType.YML) {
        return false;
    }

    if (psiFile.getName().matches("(security|config).*\\.(yml|yaml)")) {
        return true;
    }

    // psiFile.virtualFile is empty; check via folder structure
    PsiDirectory containingDirectory = psiFile.getContainingDirectory();
    if (containingDirectory == null) {
        return false;
    }

    if ("packages".equals(containingDirectory.getName())) {
        return true;
    }

    VirtualFile virtualDirectoryFile = containingDirectory.getVirtualFile();

    String relativePath = VfsExUtil.getRelativeProjectPath(psiFile.getProject(), virtualDirectoryFile);
    return relativePath != null && relativePath.contains("config/packages/");
}
 
Example #16
Source File: ShaderLabCGCompletionContributor.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
public ShaderLabCGCompletionContributor()
{
	extend(CompletionType.BASIC, StandardPatterns.psiElement().withLanguage(CGLanguage.INSTANCE), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull final CompletionResultSet result)
		{
			Place shreds = InjectedLanguageUtil.getShreds(parameters.getOriginalFile());

			for(PsiLanguageInjectionHost.Shred shred : shreds)
			{
				PsiLanguageInjectionHost host = shred.getHost();
				if(host instanceof ShaderCGScript)
				{
					ShaderLabFile containingFile = (ShaderLabFile) host.getContainingFile();
					ShaderReference.consumeProperties(containingFile, result::addElement);
				}
			}
		}
	});
}
 
Example #17
Source File: TranslationReferenceContributor.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(StringLiteralExpression.class), new PsiReferenceProvider() {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            if (!(element instanceof StringLiteralExpression)) {
                return PsiReference.EMPTY_ARRAY;
            }

            StringLiteralExpression stringLiteralExpression = (StringLiteralExpression) element;
            if (!stringLiteralExpression.getContents().startsWith("LLL:")) {
                return PsiReference.EMPTY_ARRAY;
            }

            return new PsiReference[]{new TranslationReference(stringLiteralExpression)};
        }
    });
}
 
Example #18
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
	if (!(element instanceof SQFVariable)) {
		return PsiReference.EMPTY_ARRAY; //can't be referenced
	}
	SQFVariable var = (SQFVariable) element;

	if (var.isLocal()) {
		return PsiReference.EMPTY_ARRAY;
	}
	List<SQFVariable> vars = findGlobalVariables(element.getProject(), var);
	if (vars.isEmpty()) {
		return PsiReference.EMPTY_ARRAY;
	}
	return new PsiReference[]{new SQFVariableReference.IdentifierReference(var, vars)};
}
 
Example #19
Source File: EelProvider.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    Project project = parameters.getPosition().getProject();
    Collection<String> contexts = FileBasedIndex.getInstance().getAllKeys(DefaultContextFileIndex.KEY, project);

    for (String eelHelper : contexts) {
        List<String> helpers = FileBasedIndex.getInstance().getValues(DefaultContextFileIndex.KEY, eelHelper, GlobalSearchScope.allScope(project));
        if (!helpers.isEmpty()) {
            for (String helper : helpers) {
                Collection<PhpClass> classes = PhpIndex.getInstance(project).getClassesByFQN(helper);
                for (PhpClass phpClass : classes) {
                    for (Method method : phpClass.getMethods()) {
                        if (!method.getAccess().isPublic()) {
                            continue;
                        }
                        if (method.getName().equals("allowsCallOfMethod")) {
                            continue;
                        }
                        String completionText = eelHelper + "." + method.getName() + "()";
                        result.addElement(LookupElementBuilder.create(completionText).withIcon(PhpIcons.METHOD_ICON));
                    }
                }
            }
        }
    }
}
 
Example #20
Source File: PhpEntityClassCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {

        if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
            return;
        }

        PhpIndex phpIndex = PhpIndex.getInstance(parameters.getOriginalFile().getProject());
        Map<String, String> entityNamespaces = ServiceXmlParserFactory.getInstance(parameters.getOriginalFile().getProject(), EntityNamesServiceParser.class).getEntityNameMap();

        // copied from PhpCompletionUtil::addClassesInNamespace looks the official way to find classes in namespaces
        // its a really performance nightmare

        Collection<String> names = phpIndex.getAllClassNames(new CamelHumpMatcher(resultSet.getPrefixMatcher().getPrefix()));
        for (String name : names) {
            Collection<PhpClass> classes = phpIndex.getClassesByName(name);

            for(Map.Entry<String, String> entry: entityNamespaces.entrySet()) {
                String namespaceFqn = PhpLangUtil.toFQN(entry.getValue());
                Collection<PhpClass> filtered = PhpCompletionUtil.filterByNamespace(classes, namespaceFqn);
                for (PhpClass phpClass : filtered) {
                    resultSet.addElement(new PhpClassLookupElement(phpClass, true, PhpClassReferenceInsertHandler.getInstance()));
                }
            }
        }
    }
 
Example #21
Source File: XmlReferenceContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement instanceof XmlAttributeValue)) {
        return new PsiReference[0];
    }

    String method = ((XmlAttributeValue) psiElement).getValue();
    if(StringUtils.isBlank(method)) {
        return new PsiReference[0];
    }

    PhpClass phpClass = XmlHelper.getPhpClassForServiceFactory((XmlAttributeValue) psiElement);
    if(phpClass == null) {
        return new PsiReference[0];
    }

    Method targetMethod = phpClass.findMethodByName(method);
    if(targetMethod == null) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new ClassMethodStringPsiReference(psiElement, phpClass.getFQN(), targetMethod.getName()),
    };
}
 
Example #22
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
private void completeFieldArgumentTypeName() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {

            final PsiElement completionElement = parameters.getPosition();
            final TypeDefinitionRegistry registry = GraphQLTypeDefinitionRegistryServiceImpl.getService(completionElement.getProject()).getRegistry(parameters.getOriginalFile());
            addInputTypeCompletions(result, registry);
        }
    };
    extend(CompletionType.BASIC,
            psiElement(GraphQLElementTypes.NAME).afterLeafSkipping(
                    // skip
                    PlatformPatterns.or(psiComment(), psiElement(TokenType.WHITE_SPACE), psiElement().withText("[")),
                    // until argument type colon occurs
                    psiElement().withText(":")
            ).inside(GraphQLInputValueDefinition.class), provider);
}
 
Example #23
Source File: CollectionPattern.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CollectionPattern<T> atLeast(final int size) {
  return with(new PatternCondition<Collection<T>>("atLeast") {
    public boolean accepts(@Nonnull final Collection<T> ts, final ProcessingContext context) {
      return ts.size() >= size;
    }
  });
}
 
Example #24
Source File: CustomFileTypeCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CustomFileTypeCompletionContributor() {
  extend(CompletionType.BASIC, psiElement().inFile(psiFile().withFileType(instanceOf(CustomSyntaxTableFileType.class))), new CompletionProvider() {
    @RequiredReadAction
    @Override
    public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result) {
      if (inCommentOrLiteral(parameters)) {
        return;
      }

      FileType fileType = parameters.getOriginalFile().getFileType();
      if (!(fileType instanceof CustomSyntaxTableFileType)) {
        return;
      }

      SyntaxTable syntaxTable = ((CustomSyntaxTableFileType)fileType).getSyntaxTable();
      String prefix = findPrefix(parameters.getPosition(), parameters.getOffset());
      CompletionResultSet resultSetWithPrefix = result.withPrefixMatcher(prefix);

      addVariants(resultSetWithPrefix, syntaxTable.getKeywords1());
      addVariants(resultSetWithPrefix, syntaxTable.getKeywords2());
      addVariants(resultSetWithPrefix, syntaxTable.getKeywords3());
      addVariants(resultSetWithPrefix, syntaxTable.getKeywords4());

      WordCompletionContributor.addWordCompletionVariants(resultSetWithPrefix, parameters, Collections.<String>emptySet());
    }
  });
}
 
Example #25
Source File: TwigTemplateCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext paramProcessingContext, @NotNull CompletionResultSet resultSet) {
    PsiElement psiElement = parameters.getOriginalPosition();
    if(psiElement == null || !Symfony2ProjectComponent.isEnabled(psiElement)) {
        return;
    }

    Collection<String> possibleTypes = TwigTypeResolveUtil.formatPsiTypeName(psiElement);

    // find core function for that
    for(TwigTypeContainer twigTypeContainer: TwigTypeResolveUtil.resolveTwigMethodName(psiElement, possibleTypes)) {
        if(twigTypeContainer.getPhpNamedElement() instanceof PhpClass) {

            for(Method method: ((PhpClass) twigTypeContainer.getPhpNamedElement()).getMethods()) {
                if(!(!method.getModifier().isPublic() || method.getName().startsWith("set") || method.getName().startsWith("__"))) {
                    resultSet.addElement(new PhpTwigMethodLookupElement(method));
                }
            }

            for(Field field: ((PhpClass) twigTypeContainer.getPhpNamedElement()).getFields()) {
                if(field.getModifier().isPublic()) {
                    resultSet.addElement(new PhpTwigMethodLookupElement(field));
                }
            }
        }

        if(twigTypeContainer.getStringElement() != null) {
            resultSet.addElement(LookupElementBuilder.create(twigTypeContainer.getStringElement()));
        }
    }
}
 
Example #26
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private void completeImpementsKeyword() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
            final PsiElement completionElement = parameters.getPosition();
            final GraphQLTypeSystemDefinition typeDefinition = PsiTreeUtil.getParentOfType(completionElement, GraphQLObjectTypeDefinition.class, GraphQLObjectTypeExtensionDefinition.class, GraphQLInterfaceTypeDefinition.class, GraphQLInterfaceTypeExtensionDefinition.class);
            if (typeDefinition instanceof GraphQLObjectTypeDefinition && ((GraphQLObjectTypeDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLObjectTypeExtensionDefinition && ((GraphQLObjectTypeExtensionDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLInterfaceTypeDefinition && ((GraphQLInterfaceTypeDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLInterfaceTypeExtensionDefinition && ((GraphQLInterfaceTypeExtensionDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            result.addElement(LookupElementBuilder.create("implements").withBoldness(true).withInsertHandler(AddSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP));
        }
    };
    final ElementPattern<PsiElement> insideTypeDefElement = PlatformPatterns.or(
            psiElement().inside(GraphQLObjectTypeDefinition.class),
            psiElement().inside(GraphQLObjectTypeExtensionDefinition.class),
            psiElement().inside(GraphQLInterfaceTypeDefinition.class),
            psiElement().inside(GraphQLInterfaceTypeExtensionDefinition.class)
    );
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).afterLeaf(psiElement(GraphQLElementTypes.NAME).inside(insideTypeDefElement)), provider);
}
 
Example #27
Source File: CamelPsiReferenceProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (!ServiceManager.getService(element.getProject(), CamelService.class).isCamelPresent()) {
        return PsiReference.EMPTY_ARRAY;
    } else {
        return getCamelReferencesByElement(element, context);
    }
}
 
Example #28
Source File: YamlCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {

            if(!YamlHelper.isRoutingFile(parameters.getOriginalFile())) {
                return;
            }

            super.addCompletions(parameters, context, resultSet);
        }
 
Example #29
Source File: CharPattern.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CharPattern javaIdentifierStart() {
  return with(new PatternCondition<Character>("javaIdentifierStart") {
    @Override
    public boolean accepts(@Nonnull final Character character, final ProcessingContext context) {
      return Character.isJavaIdentifierStart(character.charValue());
    }
  });
}
 
Example #30
Source File: SQFDocTagsCompletionProvider.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
	try {
		doAddCompletions(parameters, context, result);
	} catch (Exception ignore) {

	}
}