com.intellij.psi.search.EverythingGlobalScope Java Examples

The following examples show how to use com.intellij.psi.search.EverythingGlobalScope. 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: ApplyPatchWrapper.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
public void setSelectedPatch(Patch selectedPatch) {
	System.out.println(selectedPatch.asString() + " selected! ");
	this.selectedPatch = selectedPatch;
	final SourceLocation location = this.selectedPatch.getSourceLocation();
	PsiClass classToBeFix = JavaPsiFacade.getInstance(this.project).findClass(this.selectedPatch.getRootClassName(), new EverythingGlobalScope(this.project));
	classToBeFix.accept(new JavaRecursiveElementVisitor() {
		@Override
		public void visitStatement(PsiStatement statement) {
			if (location.getBeginSource() == statement.getTextOffset() &&
					location.getEndSource() == statement.getTextOffset() + statement.getTextLength() - 1) {
				buggyElement = statement;
			}
			super.visitStatement(statement);
		}
	});
}
 
Example #2
Source File: InjectWriter.java    From android-butterknife-zelezny with Apache License 2.0 6 votes vote down vote up
protected void generateInjects(@NotNull IButterKnife butterKnife) {
    PsiClass activityClass = JavaPsiFacade.getInstance(mProject).findClass(
            "android.app.Activity", new EverythingGlobalScope(mProject));
    PsiClass fragmentClass = JavaPsiFacade.getInstance(mProject).findClass(
            "android.app.Fragment", new EverythingGlobalScope(mProject));
    PsiClass supportFragmentClass = JavaPsiFacade.getInstance(mProject).findClass(
            "android.support.v4.app.Fragment", new EverythingGlobalScope(mProject));

    // Check for Activity class
    if (activityClass != null && mClass.isInheritor(activityClass, true)) {
        generateActivityBind(butterKnife);
    // Check for Fragment class
    } else if ((fragmentClass != null && mClass.isInheritor(fragmentClass, true)) || (supportFragmentClass != null && mClass.isInheritor(supportFragmentClass, true))) {
        generateFragmentBindAndUnbind(butterKnife);
    }
}
 
Example #3
Source File: ExcludeBuildFilesScope.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public GlobalSearchScope getScopeToExclude(PsiElement element) {
  if (!enabled.getValue()) {
    return null;
  }
  if (element instanceof PsiFileSystemItem) {
    return GlobalSearchScope.getScopeRestrictedByFileTypes(
        new EverythingGlobalScope(), BuildFileType.INSTANCE);
  }
  return null;
}
 
Example #4
Source File: Utils.java    From android-butterknife-zelezny with Apache License 2.0 5 votes vote down vote up
private static PsiFile resolveLayoutResourceFile(PsiElement element, Project project, String name) {
    // restricting the search to the current module - searching the whole project could return wrong layouts
    Module module = ModuleUtil.findModuleForPsiElement(element);
    PsiFile[] files = null;
    if (module != null) {
        // first omit libraries, it might cause issues like (#103)
        GlobalSearchScope moduleScope = module.getModuleWithDependenciesScope();
        files = FilenameIndex.getFilesByName(project, name, moduleScope);
        if (files == null || files.length <= 0) {
            // now let's do a fallback including the libraries
            moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false);
            files = FilenameIndex.getFilesByName(project, name, moduleScope);
        }
    }
    if (files == null || files.length <= 0) {
        // fallback to search through the whole project
        // useful when the project is not properly configured - when the resource directory is not configured
        files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
        if (files.length <= 0) {
            return null; //no matching files
        }
    }

    // TODO - we have a problem here - we still can have multiple layouts (some coming from a dependency)
    // we need to resolve R class properly and find the proper layout for the R class
    for (PsiFile file : files) {
        log.info("Resolved layout resource file for name [" + name + "]: " + file.getVirtualFile());
    }
    return files[0];
}
 
Example #5
Source File: FindSymbolParameters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static GlobalSearchScope searchScopeFor(@Nullable Project project, boolean searchInLibraries) {
  GlobalSearchScope baseScope = project == null ? new EverythingGlobalScope() : searchInLibraries ? ProjectScope.getAllScope(project) : ProjectScope.getProjectScope(project);

  return baseScope.intersectWith(new EverythingGlobalScope(project) {
    @Override
    public boolean contains(@Nonnull VirtualFile file) {
      return !(file.getFileSystem() instanceof HiddenFileSystem);
    }
  });
}
 
Example #6
Source File: ApplyPatchAction.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	final Project project = this.parent.getProject();
	PsiElement buggyElement = this.parent.getBuggyElement();
	final Patch selectedPatch = this.parent.getSelectedPatch();

	PsiClass classToBeFix = JavaPsiFacade.getInstance(project).findClass(selectedPatch.getRootClassName(), new EverythingGlobalScope(project));
	OpenFileDescriptor descriptor = new OpenFileDescriptor(project, classToBeFix.getContainingFile().getVirtualFile(), buggyElement.getTextOffset());
	Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
	Document modifiedDocument = editor.getDocument();

	final String patch;

	if (selectedPatch.getType() == RepairType.CONDITIONAL) {
		buggyElement = ((PsiIfStatement) buggyElement).getCondition();
		patch = selectedPatch.asString();
	} else {
		String newline = FileDocumentManager.getInstance().getFile(modifiedDocument).getDetectedLineSeparator();
		StringBuilder sb = new StringBuilder();
		sb.append("if( ");
		sb.append(selectedPatch.asString());
		sb.append(" ) {" + newline);
		sb.append(buggyElement.getText() + newline);
		sb.append("}");
		patch = sb.toString();
	}

	final PsiElement finalBuggyElement = buggyElement;

	CommandProcessor.getInstance().executeCommand(project, () -> WriteCommandAction.runWriteCommandAction(project, () -> {
		//Apply the patch
		modifiedDocument.replaceString(finalBuggyElement.getTextOffset(), finalBuggyElement.getTextOffset() + finalBuggyElement.getTextLength(), patch);
		//Move caret to modification
		editor.getCaretModel().moveToOffset(finalBuggyElement.getTextOffset());
		//Select patch
		editor.getSelectionModel().setSelection(finalBuggyElement.getTextOffset(), finalBuggyElement.getTextOffset() +
				(selectedPatch.getType() == RepairType.CONDITIONAL ? finalBuggyElement.getTextLength() : patch.length()));
		PsiDocumentManager.getInstance(project).commitDocument(modifiedDocument);
		CodeStyleManager.getInstance(project).reformat(PsiDocumentManager.getInstance(project).getPsiFile(modifiedDocument), false);
	}), "Apply Patch", DocCommandGroupId.noneGroupId(modifiedDocument));

	PsiDocumentManager.getInstance(project).commitDocument(modifiedDocument);

	parent.close(0);
}
 
