mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
@SystemDependent / @SystemIndependent path annotations, #IDEA-173344 fixed
This commit is contained in:
@@ -18,6 +18,8 @@ package com.intellij.openapi.project;
|
||||
import com.intellij.openapi.components.ComponentManager;
|
||||
import com.intellij.openapi.extensions.AreaInstance;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.SystemDependent;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -52,12 +54,13 @@ public interface Project extends ComponentManager, AreaInstance {
|
||||
VirtualFile getBaseDir();
|
||||
|
||||
/**
|
||||
* Returns a system-independent path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
|
||||
* Returns a path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
|
||||
* Returns {@code null} for default project.
|
||||
*
|
||||
* @return a path to a project base directory, or {@code null} for default project
|
||||
*/
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
String getBasePath();
|
||||
|
||||
/**
|
||||
@@ -74,9 +77,10 @@ public interface Project extends ComponentManager, AreaInstance {
|
||||
VirtualFile getProjectFile();
|
||||
|
||||
/**
|
||||
* @return a system-independent path to project file (see {@linkplain #getProjectFile()}) or {@code null} for default project.
|
||||
* @return a path to project file (see {@linkplain #getProjectFile()}) or {@code null} for default project.
|
||||
*/
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
String getProjectFilePath();
|
||||
|
||||
/**
|
||||
@@ -88,6 +92,7 @@ public interface Project extends ComponentManager, AreaInstance {
|
||||
* @return presentable project path
|
||||
*/
|
||||
@Nullable
|
||||
@SystemDependent
|
||||
default String getPresentableUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,21 @@ public class PathUtil {
|
||||
return path == null ? null : FileUtilRt.toSystemDependentName(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure that the given path is system-independent (with <code>/</code> separators).
|
||||
*
|
||||
* @param path Path
|
||||
* @throws IllegalArgumentException
|
||||
* @see SystemDependent
|
||||
* @see SystemIndependent
|
||||
*/
|
||||
public static void assertSystemIndependentName(@Nullable String path) {
|
||||
// A simplified check that test only for a drive letter (to improve the performance and avoid possible false-negatives).
|
||||
if (path != null && path.length() > 3 && path.substring(1).startsWith(":\\")) {
|
||||
throw new IllegalArgumentException("System-dependent path: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String driveLetterToLowerCase(@NotNull String path) {
|
||||
if (SystemInfo.isWindows && path.length() >= 2 && Character.isUpperCase(path.charAt(0)) && path.charAt(1) == ':') {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Designates a system-dependent path, which can contain <code>\</code> separators.
|
||||
* <p>
|
||||
* This annotation doesn't add any bytecode instrumentation.
|
||||
*
|
||||
* @see PathUtil#toSystemIndependentName(String)
|
||||
* @see PathUtil#toSystemDependentName(String)
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface SystemDependent {
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Designates a system-independent path, with <code>/</code> separators.
|
||||
* <p>
|
||||
* This annotation doesn't add any bytecode instrumentation.<p>
|
||||
*
|
||||
* @see PathUtil#toSystemIndependentName(String)
|
||||
* @see PathUtil#toSystemDependentName(String)
|
||||
* @see PathUtil#assertSystemIndependentName(String)
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface SystemIndependent {
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.SystemDependent;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -89,6 +91,7 @@ public class MockProject extends MockComponentManager implements Project {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public String getProjectFilePath() {
|
||||
return null;
|
||||
}
|
||||
@@ -109,6 +112,7 @@ public class MockProject extends MockComponentManager implements Project {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -61,6 +62,7 @@ public class DummyProject extends UserDataHolderBase implements Project {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public String getProjectFilePath() {
|
||||
return null;
|
||||
}
|
||||
@@ -77,6 +79,7 @@ public class DummyProject extends UserDataHolderBase implements Project {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return null;
|
||||
|
||||
@@ -52,6 +52,9 @@ import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.impl.FrameTitleBuilder;
|
||||
import com.intellij.project.ProjectKt;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemDependent;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import com.intellij.util.TimedReference;
|
||||
import com.intellij.util.io.storage.HeavyProcessLatch;
|
||||
import com.intellij.util.pico.CachingConstructorInjectionComponentAdapter;
|
||||
@@ -211,6 +214,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public String getProjectFilePath() {
|
||||
return isDefault() ? null : getStateStore().getProjectFilePath();
|
||||
}
|
||||
@@ -227,6 +231,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SystemIndependent
|
||||
public String getBasePath() {
|
||||
return isDefault() ? null : getStateStore().getProjectBasePath();
|
||||
}
|
||||
@@ -240,6 +245,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
return myName;
|
||||
}
|
||||
|
||||
@SystemDependent
|
||||
@Override
|
||||
public String getPresentableUrl() {
|
||||
if (isDefault()) {
|
||||
@@ -247,7 +253,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
}
|
||||
|
||||
IProjectStore store = getStateStore();
|
||||
return FileUtil.toSystemDependentName(store.getStorageScheme() == StorageScheme.DIRECTORY_BASED ? store.getProjectBasePath() : store.getProjectFilePath());
|
||||
return PathUtil.toSystemDependentName(store.getStorageScheme() == StorageScheme.DIRECTORY_BASED ? store.getProjectBasePath() : store.getProjectFilePath());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user