use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class AppEngineForbiddenCodeInspection method checkFile.
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
final Project project = manager.getProject();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
final AppEngineFacet appEngineFacet = AppEngineFacet.getAppEngineFacetByModule(module);
if (appEngineFacet == null) {
return null;
}
final AppEngineSdk appEngineSdk = appEngineFacet.getSdk();
if (!appEngineSdk.isValid()) {
return null;
}
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final List<ProblemDescriptor> problems = new ArrayList<>();
file.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitDocComment(PsiDocComment comment) {
}
@Override
public void visitMethod(PsiMethod method) {
final PsiModifierList modifierList = method.getModifierList();
if (modifierList.hasModifierProperty(PsiModifier.NATIVE)) {
if (!isNativeMethodAllowed(method)) {
problems.add(manager.createProblemDescriptor(modifierList, "Native methods aren't allowed in App Engine application", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
super.visitMethod(method);
}
@Override
public void visitNewExpression(PsiNewExpression expression) {
final PsiJavaCodeReferenceElement classReference = expression.getClassReference();
if (classReference != null) {
final PsiElement resolved = classReference.resolve();
if (resolved instanceof PsiClass) {
final String qualifiedName = ((PsiClass) resolved).getQualifiedName();
if (qualifiedName != null && appEngineSdk.isMethodInBlacklist(qualifiedName, "new")) {
final String message = "App Engine application should not create new instances of '" + qualifiedName + "' class";
problems.add(manager.createProblemDescriptor(classReference, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
super.visitNewExpression(expression);
}
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiElement element = methodExpression.resolve();
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final PsiClass psiClass = method.getContainingClass();
if (psiClass != null) {
final String qualifiedName = psiClass.getQualifiedName();
final String methodName = method.getName();
if (qualifiedName != null && appEngineSdk.isMethodInBlacklist(qualifiedName, methodName)) {
final String message = "AppEngine application should not call '" + StringUtil.getShortName(qualifiedName) + "." + methodName + "' method";
problems.add(manager.createProblemDescriptor(methodExpression, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
super.visitMethodCallExpression(expression);
}
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
final PsiElement resolved = reference.resolve();
if (resolved instanceof PsiClass) {
final PsiFile psiFile = resolved.getContainingFile();
if (psiFile != null) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null && !fileIndex.isInSource(virtualFile)) {
final List<OrderEntry> list = fileIndex.getOrderEntriesForFile(virtualFile);
for (OrderEntry entry : list) {
if (entry instanceof JdkOrderEntry) {
final String className = ClassUtil.getJVMClassName((PsiClass) resolved);
if (className != null && !appEngineSdk.isClassInWhiteList(className)) {
problems.add(manager.createProblemDescriptor(reference, "Class '" + className + "' is not included in App Engine JRE White List", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
}
}
}
super.visitReferenceElement(reference);
}
});
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class GradleScriptType method patchResolveScopeInner.
public GlobalSearchScope patchResolveScopeInner(@Nullable Module module, @NotNull GlobalSearchScope baseScope) {
if (module == null)
return GlobalSearchScope.EMPTY_SCOPE;
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
return baseScope;
GlobalSearchScope result = GlobalSearchScope.EMPTY_SCOPE;
final Project project = module.getProject();
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof JdkOrderEntry) {
GlobalSearchScope scopeForSdk = LibraryScopeCache.getInstance(project).getScopeForSdk((JdkOrderEntry) entry);
result = result.uniteWith(scopeForSdk);
}
}
String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (modulePath == null)
return result;
final Collection<VirtualFile> files = GradleBuildClasspathManager.getInstance(project).getModuleClasspathEntries(modulePath);
result = new ExternalModuleBuildGlobalSearchScope(project, result.uniteWith(new NonClasspathDirectoriesScope(files)), modulePath);
return result;
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class ClasspathTableModel method init.
public void init() {
final OrderEntry[] orderEntries = getModel().getOrderEntries();
boolean hasJdkOrderEntry = false;
List<ClasspathTableItem<?>> items = new ArrayList<>();
for (final OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
hasJdkOrderEntry = true;
}
items.add(ClasspathTableItem.createItem(orderEntry, myContext));
}
if (!hasJdkOrderEntry) {
items.add(0, new InvalidJdkItem());
}
setItems(items);
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class DvcsUtil method getVcsRootForLibraryFile.
@Nullable
private static VirtualFile getVcsRootForLibraryFile(@NotNull Project project, @NotNull VirtualFile file) {
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
// for a file inside .jar/.zip consider the .jar/.zip file itself
VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
if (root != null) {
LOGGER.debug("Found root for zip/jar file: " + root);
return root;
}
// for other libs which don't have jars inside the project dir (such as JDK) take the owner module of the lib
List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
Set<VirtualFile> libraryRoots = new HashSet<>();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
if (moduleRoot != null) {
libraryRoots.add(moduleRoot);
}
}
}
if (libraryRoots.size() == 0) {
LOGGER.debug("No library roots");
return null;
}
// if the lib is used in several modules, take the top module
// (for modules of the same level we can't guess anything => take the first one)
Iterator<VirtualFile> libIterator = libraryRoots.iterator();
VirtualFile topLibraryRoot = libIterator.next();
while (libIterator.hasNext()) {
VirtualFile libRoot = libIterator.next();
if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
topLibraryRoot = libRoot;
}
}
LOGGER.debug("Several library roots, returning " + topLibraryRoot);
return topLibraryRoot;
}
use of com.intellij.openapi.roots.JdkOrderEntry in project android by JetBrains.
the class AndroidTreeStructureProvider method modify.
@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
Project project = parent.getProject();
if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
if (parent instanceof NamedLibraryElementNode) {
NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
if (orderEntry instanceof JdkOrderEntry) {
Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (sdk.getSdkType() instanceof JavaSdk) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (isRtJar(child)) {
newChildren.add(child);
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
} else if (isRtJar(parent)) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (child instanceof PsiDirectoryNode) {
VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
newChildren.add(child);
}
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
return children;
}
Aggregations