Example #7
Source File: PsiClassUtil.java    From GsonFormat with Apache License 2.0 4 votes vote down vote up
public static boolean isClassAvailableForProject(Project project, String className) {
    PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className,
            new EverythingGlobalScope(project));
    return classInModule != null;
}
 
Example #8
Source File: CSharpDirectTypeInheritorsSearcherExecutor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public boolean execute(@Nonnull final DirectTypeInheritorsSearch.SearchParameters p, @Nonnull final Processor<? super DotNetTypeDeclaration> consumer)
{
	String vmQName = p.getVmQName();

	/*if(DotNetTypes.System_Object.equals(qualifiedName))
	{
		final SearchScope scope = useScope;

		return AllClassesSearch.search(scope, aClass.getProject()).forEach(new Processor<DotNetTypeDeclaration>()
		{
			@Override
			public boolean process(final DotNetTypeDeclaration typeDcl)
			{
				if(typeDcl.isInterface())
				{
					return consumer.process(typeDcl);
				}
				final DotNetTypeDeclaration superClass = typeDcl.getSuperClass();
				if(superClass != null && DotNetTypes.System_Object.equals(ApplicationManager.getApplication().runReadAction(
						new Computable<String>()
				{
					public String compute()
					{
						return superClass.getPresentableQName();
					}
				})))
				{
					return consumer.process(typeDcl);
				}
				return true;
			}
		});
	}  */

	SearchScope useScope = p.getScope();
	final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope) useScope : new EverythingGlobalScope(p
			.getProject());
	final String searchKey = MsilHelper.cutGenericMarker(StringUtil.getShortName(vmQName));

	if(StringUtil.isEmpty(searchKey))
	{
		return true;
	}

	Collection<DotNetTypeList> candidates = ApplicationManager.getApplication().runReadAction((Computable<Collection<DotNetTypeList>>) () -> ExtendsListIndex.getInstance().get(searchKey, p.getProject(), scope));

	Map<String, List<DotNetTypeDeclaration>> classes = new HashMap<>();

	for(DotNetTypeList referenceList : candidates)
	{
		ProgressIndicatorProvider.checkCanceled();
		final DotNetTypeDeclaration candidate = ReadAction.compute(() -> (DotNetTypeDeclaration) referenceList.getParent());
		if(!checkInheritance(p, vmQName, candidate))
		{
			continue;
		}

		String fqn = ReadAction.compute(candidate::getPresentableQName);
		List<DotNetTypeDeclaration> list = classes.get(fqn);
		if(list == null)
		{
			list = new ArrayList<>();
			classes.put(fqn, list);
		}
		list.add(candidate);
	}

	for(List<DotNetTypeDeclaration> sameNamedClasses : classes.values())
	{
		for(DotNetTypeDeclaration sameNamedClass : sameNamedClasses)
		{
			if(!consumer.process(sameNamedClass))
			{
				return false;
			}
		}
	}

	return true;
}
 
Example #9
Source File: CoreProjectScopeBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public GlobalSearchScope buildEverythingScope() {
  return new EverythingGlobalScope(myProject);
}
 
Example #10
Source File: CoreProjectScopeBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public GlobalSearchScope buildAllScope() {
  return new EverythingGlobalScope();
}
 
Example #11
Source File: FileBasedIndexImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public <K> boolean processAllKeys(@Nonnull final ID<K, ?> indexId, @Nonnull Processor<? super K> processor, @Nullable Project project) {
  return processAllKeys(indexId, processor, project == null ? new EverythingGlobalScope() : GlobalSearchScope.allScope(project), null);
}
 
Example #12
Source File: Utils.java    From OkHttpParamsGet with Apache License 2.0 2 votes vote down vote up
/**
 * Check whether classpath of a the whole project contains given class.
 * This is only fallback for wrongly setup projects.
 *
 * @param project   Project
 * @param className Class name of the searched class
 * @return True if the class is present on the classpath
 * @since 1.3.1
 */
public static boolean isClassAvailableForProject(@NotNull Project project, @NotNull String className) {
    PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className,
            new EverythingGlobalScope(project));
    return classInModule != null;
}
 
Example #13
Source File: Utils.java    From android-butterknife-zelezny with Apache License 2.0 2 votes vote down vote up
/**
 * Check whether classpath of a the whole project contains given class.
 * This is only fallback for wrongly setup projects.
 *
 * @param project   Project
 * @param className Class name of the searched class
 * @return True if the class is present on the classpath
 * @since 1.3.1
 */
public static boolean isClassAvailableForProject(@NotNull Project project, @NotNull String className) {
    PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className,
            new EverythingGlobalScope(project));
    return classInModule != null;
}