mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+88
-55
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.generation.ClassMember;
|
||||
import com.intellij.codeInsight.generation.MemberChooserObject;
|
||||
import com.intellij.codeInsight.generation.PsiMethodMember;
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.ide.util.MemberChooser;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -48,7 +49,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class CreateAssignFieldsFromParametersAction extends BaseIntentionAction {
|
||||
public class BindFieldsFromParametersAction extends BaseIntentionAction implements HighPriorityAction {
|
||||
private static final Logger LOG = Logger.getInstance(CreateFieldFromParameterAction.class);
|
||||
private static final Key<Map<SmartPsiElementPointer<PsiParameter>, Boolean>> PARAMS = Key.create("FIELDS_FROM_PARAMS");
|
||||
|
||||
@@ -75,7 +76,7 @@ public class CreateAssignFieldsFromParametersAction extends BaseIntentionAction
|
||||
LOG.assertTrue(psiParameter != null);
|
||||
}
|
||||
|
||||
setText(CodeInsightBundle.message("intention.create.assign.fields.from.parameters.text", method.isConstructor() ? "Constructor" : "Method"));
|
||||
setText(CodeInsightBundle.message("intention.bind.fields.from.parameters.text", method.isConstructor() ? "Constructor" : "Method"));
|
||||
}
|
||||
return isAvailable(psiParameter);
|
||||
}
|
||||
@@ -150,7 +151,7 @@ public class CreateAssignFieldsFromParametersAction extends BaseIntentionAction
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return CodeInsightBundle.message("intention.create.assign.fields.from.parameters.family");
|
||||
return CodeInsightBundle.message("intention.bind.fields.from.parameters.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,62 +164,94 @@ public class CreateAssignFieldsFromParametersAction extends BaseIntentionAction
|
||||
if (!CodeInsightUtilBase.prepareFileForWrite(file)) return;
|
||||
final PsiMethod method = myParameter != null ? (PsiMethod)myParameter.getDeclarationScope() : PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiMethod.class);
|
||||
LOG.assertTrue(method != null);
|
||||
final Collection<SmartPsiElementPointer<PsiParameter>> unboundedParams;
|
||||
synchronized (LOCK) {
|
||||
unboundedParams = getUnboundedParams(method);
|
||||
if (unboundedParams.isEmpty()) return;
|
||||
if (myParameter == null) {
|
||||
myParameter = unboundedParams.iterator().next().getElement();
|
||||
}
|
||||
}
|
||||
if (unboundedParams.size() > 1 && isInteractive) {
|
||||
ClassMember[] members = new ClassMember[unboundedParams.size()];
|
||||
ClassMember selection = null;
|
||||
int i = 0;
|
||||
for (SmartPsiElementPointer<PsiParameter> pointer : unboundedParams) {
|
||||
final PsiParameter parameter = pointer.getElement();
|
||||
final ParameterClassMember classMember = new ParameterClassMember(parameter);
|
||||
members[i++] = classMember;
|
||||
if (parameter == myParameter) {
|
||||
selection = classMember;
|
||||
}
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
Arrays.sort(members, new Comparator<ClassMember>() {
|
||||
@Override
|
||||
public int compare(ClassMember o1, ClassMember o2) {
|
||||
return parameterList.getParameterIndex(((ParameterClassMember)o1).getParameter()) -
|
||||
parameterList.getParameterIndex(((ParameterClassMember)o2).getParameter());
|
||||
}
|
||||
});
|
||||
|
||||
final MemberChooser<ClassMember> chooser = new MemberChooser<ClassMember>(members, false, true, project);
|
||||
if (selection != null) {
|
||||
chooser.selectElements(new ClassMember[]{selection});
|
||||
}
|
||||
chooser.setTitle("Choose " + (method.isConstructor() ? "Constructor" : "Method") + " Parameters");
|
||||
chooser.setCopyJavadocVisible(false);
|
||||
chooser.show();
|
||||
if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) return;
|
||||
final List<ClassMember> selectedElements = chooser.getSelectedElements();
|
||||
if (selectedElements == null) return;
|
||||
|
||||
final HashSet<String> usedNames = new HashSet<String>();
|
||||
for (ClassMember selectedElement : selectedElements) {
|
||||
processParameter(project, ((ParameterClassMember)selectedElement).getParameter(), usedNames);
|
||||
}
|
||||
}
|
||||
else {
|
||||
processParameter(project, myParameter);
|
||||
}
|
||||
synchronized (LOCK) {
|
||||
unboundedParams.clear();
|
||||
final HashSet<String> usedNames = new HashSet<String>();
|
||||
for (PsiParameter selected : selectParameters(project, method, copyUnboundedParamsAndClearOriginal(method), isInteractive)) {
|
||||
processParameter(project, selected, usedNames);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processParameter(final Project project,
|
||||
final PsiParameter myParameter) {
|
||||
processParameter(project, myParameter, new HashSet<String>());
|
||||
@NotNull
|
||||
private static Iterable<PsiParameter> selectParameters(@NotNull Project project,
|
||||
@NotNull PsiMethod method,
|
||||
@NotNull Collection<SmartPsiElementPointer<PsiParameter>> unboundedParams,
|
||||
boolean isInteractive) {
|
||||
if (unboundedParams.size() < 2 || !isInteractive) {
|
||||
return revealPointers(unboundedParams);
|
||||
}
|
||||
|
||||
final ParameterClassMember[] members = sortByParameterIndex(toClassMemberArray(unboundedParams), method);
|
||||
|
||||
final MemberChooser<ParameterClassMember> chooser = showChooser(project, method, members);
|
||||
|
||||
final List<ParameterClassMember> selectedElements = chooser.getSelectedElements();
|
||||
if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE || selectedElements == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return revealParameterClassMembers(selectedElements);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static MemberChooser<ParameterClassMember> showChooser(@NotNull Project project,
|
||||
@NotNull PsiMethod method,
|
||||
@NotNull ParameterClassMember[] members) {
|
||||
final MemberChooser<ParameterClassMember> chooser = new MemberChooser<ParameterClassMember>(members, false, true, project);
|
||||
chooser.selectElements(members);
|
||||
chooser.setTitle("Choose " + (method.isConstructor() ? "Constructor" : "Method") + " Parameters");
|
||||
chooser.show();
|
||||
return chooser;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ParameterClassMember[] sortByParameterIndex(@NotNull ParameterClassMember[] members, @NotNull PsiMethod method) {
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
Arrays.sort(members, new Comparator<ParameterClassMember>() {
|
||||
@Override
|
||||
public int compare(ParameterClassMember o1, ParameterClassMember o2) {
|
||||
return parameterList.getParameterIndex(o1.getParameter()) -
|
||||
parameterList.getParameterIndex(o2.getParameter());
|
||||
}
|
||||
});
|
||||
return members;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T extends PsiElement> List<T> revealPointers(@NotNull Iterable<SmartPsiElementPointer<T>> pointers) {
|
||||
final List<T> result = new ArrayList<T>();
|
||||
for (SmartPsiElementPointer<T> pointer : pointers) {
|
||||
result.add(pointer.getElement());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<PsiParameter> revealParameterClassMembers(@NotNull Iterable<ParameterClassMember> parameterClassMembers) {
|
||||
final List<PsiParameter> result = new ArrayList<PsiParameter>();
|
||||
for (ParameterClassMember parameterClassMember : parameterClassMembers) {
|
||||
result.add(parameterClassMember.getParameter());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ParameterClassMember[] toClassMemberArray(@NotNull Collection<SmartPsiElementPointer<PsiParameter>> unboundedParams) {
|
||||
final ParameterClassMember[] result = new ParameterClassMember[unboundedParams.size()];
|
||||
int i = 0;
|
||||
for (SmartPsiElementPointer<PsiParameter> pointer : unboundedParams) {
|
||||
result[i++] = new ParameterClassMember(pointer.getElement());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<SmartPsiElementPointer<PsiParameter>> copyUnboundedParamsAndClearOriginal(@NotNull PsiMethod method) {
|
||||
synchronized (LOCK) {
|
||||
final Collection<SmartPsiElementPointer<PsiParameter>> unboundedParams = getUnboundedParams(method);
|
||||
final Collection<SmartPsiElementPointer<PsiParameter>> result = new ArrayList<SmartPsiElementPointer<PsiParameter>>(unboundedParams);
|
||||
unboundedParams.clear();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processParameter(final Project project,
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
private int myP1;
|
||||
private int myP2;
|
||||
|
||||
void method(int p1, int p2){
|
||||
myP1 = p1;
|
||||
myP2 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestBefore {
|
||||
|
||||
@NotNull
|
||||
private final String myName;
|
||||
@NotNull
|
||||
private final String myName2;
|
||||
|
||||
public TestBefore(@NotNull String name, @NotNull String name2) {
|
||||
super();
|
||||
myName = name;
|
||||
myName2 = name2;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestBefore {
|
||||
|
||||
@Nullable
|
||||
private final String myName;
|
||||
@Nullable
|
||||
private final String myName2;
|
||||
|
||||
public TestBefore(@Nullable String name, @Nullable String name2) {
|
||||
super();
|
||||
myName = name;
|
||||
myName2 = name2;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
class Bar {
|
||||
|
||||
private int myi1;
|
||||
private int myi2;
|
||||
private final int myI1;
|
||||
private final int myI2;
|
||||
private final String myI3;
|
||||
|
||||
Bar(int i1, int i2, String i3) {
|
||||
myI1 = i1;
|
||||
myI2 = i2;
|
||||
myI3 = i3;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
private Object myP1;
|
||||
private Object myP2;
|
||||
|
||||
<T> void f(T p1, T p2){
|
||||
myP1 = p1;
|
||||
myP2 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
private String myP1;
|
||||
private String myP2;
|
||||
|
||||
<T extends String> void f(T p1, T p2){
|
||||
myP1 = p1;
|
||||
myP2 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
void <caret>method(int p1, int p2){
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Bind Method Parameters to Fields" "false"
|
||||
|
||||
class A{
|
||||
private final String myP1;
|
||||
|
||||
void <caret>f(String p1){
|
||||
myP1 = p1;
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Bind Method Parameters to Fields" "false"
|
||||
|
||||
class A{
|
||||
private final String myP1;
|
||||
private final String myP2;
|
||||
|
||||
void <caret>f(String p1, String p2){
|
||||
myP1 = p1;
|
||||
myP2 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Bind Method Parameters to Fields" "false"
|
||||
|
||||
class A{
|
||||
void <caret>f(){
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestBefore {
|
||||
|
||||
public TestBefore(@NotNull String name<caret>, @NotNull String name2) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestBefore {
|
||||
|
||||
public TestBefore(@Nullable String name<caret>, @Nullable String name2) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Bind Constructor Parameters to Fields" "true"
|
||||
|
||||
class Bar {
|
||||
|
||||
private int myi1;
|
||||
private int myi2;
|
||||
|
||||
Bar(int <caret>i1, int i2, String i3) {
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
<T> void f(T p<caret>1, T p2){
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Bind Method Parameters to Fields" "true"
|
||||
|
||||
class A{
|
||||
<T extends String> void f(T p<caret>1, T p2){
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class CreateAssignFieldsFromParametersTest extends LightIntentionActionTestCase {
|
||||
public class BindFieldsFromParametersTest extends LightIntentionActionTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -41,6 +41,6 @@ public class CreateAssignFieldsFromParametersTest extends LightIntentionActionTe
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/createAssignFieldsFromParameters";
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/bindFieldsFromParameters";
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,6 @@ public class OrderEntriesTest extends ModuleRootManagerTestCase {
|
||||
}
|
||||
|
||||
private void assertOrderFiles(final OrderRootType type, VirtualFile... files) {
|
||||
assertOrderedEquals(ModuleRootManager.getInstance(myModule).getFiles(type), files);
|
||||
assertRoots(collectByOrderEnumerator(type), files);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface JpsCompositeElement extends JpsParentElement {
|
||||
public interface JpsCompositeElement extends JpsElement {
|
||||
@NotNull
|
||||
JpsElementContainer getContainer();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface JpsElementCollection<E extends JpsElement> extends JpsParentElement {
|
||||
public interface JpsElementCollection<E extends JpsElement> extends JpsElement {
|
||||
List<E> getElements();
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jps.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
|
||||
/**
|
||||
@@ -11,5 +12,6 @@ public interface JpsGlobal extends JpsCompositeElement, JpsReferenceableElement<
|
||||
@NotNull
|
||||
JpsLibrary addLibrary(@NotNull JpsLibraryType libraryType, final @NotNull String name);
|
||||
|
||||
|
||||
@NotNull
|
||||
JpsLibraryCollection getLibraryCollection();
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.jetbrains.jps.model;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface JpsParentElement extends JpsElement {
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jps.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleType;
|
||||
@@ -16,16 +17,15 @@ public interface JpsProject extends JpsCompositeElement, JpsReferenceableElement
|
||||
@NotNull
|
||||
JpsModule addModule(@NotNull JpsModuleType<?> moduleType, @NotNull String name);
|
||||
|
||||
void addModule(@NotNull JpsModule module);
|
||||
|
||||
@NotNull
|
||||
List<JpsModule> getModules();
|
||||
|
||||
|
||||
@NotNull
|
||||
JpsLibrary addLibrary(@NotNull JpsLibraryType<?> libraryType, @NotNull String name);
|
||||
|
||||
@NotNull
|
||||
List<? extends JpsLibrary> getLibraries();
|
||||
|
||||
@NotNull
|
||||
List<? extends JpsModule> getModules();
|
||||
|
||||
void addModule(JpsModule module);
|
||||
|
||||
void addLibrary(JpsLibrary library);
|
||||
JpsLibraryCollection getLibraryCollection();
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@ import java.util.List;
|
||||
public interface JpsLibrary extends JpsNamedElement, JpsReferenceableElement<JpsLibrary> {
|
||||
|
||||
@NotNull
|
||||
List<String> getUrls(@NotNull JpsLibraryRootType rootType);
|
||||
List<JpsLibraryRoot> getRoots(@NotNull JpsOrderRootType rootType);
|
||||
|
||||
void addUrl(@NotNull String url, @NotNull JpsLibraryRootType rootType);
|
||||
void addRoot(@NotNull String url, @NotNull JpsOrderRootType rootType);
|
||||
|
||||
void removeUrl(@NotNull String url, @NotNull JpsLibraryRootType rootType);
|
||||
void addRoot(@NotNull String url, @NotNull JpsOrderRootType rootType, @NotNull JpsLibraryRoot.InclusionOptions options);
|
||||
|
||||
void removeUrl(@NotNull String url, @NotNull JpsOrderRootType rootType);
|
||||
|
||||
void delete();
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.jetbrains.jps.model.library;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface JpsLibraryCollection {
|
||||
@NotNull
|
||||
JpsLibrary addLibrary(@NotNull JpsLibraryType<?> libraryType, @NotNull String name);
|
||||
|
||||
@NotNull
|
||||
List<JpsLibrary> getLibraries();
|
||||
|
||||
void addLibrary(@NotNull JpsLibrary library);
|
||||
}
|
||||
@@ -8,11 +8,16 @@ import org.jetbrains.jps.model.JpsElement;
|
||||
*/
|
||||
public interface JpsLibraryRoot extends JpsElement {
|
||||
@NotNull
|
||||
JpsLibraryRootType getRootType();
|
||||
JpsOrderRootType getRootType();
|
||||
|
||||
@NotNull
|
||||
String getUrl();
|
||||
|
||||
@NotNull
|
||||
InclusionOptions getInclusionOptions();
|
||||
|
||||
@NotNull
|
||||
JpsLibrary getLibrary();
|
||||
|
||||
enum InclusionOptions {ROOT_ITSELF, ARCHIVES_UNDER_ROOT, ARCHIVES_UNDER_ROOT_RECURSIVELY}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.jetbrains.jps.model.library;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryRootType {
|
||||
public static final JpsLibraryRootType COMPILED = new JpsLibraryRootType(JpsOrderRootType.COMPILED, false, false);
|
||||
public static final JpsLibraryRootType SOURCES = new JpsLibraryRootType(JpsOrderRootType.SOURCES, false, false);
|
||||
private final boolean myJarDirectory;
|
||||
private final boolean myRecursive;
|
||||
private final JpsOrderRootType myType;
|
||||
|
||||
public JpsLibraryRootType(JpsOrderRootType type, boolean jarDirectory, boolean recursive) {
|
||||
myJarDirectory = jarDirectory;
|
||||
myRecursive = recursive;
|
||||
myType = type;
|
||||
}
|
||||
|
||||
public boolean isJarDirectory() {
|
||||
return myJarDirectory;
|
||||
}
|
||||
|
||||
public JpsOrderRootType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
public boolean isRecursive() {
|
||||
return myRecursive;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jps.model.module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
|
||||
import java.util.List;
|
||||
@@ -42,11 +43,13 @@ public interface JpsModule extends JpsNamedElement, JpsReferenceableElement<JpsM
|
||||
@NotNull
|
||||
JpsLibrary addModuleLibrary(@NotNull JpsLibraryType<?> type, @NotNull String name);
|
||||
|
||||
@NotNull
|
||||
JpsLibrary addModuleLibrary(@NotNull JpsLibrary library);
|
||||
void addModuleLibrary(@NotNull JpsLibrary library);
|
||||
|
||||
void delete();
|
||||
@NotNull
|
||||
JpsLibraryCollection getLibraryCollection();
|
||||
|
||||
@NotNull
|
||||
JpsSdkReferencesTable getSdkReferencesTable();
|
||||
|
||||
void delete();
|
||||
}
|
||||
|
||||
@@ -1,30 +1,42 @@
|
||||
package org.jetbrains.jps.model.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.JpsElementReference;
|
||||
import org.jetbrains.jps.model.JpsEventDispatcher;
|
||||
import org.jetbrains.jps.model.JpsGlobal;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryCollectionImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryKind;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsGlobalImpl extends JpsRootElementBase<JpsGlobalImpl> implements JpsGlobal {
|
||||
private final JpsLibraryCollectionImpl myLibraryCollection;
|
||||
|
||||
public JpsGlobalImpl(JpsModel model, JpsEventDispatcher eventDispatcher) {
|
||||
super(model, eventDispatcher);
|
||||
myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
}
|
||||
|
||||
public JpsGlobalImpl(JpsGlobalImpl original, JpsModel model, JpsEventDispatcher eventDispatcher) {
|
||||
super(original, model, eventDispatcher);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibrary addLibrary(@NotNull JpsLibraryType libraryType, @NotNull final String name) {
|
||||
final JpsElementCollectionImpl<JpsLibrary> collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND);
|
||||
return collection.addChild(new JpsLibraryImpl(name, libraryType));
|
||||
return myLibraryCollection.addLibrary(libraryType, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibraryCollection getLibraryCollection() {
|
||||
return myLibraryCollection;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package org.jetbrains.jps.model.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.JpsElementReference;
|
||||
import org.jetbrains.jps.model.JpsEventDispatcher;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryCollectionImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryKind;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleType;
|
||||
@@ -19,16 +23,18 @@ import java.util.List;
|
||||
public class JpsProjectImpl extends JpsRootElementBase<JpsProjectImpl> implements JpsProject {
|
||||
private static final JpsElementCollectionKind<JpsElementReference<?>> EXTERNAL_REFERENCES_COLLECTION_KIND =
|
||||
new JpsElementCollectionKind<JpsElementReference<?>>(new JpsElementKindBase<JpsElementReference<?>>("external reference"));
|
||||
private final JpsLibraryCollection myLibraryCollection;
|
||||
|
||||
public JpsProjectImpl(JpsModel model, JpsEventDispatcher eventDispatcher) {
|
||||
super(model, eventDispatcher);
|
||||
myContainer.setChild(JpsModuleKind.MODULE_COLLECTION_KIND);
|
||||
myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND);
|
||||
myContainer.setChild(EXTERNAL_REFERENCES_COLLECTION_KIND);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
}
|
||||
|
||||
public JpsProjectImpl(JpsProjectImpl original, JpsModel model, JpsEventDispatcher eventDispatcher) {
|
||||
super(original, model, eventDispatcher);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
}
|
||||
|
||||
public void addExternalReference(@NotNull JpsElementReference<?> reference) {
|
||||
@@ -45,30 +51,24 @@ public class JpsProjectImpl extends JpsRootElementBase<JpsProjectImpl> implement
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibrary addLibrary(@NotNull JpsLibraryType<?> libraryType, @NotNull final String name) {
|
||||
final JpsElementCollectionImpl<JpsLibrary> collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND);
|
||||
return collection.addChild(new JpsLibraryImpl(name, libraryType));
|
||||
return myLibraryCollection.addLibrary(libraryType, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsLibrary> getLibraries() {
|
||||
return myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).getElements();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsModule> getModules() {
|
||||
public List<JpsModule> getModules() {
|
||||
return myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND).getElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addModule(JpsModule module) {
|
||||
public void addModule(@NotNull JpsModule module) {
|
||||
myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND).addChild(module);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void addLibrary(JpsLibrary library) {
|
||||
myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).addChild(library);
|
||||
public JpsLibraryCollection getLibraryCollection() {
|
||||
return myLibraryCollection;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.jetbrains.jps.model.library.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryCollectionImpl implements JpsLibraryCollection {
|
||||
private final JpsElementCollection<JpsLibrary> myCollection;
|
||||
|
||||
public JpsLibraryCollectionImpl(JpsElementCollection<JpsLibrary> collection) {
|
||||
myCollection = collection;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibrary addLibrary(@NotNull JpsLibraryType<?> libraryType, @NotNull String name) {
|
||||
return myCollection.addChild(new JpsLibraryImpl(name, libraryType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JpsLibrary> getLibraries() {
|
||||
return myCollection.getElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLibrary(@NotNull JpsLibrary library) {
|
||||
myCollection.addChild(library);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,16 @@ package org.jetbrains.jps.model.library.impl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.impl.*;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryReference;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRootType;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryImpl extends JpsNamedCompositeElementBase<JpsLibraryImpl, JpsProjectImpl> implements JpsLibrary {
|
||||
private static final JpsElementCollectionKind<JpsLibraryRootImpl> LIBRARY_ROOTS_COLLECTION =
|
||||
new JpsElementCollectionKind<JpsLibraryRootImpl>(JpsLibraryRootKind.INSTANCE);
|
||||
private static final JpsElementCollectionKind<JpsLibraryRoot> LIBRARY_ROOTS_COLLECTION =
|
||||
new JpsElementCollectionKind<JpsLibraryRoot>(JpsLibraryRootKind.INSTANCE);
|
||||
private static final JpsTypedDataKind<JpsLibraryType<?>> TYPED_DATA_KIND = new JpsTypedDataKind<JpsLibraryType<?>>();
|
||||
|
||||
public JpsLibraryImpl(@NotNull String name, @NotNull JpsLibraryType<?> type) {
|
||||
@@ -31,29 +27,29 @@ public class JpsLibraryImpl extends JpsNamedCompositeElementBase<JpsLibraryImpl,
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getUrls(@NotNull JpsLibraryRootType rootType) {
|
||||
final List<String> urls = new ArrayList<String>();
|
||||
for (JpsLibraryRootImpl root : getRootsCollection().getElements()) {
|
||||
if (root.getRootType().equals(rootType)) {
|
||||
urls.add(root.getUrl());
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
public List<JpsLibraryRoot> getRoots(@NotNull JpsOrderRootType rootType) {
|
||||
return getRootsCollection().getElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUrl(@NotNull final String url, @NotNull final JpsLibraryRootType rootType) {
|
||||
getRootsCollection().addChild(new JpsLibraryRootImpl(url, rootType));
|
||||
public void addRoot(@NotNull String url, @NotNull JpsOrderRootType rootType) {
|
||||
addRoot(url, rootType, JpsLibraryRoot.InclusionOptions.ROOT_ITSELF);
|
||||
}
|
||||
|
||||
private JpsElementCollectionImpl<JpsLibraryRootImpl> getRootsCollection() {
|
||||
@Override
|
||||
public void addRoot(@NotNull final String url, @NotNull final JpsOrderRootType rootType,
|
||||
@NotNull JpsLibraryRoot.InclusionOptions options) {
|
||||
getRootsCollection().addChild(new JpsLibraryRootImpl(url, rootType, options));
|
||||
}
|
||||
|
||||
private JpsElementCollectionImpl<JpsLibraryRoot> getRootsCollection() {
|
||||
return myContainer.getChild(LIBRARY_ROOTS_COLLECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUrl(@NotNull final String url, @NotNull final JpsLibraryRootType rootType) {
|
||||
final JpsElementCollectionImpl<JpsLibraryRootImpl> rootsCollection = getRootsCollection();
|
||||
for (JpsLibraryRootImpl root : rootsCollection.getElements()) {
|
||||
public void removeUrl(@NotNull final String url, @NotNull final JpsOrderRootType rootType) {
|
||||
final JpsElementCollection<JpsLibraryRoot> rootsCollection = getRootsCollection();
|
||||
for (JpsLibraryRoot root : rootsCollection.getElements()) {
|
||||
if (root.getUrl().equals(url) && root.getRootType().equals(rootType)) {
|
||||
rootsCollection.removeChild(root);
|
||||
break;
|
||||
|
||||
@@ -4,29 +4,31 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.impl.JpsElementBase;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRootType;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryRootImpl extends JpsElementBase<JpsLibraryRootImpl> implements JpsLibraryRoot {
|
||||
private final String myUrl;
|
||||
private final JpsLibraryRootType myRootType;
|
||||
private final JpsOrderRootType myRootType;
|
||||
private final InclusionOptions myOptions;
|
||||
|
||||
public JpsLibraryRootImpl(@NotNull String url,
|
||||
@NotNull JpsLibraryRootType rootType) {
|
||||
public JpsLibraryRootImpl(@NotNull String url, @NotNull JpsOrderRootType rootType, @NotNull InclusionOptions options) {
|
||||
myUrl = url;
|
||||
myRootType = rootType;
|
||||
myOptions = options;
|
||||
}
|
||||
|
||||
public JpsLibraryRootImpl(JpsLibraryRootImpl original) {
|
||||
myUrl = original.myUrl;
|
||||
myRootType = original.myRootType;
|
||||
myOptions = original.myOptions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibraryRootType getRootType() {
|
||||
public JpsOrderRootType getRootType() {
|
||||
return myRootType;
|
||||
}
|
||||
|
||||
@@ -35,6 +37,12 @@ public class JpsLibraryRootImpl extends JpsElementBase<JpsLibraryRootImpl> imple
|
||||
return myUrl;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InclusionOptions getInclusionOptions() {
|
||||
return myOptions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibraryRootImpl createCopy() {
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.jetbrains.jps.model.library.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.impl.JpsElementKindBase;
|
||||
import org.jetbrains.jps.model.JpsEventDispatcher;
|
||||
import org.jetbrains.jps.model.impl.JpsElementKindBase;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRootListener;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryRootKind extends JpsElementKindBase<JpsLibraryRootImpl> {
|
||||
public class JpsLibraryRootKind extends JpsElementKindBase<JpsLibraryRoot> {
|
||||
public static final JpsLibraryRootKind INSTANCE = new JpsLibraryRootKind();
|
||||
|
||||
public JpsLibraryRootKind() {
|
||||
@@ -16,12 +17,12 @@ public class JpsLibraryRootKind extends JpsElementKindBase<JpsLibraryRootImpl> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRootImpl element) {
|
||||
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRoot element) {
|
||||
dispatcher.getPublisher(JpsLibraryRootListener.class).rootAdded(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRootImpl element) {
|
||||
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRoot element) {
|
||||
dispatcher.getPublisher(JpsLibraryRootListener.class).rootRemoved(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.jetbrains.jps.model.module.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.JpsElementKind;
|
||||
import org.jetbrains.jps.model.JpsElementProperties;
|
||||
import org.jetbrains.jps.model.JpsUrlList;
|
||||
import org.jetbrains.jps.model.impl.*;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryCollectionImpl;
|
||||
import org.jetbrains.jps.model.library.impl.JpsLibraryKind;
|
||||
import org.jetbrains.jps.model.module.*;
|
||||
|
||||
@@ -18,8 +21,8 @@ public class JpsModuleImpl extends JpsNamedCompositeElementBase<JpsModuleImpl, J
|
||||
private static final JpsTypedDataKind<JpsModuleType<?>> TYPED_DATA_KIND = new JpsTypedDataKind<JpsModuleType<?>>();
|
||||
private static final JpsUrlListKind CONTENT_ROOTS_KIND = new JpsUrlListKind("content roots");
|
||||
private static final JpsUrlListKind EXCLUDED_ROOTS_KIND = new JpsUrlListKind("excluded roots");
|
||||
public static final JpsElementKind<JpsDependenciesListImpl> DEPENDENCIES_LIST_KIND =
|
||||
new JpsElementKindBase<JpsDependenciesListImpl>("dependencies");
|
||||
public static final JpsElementKind<JpsDependenciesListImpl> DEPENDENCIES_LIST_KIND = new JpsElementKindBase<JpsDependenciesListImpl>("dependencies");
|
||||
private final JpsLibraryCollection myLibraryCollection;
|
||||
|
||||
public JpsModuleImpl(JpsModuleType type,
|
||||
@NotNull String name) {
|
||||
@@ -28,13 +31,14 @@ public class JpsModuleImpl extends JpsNamedCompositeElementBase<JpsModuleImpl, J
|
||||
myContainer.setChild(CONTENT_ROOTS_KIND);
|
||||
myContainer.setChild(EXCLUDED_ROOTS_KIND);
|
||||
myContainer.setChild(DEPENDENCIES_LIST_KIND, new JpsDependenciesListImpl());
|
||||
myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
myContainer.setChild(JpsModuleSourceRootKind.ROOT_COLLECTION_KIND);
|
||||
myContainer.setChild(JpsSdkReferencesTableImpl.KIND, new JpsSdkReferencesTableImpl());
|
||||
}
|
||||
|
||||
private JpsModuleImpl(JpsModuleImpl original) {
|
||||
super(original);
|
||||
myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -116,12 +120,17 @@ public class JpsModuleImpl extends JpsNamedCompositeElementBase<JpsModuleImpl, J
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibrary addModuleLibrary(@NotNull JpsLibraryType<?> type, @NotNull String name) {
|
||||
return addModuleLibrary(new JpsLibraryImpl(name, type));
|
||||
return myLibraryCollection.addLibrary(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addModuleLibrary(final @NotNull JpsLibrary library) {
|
||||
myLibraryCollection.addLibrary(library);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsLibrary addModuleLibrary(final @NotNull JpsLibrary library) {
|
||||
return myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).addChild(library);
|
||||
public JpsLibraryCollection getLibraryCollection() {
|
||||
return myLibraryCollection;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.jetbrains.jps.model;
|
||||
|
||||
import org.jetbrains.jps.model.java.JpsJavaLibraryType;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryReference;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRootType;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -11,20 +9,20 @@ import org.jetbrains.jps.model.library.JpsLibraryRootType;
|
||||
public class JpsLibraryTest extends JpsModelTestCase {
|
||||
public void testAddRoot() {
|
||||
final JpsLibrary library = myModel.getProject().addLibrary(JpsJavaLibraryType.INSTANCE, "a");
|
||||
library.addUrl("file://my-url", JpsLibraryRootType.COMPILED);
|
||||
assertEquals("file://my-url", assertOneElement(library.getUrls(JpsLibraryRootType.COMPILED)));
|
||||
library.addRoot("file://my-url", JpsOrderRootType.COMPILED);
|
||||
assertEquals("file://my-url", assertOneElement(library.getRoots(JpsOrderRootType.COMPILED)).getUrl());
|
||||
}
|
||||
|
||||
public void testModifiableCopy() {
|
||||
myModel.getProject().addLibrary(JpsJavaLibraryType.INSTANCE, "a");
|
||||
|
||||
final JpsModel modifiableModel = myModel.createModifiableModel(new TestJpsEventDispatcher());
|
||||
final JpsLibrary modifiable = assertOneElement(modifiableModel.getProject().getLibraries());
|
||||
modifiable.addUrl("file://my-url", JpsLibraryRootType.COMPILED);
|
||||
final JpsLibrary modifiable = assertOneElement(modifiableModel.getProject().getLibraryCollection().getLibraries());
|
||||
modifiable.addRoot("file://my-url", JpsOrderRootType.COMPILED);
|
||||
modifiableModel.commit();
|
||||
|
||||
final JpsLibrary library = assertOneElement(myModel.getProject().getLibraries());
|
||||
assertEquals("file://my-url", assertOneElement(library.getUrls(JpsLibraryRootType.COMPILED)));
|
||||
final JpsLibrary library = assertOneElement(myModel.getProject().getLibraryCollection().getLibraries());
|
||||
assertEquals("file://my-url", assertOneElement(library.getRoots(JpsOrderRootType.COMPILED)).getUrl());
|
||||
}
|
||||
|
||||
public void testCreateReferenceByLibrary() {
|
||||
|
||||
+10
-7
@@ -5,10 +5,7 @@ import com.intellij.util.containers.MultiMap;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.java.JpsJavaLibraryType;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRootType;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -55,9 +52,15 @@ public class JpsLibraryTableLoader {
|
||||
final JpsOrderRootType rootType = getRootType(rootTypeId);
|
||||
for (Element rootElement : JDOMUtil.getChildren(rootsElement, "root")) {
|
||||
String url = rootElement.getAttributeValue("url");
|
||||
final boolean jarDirectory = jarDirectories.get(rootType).contains(url);
|
||||
final boolean recursive = recursiveJarDirectories.get(rootType).contains(url);
|
||||
library.addUrl(url, new JpsLibraryRootType(rootType, jarDirectory, recursive));
|
||||
JpsLibraryRoot.InclusionOptions options;
|
||||
if (jarDirectories.get(rootType).contains(url)) {
|
||||
final boolean recursive = recursiveJarDirectories.get(rootType).contains(url);
|
||||
options = recursive ? JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY : JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT;
|
||||
}
|
||||
else {
|
||||
options = JpsLibraryRoot.InclusionOptions.ROOT_ITSELF;
|
||||
}
|
||||
library.addRoot(url, rootType, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class JpsProjectLoader {
|
||||
final ArrayList<JpsLibrary> libraries = new ArrayList<JpsLibrary>();
|
||||
JpsLibraryTableLoader.loadLibraries(libraryTableElement, libraries);
|
||||
for (JpsLibrary library : libraries) {
|
||||
myProject.addLibrary(library);
|
||||
myProject.getLibraryCollection().addLibrary(library);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class JpsModuleSerializationTest extends JpsModelTestCase {
|
||||
loadProject("iprProject/iprProject.ipr");
|
||||
final JpsModule module = assertOneElement(myModel.getProject().getModules());
|
||||
assertEquals("iprProject", module.getName());
|
||||
final JpsLibrary library = assertOneElement(myModel.getProject().getLibraries());
|
||||
final JpsLibrary library = assertOneElement(myModel.getProject().getLibraryCollection().getLibraries());
|
||||
assertEquals("junit", library.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,9 @@ public class EnterHandler extends BaseEnterHandler {
|
||||
throw new AssertionError("Wrong caret offset change by " + delegate);
|
||||
}
|
||||
|
||||
if (result == EnterHandlerDelegate.Result.Stop) return;
|
||||
if (result == EnterHandlerDelegate.Result.Stop) {
|
||||
return;
|
||||
}
|
||||
if (result != EnterHandlerDelegate.Result.Continue) {
|
||||
if (result == EnterHandlerDelegate.Result.DefaultForceIndent) {
|
||||
forceIndent = true;
|
||||
|
||||
@@ -192,8 +192,8 @@ intention.assign.field.from.parameter.text=Assign Parameter to Field ''{0}''
|
||||
intention.assign.field.from.parameter.family=Assign Parameter to Field
|
||||
intention.create.field.from.parameter.text=Create Field for Parameter ''{0}''
|
||||
intention.create.field.from.parameter.family=Create Field for Parameter
|
||||
intention.create.assign.fields.from.parameters.text=Create/Assign Fields from {0} Parameters
|
||||
intention.create.assign.fields.from.parameters.family=Create/Assign Fields from Parameters
|
||||
intention.bind.fields.from.parameters.text=Bind {0} Parameters to Fields
|
||||
intention.bind.fields.from.parameters.family=Bind Parameters to Fields
|
||||
intention.implement.abstract.method.searching.for.descendants.progress=Searching For Descendants...
|
||||
intention.implement.abstract.method.error.no.classes.message=There are no classes found where this method can be implemented
|
||||
intention.implement.abstract.method.error.no.classes.title=No Classes Found
|
||||
@@ -205,6 +205,8 @@ intention.extract.if.condition.family=Extract If Condition
|
||||
intention.underscores.in.literals.family=Underscores in numeric literals
|
||||
intention.remove.literal.underscores=Remove underscores from literal
|
||||
intention.insert.literal.underscores=Insert underscores into literal
|
||||
intention.replace.cast.with.var.text=Replace '{0}' with '{1}'
|
||||
intention.replace.cast.with.var.family=Replace cast with variable
|
||||
|
||||
|
||||
intention.create.test=Create Test
|
||||
|
||||
@@ -151,23 +151,12 @@ public interface ModifiableRootModel extends ModuleRootModel {
|
||||
*/
|
||||
void inheritSdk();
|
||||
|
||||
/**
|
||||
* @deprecated see {@link ModuleRootManager#getFiles(OrderRootType)} for replacement
|
||||
*/
|
||||
@NotNull VirtualFile[] getOrderedRoots(OrderRootType type);
|
||||
|
||||
|
||||
void setExplodedDirectory(VirtualFile file);
|
||||
|
||||
void setExplodedDirectory(String url);
|
||||
|
||||
boolean isChanged();
|
||||
|
||||
/**
|
||||
* @deprecated see {@link ModuleRootManager#getUrls(OrderRootType)} for replacement
|
||||
*/
|
||||
@NotNull String[] getOrderedRootUrls(OrderRootType type);
|
||||
|
||||
boolean isExcludeExplodedDirectory();
|
||||
|
||||
void setExcludeExplodedDirectory(boolean excludeExplodedDir);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -35,34 +34,6 @@ public abstract class ModuleRootManager implements ModuleRootModel {
|
||||
return module.getComponent(ModuleRootManager.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of roots of the specified type for the current module and all modules it depends on.
|
||||
*
|
||||
* @param type the type of roots requested.
|
||||
* @return the list of roots.
|
||||
*
|
||||
* @deprecated
|
||||
* <ul>
|
||||
* <li> to get {@link OrderRootType#CLASSES} use <code>OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots()<code>
|
||||
* <li> to get {@link OrderRootType#SOURCES} use <code>OrderEnumerator.orderEntries(module).getAllSourceRoots()<code>
|
||||
*/
|
||||
@NotNull
|
||||
public abstract VirtualFile[] getFiles(OrderRootType type);
|
||||
|
||||
/**
|
||||
* Returns the list of URLs of roots of the specified type for the current module and all modules it depends on.
|
||||
*
|
||||
* @param type the type of roots requested.
|
||||
* @return the list of root URLs.
|
||||
|
||||
* @deprecated
|
||||
* <ul>
|
||||
* <li> to get {@link OrderRootType#CLASSES} use <code>OrderEnumerator.orderEntries(module).withoutModuleSourceEntries().recursively().exportedOnly().classes().getUrls()<code>
|
||||
* <li> to get {@link OrderRootType#SOURCES} use <code>OrderEnumerator.orderEntries(module).recursively().exportedOnly().sources().getUrls()<code>
|
||||
*/
|
||||
@NotNull
|
||||
public abstract String[] getUrls(OrderRootType type);
|
||||
|
||||
/**
|
||||
* Returns the file index for the current module.
|
||||
*
|
||||
|
||||
@@ -51,11 +51,6 @@ public abstract class ProjectRootManager implements ModificationTracker {
|
||||
@NotNull
|
||||
public abstract ProjectFileIndex getFileIndex();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #orderEntries()}
|
||||
*/
|
||||
public abstract VirtualFile[] getFilesFromAllModules(OrderRootType type);
|
||||
|
||||
/**
|
||||
* Creates new enumerator instance to process dependencies of all modules in the project. Only first level dependencies of
|
||||
* modules are processed so {@link OrderEnumerator#recursively()} option is ignored and {@link OrderEnumerator#withoutDepModules()} option is forced
|
||||
|
||||
-10
@@ -168,16 +168,6 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements ModuleCo
|
||||
return myRootModel.isSdkInherited();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getFiles(OrderRootType type) {
|
||||
return getCachingEnumeratorForType(type, myModule, false).getRoots();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[] getUrls(OrderRootType type) {
|
||||
return getCachingEnumeratorForType(type, myModule, false).getUrls();
|
||||
}
|
||||
|
||||
void commitModel(RootModelImpl rootModel) {
|
||||
ApplicationManager.getApplication().assertWriteAccessAllowed();
|
||||
LOG.assertTrue(rootModel.myModuleRootManager == this);
|
||||
|
||||
-10
@@ -176,16 +176,6 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
return VfsUtilCore.toVirtualFileArray(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile[] getFilesFromAllModules(OrderRootType type) {
|
||||
final List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
for (Module module : getModuleManager().getSortedModules()) {
|
||||
final VirtualFile[] files = ModuleRootManager.getInstance(module).getFiles(type);
|
||||
ContainerUtil.addAll(result, files);
|
||||
}
|
||||
return VfsUtilCore.toVirtualFileArray(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OrderEnumerator orderEntries() {
|
||||
|
||||
@@ -247,28 +247,6 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel
|
||||
return myOrderRootPointerContainers.get(orderRootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile[] getOrderedRoots(OrderRootType type) {
|
||||
final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
|
||||
for (OrderEntry orderEntry : getOrderEntries()) {
|
||||
ContainerUtil.addAll(result, orderEntry.getFiles(type));
|
||||
}
|
||||
return ContainerUtil.toArray(result, new VirtualFile[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getOrderedRootUrls(OrderRootType type) {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
for (OrderEntry orderEntry : getOrderEntries()) {
|
||||
ContainerUtil.addAll(result, orderEntry.getUrls(type));
|
||||
}
|
||||
return ContainerUtil.toArray(result, new String[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OrderEntry[] getOrderEntries() {
|
||||
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.project.model.impl.library;
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.RootProvider;
|
||||
import com.intellij.openapi.roots.impl.RootModelImpl;
|
||||
import com.intellij.openapi.roots.impl.RootProviderBaseImpl;
|
||||
import com.intellij.openapi.roots.impl.libraries.JarDirectories;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryProperties;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryDelegate implements LibraryEx {
|
||||
private JpsLibrary myJpsLibrary;
|
||||
private JpsLibraryTableImpl myLibraryTable;
|
||||
private Map<OrderRootType, VirtualFilePointerContainer> myRoots;
|
||||
private RootProviderBaseImpl myRootProvider = new MyRootProvider();
|
||||
|
||||
public JpsLibraryDelegate(JpsLibrary library, JpsLibraryTableImpl table) {
|
||||
myJpsLibrary = library;
|
||||
myLibraryTable = table;
|
||||
myRoots = new HashMap<OrderRootType, VirtualFilePointerContainer>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myJpsLibrary.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentLibraryKind<?> getKind() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryProperties getProperties() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getUrls(@NotNull OrderRootType rootType) {
|
||||
final VirtualFilePointerContainer container = myRoots.get(rootType);
|
||||
if (container == null) return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
return container.getUrls();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
|
||||
final VirtualFilePointerContainer container = myRoots.get(rootType);
|
||||
if (container == null) return VirtualFile.EMPTY_ARRAY;
|
||||
final List<VirtualFile> expanded = new ArrayList<VirtualFile>();
|
||||
for (JpsLibraryRoot root : myJpsLibrary.getRoots(getJpsRootType(rootType))) {
|
||||
final VirtualFilePointer pointer = container.findByUrl(root.getUrl());
|
||||
if (pointer == null) continue;
|
||||
VirtualFile file = pointer.getFile();
|
||||
if (file == null) continue;
|
||||
|
||||
if (file.isDirectory() && root.getInclusionOptions() != JpsLibraryRoot.InclusionOptions.ROOT_ITSELF) {
|
||||
LibraryImpl.collectJarFiles(file, expanded, root.getInclusionOptions() == JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY);
|
||||
continue;
|
||||
}
|
||||
expanded.add(file);
|
||||
}
|
||||
return VfsUtilCore.toVirtualFileArray(expanded);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInvalidRootUrls(OrderRootType type) {
|
||||
final VirtualFilePointerContainer container = myRoots.get(type);
|
||||
if (container == null) return Collections.emptyList();
|
||||
final List<VirtualFilePointer> pointers = container.getList();
|
||||
List<String> invalidPaths = null;
|
||||
for (VirtualFilePointer pointer : pointers) {
|
||||
if (!pointer.isValid()) {
|
||||
if (invalidPaths == null) {
|
||||
invalidPaths = new SmartList<String>();
|
||||
}
|
||||
invalidPaths.add(pointer.getUrl());
|
||||
}
|
||||
}
|
||||
return invalidPaths == null ? Collections.<String>emptyList() : invalidPaths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisposed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryTable getTable() {
|
||||
return myLibraryTable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RootProvider getRootProvider() {
|
||||
return myRootProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library cloneLibrary(RootModelImpl rootModel) {
|
||||
throw new UnsupportedOperationException("'cloneLibrary' not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ModifiableModel getModifiableModel() {
|
||||
throw new UnsupportedOperationException("'getModifiableModel' not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJarDirectory(@NotNull String url) {
|
||||
return isJarDirectory(url, JarDirectories.DEFAULT_JAR_DIRECTORY_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJarDirectory(@NotNull String url, @NotNull OrderRootType rootType) {
|
||||
for (JpsLibraryRoot root : myJpsLibrary.getRoots(getJpsRootType(rootType))) {
|
||||
if (url.equals(root.getUrl()) && root.getInclusionOptions() != JpsLibraryRoot.InclusionOptions.ROOT_ITSELF) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(@NotNull String url, @NotNull OrderRootType rootType) {
|
||||
final VirtualFilePointerContainer container = myRoots.get(rootType);
|
||||
if (container == null) return false;
|
||||
final VirtualFilePointer fp = container.findByUrl(url);
|
||||
return fp != null && fp.isValid();
|
||||
}
|
||||
|
||||
private static JpsOrderRootType getJpsRootType(OrderRootType type) {
|
||||
if (type == OrderRootType.CLASSES) return JpsOrderRootType.COMPILED;
|
||||
if (type == OrderRootType.SOURCES) return JpsOrderRootType.SOURCES;
|
||||
if (type == OrderRootType.DOCUMENTATION) return JpsOrderRootType.DOCUMENTATION;
|
||||
return JpsOrderRootType.COMPILED;
|
||||
}
|
||||
|
||||
private class MyRootProvider extends RootProviderBaseImpl {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getUrls(@NotNull OrderRootType rootType) {
|
||||
Set<String> originalUrls = new LinkedHashSet<String>(Arrays.asList(JpsLibraryDelegate.this.getUrls(rootType)));
|
||||
for (VirtualFile file : getFiles(rootType)) { // Add those expanded with jar directories.
|
||||
originalUrls.add(file.getUrl());
|
||||
}
|
||||
return ArrayUtil.toStringArray(originalUrls);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
|
||||
return JpsLibraryDelegate.this.getFiles(rootType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.project.model.impl.library;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.EventDispatcher;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryCollection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryTableImpl implements LibraryTable, Disposable {
|
||||
private JpsLibrariesModel myModel;
|
||||
private final EventDispatcher<Listener> myDispatcher = EventDispatcher.create(Listener.class);
|
||||
private String myTableLevel;
|
||||
private LibraryTablePresentation myPresentation;
|
||||
|
||||
public JpsLibraryTableImpl(JpsLibraryCollection libraryCollection, String level) {
|
||||
myTableLevel = level;
|
||||
myModel = new JpsLibrariesModel(libraryCollection);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Library[] getLibraries() {
|
||||
return myModel.getLibraries();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Library> getLibraryIterator() {
|
||||
return myModel.getLibraryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library getLibraryByName(@NotNull String name) {
|
||||
return myModel.getLibraryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener) {
|
||||
myDispatcher.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener, Disposable parentDisposable) {
|
||||
myDispatcher.addListener(listener, parentDisposable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(Listener listener) {
|
||||
myDispatcher.removeListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library createLibrary() {
|
||||
return createLibrary(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library createLibrary(@NonNls String name) {
|
||||
final ModifiableModel model = getModifiableModel();
|
||||
final Library library = model.createLibrary(name);
|
||||
model.commit();
|
||||
return library;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLibrary(@NotNull Library library) {
|
||||
final ModifiableModel model = getModifiableModel();
|
||||
model.removeLibrary(library);
|
||||
model.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
for (Library library : getLibraries()) {
|
||||
Disposer.dispose(library);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModifiableModel getModifiableModel() {
|
||||
return new JpsLibrariesModel(myModel.myJpsLibraries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableLevel() {
|
||||
return myTableLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryTablePresentation getPresentation() {
|
||||
return myPresentation;
|
||||
}
|
||||
|
||||
private class JpsLibrariesModel implements LibraryTableBase.ModifiableModelEx {
|
||||
private JpsLibraryCollection myJpsLibraries;
|
||||
private List<JpsLibraryDelegate> myLibraries;
|
||||
|
||||
private JpsLibrariesModel(JpsLibraryCollection libraryCollection) {
|
||||
myLibraries = new ArrayList<JpsLibraryDelegate>();
|
||||
myJpsLibraries = libraryCollection;
|
||||
for (JpsLibrary library : libraryCollection.getLibraries()) {
|
||||
myLibraries.add(new JpsLibraryDelegate(library, JpsLibraryTableImpl.this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library createLibrary(String name) {
|
||||
return createLibrary(name, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library createLibrary(String name, @Nullable PersistentLibraryKind type) {
|
||||
throw new UnsupportedOperationException("'createLibrary' not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Library> getLibraryIterator() {
|
||||
return Collections.<Library>unmodifiableList(myLibraries).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLibrary(@NotNull Library library) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Library[] getLibraries() {
|
||||
return myLibraries.toArray(new Library[myLibraries.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library getLibraryByName(@NotNull String name) {
|
||||
for (JpsLibraryDelegate library : myLibraries) {
|
||||
if (name.equals(library.getName())) {
|
||||
return library;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
-9
@@ -31,6 +31,8 @@ import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import com.intellij.project.model.impl.module.JpsRootModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
|
||||
@@ -130,47 +132,80 @@ public class JpsContentEntry implements ContentEntry, Disposable {
|
||||
|
||||
@Override
|
||||
public SourceFolder addSourceFolder(@NotNull VirtualFile file, boolean isTestSource) {
|
||||
throw new UnsupportedOperationException("'addSourceFolder' not implemented in " + getClass().getName());
|
||||
return addSourceFolder(file, isTestSource, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFolder addSourceFolder(@NotNull VirtualFile file, boolean isTestSource, @NotNull String packagePrefix) {
|
||||
throw new UnsupportedOperationException("'addSourceFolder' not implemented in " + getClass().getName());
|
||||
return addSourceFolder(file.getUrl(), isTestSource, packagePrefix);
|
||||
}
|
||||
|
||||
private SourceFolder addSourceFolder(final String url, boolean isTestSource, String packagePrefix) {
|
||||
final JavaSourceRootType rootType = isTestSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
||||
final JpsModuleSourceRoot sourceRoot = myModule.addSourceRoot(rootType, url, new JavaSourceRootProperties(packagePrefix));
|
||||
final JpsSourceFolder sourceFolder = new JpsSourceFolder(sourceRoot, this);
|
||||
mySourceFolders.add(sourceFolder);
|
||||
return sourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFolder addSourceFolder(@NotNull String url, boolean isTestSource) {
|
||||
throw new UnsupportedOperationException("'addSourceFolder' not implemented in " + getClass().getName());
|
||||
return addSourceFolder(url, isTestSource, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSourceFolder(@NotNull SourceFolder sourceFolder) {
|
||||
throw new UnsupportedOperationException();
|
||||
final JpsSourceFolder folder = (JpsSourceFolder)sourceFolder;
|
||||
mySourceFolders.remove(folder);
|
||||
myModule.removeSourceRoot(folder.getSourceRoot().getRootType(), folder.getSourceRoot().getUrl());
|
||||
Disposer.dispose(folder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSourceFolders() {
|
||||
throw new UnsupportedOperationException();
|
||||
List<JpsModuleSourceRoot> toRemove = new ArrayList<JpsModuleSourceRoot>();
|
||||
for (JpsSourceFolder folder : mySourceFolders) {
|
||||
toRemove.add(folder.getSourceRoot());
|
||||
Disposer.dispose(folder);
|
||||
}
|
||||
mySourceFolders.clear();
|
||||
for (JpsModuleSourceRoot root : toRemove) {
|
||||
myModule.removeSourceRoot(root.getRootType(), root.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExcludeFolder addExcludeFolder(@NotNull VirtualFile file) {
|
||||
throw new UnsupportedOperationException("'addExcludeFolder' not implemented in " + getClass().getName());
|
||||
return addExcludeFolder(file.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExcludeFolder addExcludeFolder(@NotNull String url) {
|
||||
throw new UnsupportedOperationException("'addExcludeFolder' not implemented in " + getClass().getName());
|
||||
final JpsExcludeFolder folder = new JpsExcludeFolder(url, this);
|
||||
myModule.getExcludeRootsList().addUrl(url);
|
||||
myExcludeFolders.add(folder);
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeExcludeFolder(@NotNull ExcludeFolder excludeFolder) {
|
||||
throw new UnsupportedOperationException();
|
||||
JpsExcludeFolder folder = (JpsExcludeFolder)excludeFolder;
|
||||
myExcludeFolders.remove(folder);
|
||||
myModule.getExcludeRootsList().removeUrl(folder.getUrl());
|
||||
Disposer.dispose(folder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearExcludeFolders() {
|
||||
throw new UnsupportedOperationException();
|
||||
List<String> toRemove = new ArrayList<String>();
|
||||
for (JpsExcludeFolder folder : myExcludeFolders) {
|
||||
toRemove.add(folder.getUrl());
|
||||
Disposer.dispose(folder);
|
||||
}
|
||||
myExcludeFolders.clear();
|
||||
for (String url : toRemove) {
|
||||
myModule.getExcludeRootsList().removeUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
@@ -32,6 +32,10 @@ public class JpsSourceFolder extends JpsContentFolderBase implements SourceFolde
|
||||
mySourceRoot = sourceRoot;
|
||||
}
|
||||
|
||||
public JpsModuleSourceRoot getSourceRoot() {
|
||||
return mySourceRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestSource() {
|
||||
return mySourceRoot.getRootType() == JavaSourceRootType.TEST_SOURCE;
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ public abstract class JpsExportableOrderEntry<E extends JpsDependencyElement> ex
|
||||
|
||||
@Override
|
||||
public void setScope(@NotNull DependencyScope scope) {
|
||||
JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(myDependencyElement)
|
||||
.setScope(JpsJavaDependencyScope.valueOf(scope.name()));
|
||||
final JpsJavaDependencyExtension extension = JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(myDependencyElement);
|
||||
extension.setScope(JpsJavaDependencyScope.valueOf(scope.name()));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-4
@@ -18,10 +18,13 @@ package com.intellij.project.model.impl.module.dependencies;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModuleOrderEntry;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.OrderRootsEnumerator;
|
||||
import com.intellij.openapi.roots.RootPolicy;
|
||||
import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.project.model.JpsModelManager;
|
||||
import com.intellij.project.model.impl.module.JpsRootModel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
@@ -53,15 +56,23 @@ public class JpsModuleOrderEntry extends JpsExportableOrderEntry<JpsModuleDepend
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getFiles(OrderRootType type) {
|
||||
throw new UnsupportedOperationException("'getFiles' not implemented in " + getClass().getName());
|
||||
final OrderRootsEnumerator enumerator = getEnumerator(type);
|
||||
return enumerator != null ? enumerator.getRoots() : VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private OrderRootsEnumerator getEnumerator(OrderRootType type) {
|
||||
final Module module = getModule();
|
||||
if (module == null) return null;
|
||||
|
||||
return ModuleRootManagerImpl.getCachingEnumeratorForType(type, module, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getUrls(OrderRootType rootType) {
|
||||
throw new UnsupportedOperationException("'getUrls' not implemented in " + getClass().getName());
|
||||
final OrderRootsEnumerator enumerator = getEnumerator(rootType);
|
||||
return enumerator != null ? enumerator.getUrls() : ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.changes.patch.ApplyPatchAction;
|
||||
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -372,6 +373,10 @@ public class PatchApplier<BinaryType extends FilePatch> {
|
||||
}
|
||||
};
|
||||
|
||||
final LocalFileSystem lfs = LocalFileSystem.getInstance();
|
||||
for (FilePath filePath : directlyAffected) {
|
||||
lfs.refreshAndFindFileByIoFile(filePath.getIOFile());
|
||||
}
|
||||
final RefreshSession session = RefreshQueue.getInstance().createSession(false, true, new Runnable() {
|
||||
public void run() {
|
||||
if (project.isDisposed()) return;
|
||||
@@ -401,6 +406,7 @@ public class PatchApplier<BinaryType extends FilePatch> {
|
||||
final VcsDirtyScopeManager vcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
|
||||
// will schedule update
|
||||
vcsDirtyScopeManager.filePathsDirty(directlyAffected, null);
|
||||
vcsDirtyScopeManager.filesDirty(indirectlyAffected, null);
|
||||
scheduleProjectFilesReload.run();
|
||||
if (context != null) {
|
||||
context.ping();
|
||||
|
||||
@@ -686,7 +686,6 @@ public class ChangesListView extends Tree implements TypeSafeDataProvider, Advan
|
||||
final TreePath path = getPathForLocation(e.getPoint().x, e.getPoint().y);
|
||||
if (path != null) {
|
||||
setSelectionPath(path);
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class CreateXmlResourceDialog extends DialogWrapper {
|
||||
myModuleCombo.setRenderer(new ModuleListCellRendererWrapper(myModuleCombo.getRenderer()));
|
||||
}
|
||||
|
||||
final String defaultResFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType.getName());
|
||||
final String defaultResFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType);
|
||||
if (defaultResFileName != null) {
|
||||
myFileNameField.setText(defaultResFileName);
|
||||
}
|
||||
@@ -393,7 +393,18 @@ public class CreateXmlResourceDialog extends DialogWrapper {
|
||||
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myNameField.getText().length() == 0 ? myNameField : myValueField;
|
||||
if (myNameField.getText().length() == 0) {
|
||||
return myNameField;
|
||||
}
|
||||
else if (myValueField.isVisible()) {
|
||||
return myValueField;
|
||||
}
|
||||
else if (myModuleCombo.isVisible()) {
|
||||
return myModuleCombo;
|
||||
}
|
||||
else {
|
||||
return myFileNameField;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.android.dom.resources.DeclareStyleable;
|
||||
import org.jetbrains.android.dom.resources.ResourceElement;
|
||||
import org.jetbrains.android.dom.resources.Resources;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
@@ -58,10 +59,19 @@ public class ResourceNamesValidityState implements ValidityState {
|
||||
final VirtualFile file = pair.getSecond();
|
||||
|
||||
for (final ResourceType resType : AndroidResourceUtil.VALUE_RESOURCE_TYPES) {
|
||||
addValueResources(file, resType, AndroidResourceUtil.getValueResourcesFromElement(resType.getName(), resources), myResources);
|
||||
addValueResources(file, resType, AndroidResourceUtil.getValueResourcesFromElement(resType.getName(), resources), myResources, "");
|
||||
}
|
||||
addValueResources(file, ResourceType.ATTR, resources.getAttrs(), myResources, "");
|
||||
final List<DeclareStyleable> styleables = resources.getDeclareStyleables();
|
||||
addValueResources(file, ResourceType.DECLARE_STYLEABLE, styleables, myResources, "");
|
||||
|
||||
for (DeclareStyleable styleable : styleables) {
|
||||
final String styleableName = styleable.getName().getValue();
|
||||
|
||||
if (styleableName != null) {
|
||||
addValueResources(file, ResourceType.DECLARE_STYLEABLE, styleable.getAttrs(), myResources, styleableName + '_');
|
||||
}
|
||||
}
|
||||
addValueResources(file, ResourceType.ATTR, resources.getAttrs(), myResources);
|
||||
addValueResources(file, ResourceType.DECLARE_STYLEABLE, resources.getDeclareStyleables(), myResources);
|
||||
}
|
||||
|
||||
for (final VirtualFile subdir : manager.getResourceSubdirs(null)) {
|
||||
@@ -94,7 +104,8 @@ public class ResourceNamesValidityState implements ValidityState {
|
||||
private static void addValueResources(VirtualFile file,
|
||||
ResourceType resType,
|
||||
Collection<? extends ResourceElement> resourceElements,
|
||||
Map<String, ResourceFileData> result) {
|
||||
Map<String, ResourceFileData> result,
|
||||
String namePrefix) {
|
||||
for (ResourceElement element : resourceElements) {
|
||||
final String name = element.getName().getValue();
|
||||
|
||||
@@ -104,7 +115,7 @@ public class ResourceNamesValidityState implements ValidityState {
|
||||
data = new ResourceFileData();
|
||||
result.put(file.getPath(), data);
|
||||
}
|
||||
data.addValueResource(new ResourceEntry(resType.getName(), name));
|
||||
data.addValueResource(new ResourceEntry(resType.getName(), namePrefix + name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,10 @@ public interface Resources extends AndroidDomElement {
|
||||
StringArray addStringArray();
|
||||
|
||||
List<DeclareStyleable> getDeclareStyleables();
|
||||
DeclareStyleable addDeclareStyleable();
|
||||
|
||||
List<Attr> getAttrs();
|
||||
Attr addAttr();
|
||||
|
||||
List<Item> getItems();
|
||||
Item addItem();
|
||||
|
||||
@@ -51,13 +51,9 @@ public class AndroidQuickFixProvider extends UnresolvedReferenceQuickFixProvider
|
||||
final String resClassName = pair.getFirst();
|
||||
final String resFieldName = pair.getSecond();
|
||||
|
||||
final ResourceType resourceType = ResourceType.getEnum(resClassName);
|
||||
if (resourceType == ResourceType.STYLEABLE || resourceType == ResourceType.ATTR) {
|
||||
// todo: support
|
||||
return;
|
||||
}
|
||||
ResourceType resourceType = ResourceType.getEnum(resClassName);
|
||||
|
||||
if (AndroidResourceUtil.VALUE_RESOURCE_TYPES.contains(resourceType)) {
|
||||
if (AndroidResourceUtil.ALL_VALUE_RESOURCE_TYPES.contains(resourceType)) {
|
||||
registrar
|
||||
.register(new CreateValueResourceQuickFix(facet, resourceType, resFieldName, contextFile, true));
|
||||
}
|
||||
|
||||
+6
-4
@@ -49,7 +49,7 @@ public class CreateValueResourceQuickFix implements LocalQuickFix, IntentionActi
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return AndroidBundle.message("create.value.resource.quickfix.name", myResourceName,
|
||||
AndroidResourceUtil.getDefaultResourceFileName(myResourceType.getName()));
|
||||
AndroidResourceUtil.getDefaultResourceFileName(myResourceType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -75,7 +75,7 @@ public class CreateValueResourceQuickFix implements LocalQuickFix, IntentionActi
|
||||
|
||||
protected boolean doInvoke() {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
final String fileName = AndroidResourceUtil.getDefaultResourceFileName(myResourceType.getName());
|
||||
final String fileName = AndroidResourceUtil.getDefaultResourceFileName(myResourceType);
|
||||
assert fileName != null;
|
||||
|
||||
if (!AndroidResourceUtil.createValueResource(myFacet.getModule(), myResourceName, myResourceType, fileName,
|
||||
@@ -84,8 +84,10 @@ public class CreateValueResourceQuickFix implements LocalQuickFix, IntentionActi
|
||||
}
|
||||
}
|
||||
else {
|
||||
final CreateXmlResourceDialog dialog = new CreateXmlResourceDialog(myFacet.getModule(), myResourceType, myResourceName, null,
|
||||
myChooseName);
|
||||
final String value = myResourceType == ResourceType.STYLEABLE ||
|
||||
myResourceType == ResourceType.ATTR ? "\n" : null;
|
||||
final CreateXmlResourceDialog dialog =
|
||||
new CreateXmlResourceDialog(myFacet.getModule(), myResourceType, myResourceName, value, myChooseName);
|
||||
dialog.setTitle("New " + StringUtil.capitalize(myResourceType.getDisplayName()) + " Value Resource");
|
||||
dialog.show();
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
final String normalizedAppName = AndroidResourceUtil.normalizeXmlResourceValue(myApplicationName.replace("\\", "\\\\"));
|
||||
|
||||
if (appNameResElement == null) {
|
||||
final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.STRING.getName());
|
||||
final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.STRING);
|
||||
assert fileName != null;
|
||||
AndroidResourceUtil.createValueResource(facet.getModule(), appNameResource, ResourceType.STRING, fileName, Collections
|
||||
.singletonList(AndroidConstants.FD_RES_VALUES), normalizedAppName);
|
||||
|
||||
@@ -99,11 +99,6 @@ public class AndroidResourceUtil {
|
||||
ALL_VALUE_RESOURCE_TYPES.add(ResourceType.STYLEABLE);
|
||||
}
|
||||
|
||||
public static boolean isValueResourceType(@NotNull String resTypeName) {
|
||||
final ResourceType type = ResourceType.getEnum(resTypeName);
|
||||
return type != null && VALUE_RESOURCE_TYPES.contains(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiField[] findResourceFields(@NotNull AndroidFacet facet,
|
||||
@NotNull String resClassName,
|
||||
@@ -384,38 +379,36 @@ public class AndroidResourceUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceElement addValueResource(@NotNull final String type, @NotNull final Resources resources) {
|
||||
if (type.equals("string")) {
|
||||
return resources.addString();
|
||||
public static ResourceElement addValueResource(@NotNull final ResourceType resType, @NotNull final Resources resources) {
|
||||
switch (resType) {
|
||||
case STRING:
|
||||
return resources.addString();
|
||||
case DIMEN:
|
||||
return resources.addDimen();
|
||||
case COLOR:
|
||||
return resources.addColor();
|
||||
case DRAWABLE:
|
||||
return resources.addDrawable();
|
||||
case STYLE:
|
||||
return resources.addStyle();
|
||||
case ARRAY:
|
||||
// todo: choose among string-array, integer-array and array
|
||||
return resources.addStringArray();
|
||||
case INTEGER:
|
||||
return resources.addInteger();
|
||||
case BOOL:
|
||||
return resources.addBool();
|
||||
case ID:
|
||||
final Item item = resources.addItem();
|
||||
item.getType().setValue("id");
|
||||
return item;
|
||||
case ATTR:
|
||||
return resources.addAttr();
|
||||
case STYLEABLE:
|
||||
return resources.addDeclareStyleable();
|
||||
default:
|
||||
throw new IllegalArgumentException("Incorrect resource type");
|
||||
}
|
||||
else if (type.equals("dimen")) {
|
||||
return resources.addDimen();
|
||||
}
|
||||
else if (type.equals("color")) {
|
||||
return resources.addColor();
|
||||
}
|
||||
else if (type.equals("drawable")) {
|
||||
return resources.addDrawable();
|
||||
}
|
||||
else if (type.equals("style")) {
|
||||
return resources.addStyle();
|
||||
}
|
||||
else if (type.equals("array")) {
|
||||
// todo: choose among string-array, integer-array and array
|
||||
return resources.addStringArray();
|
||||
}
|
||||
else if (type.equals("integer")) {
|
||||
return resources.addInteger();
|
||||
}
|
||||
else if (type.equals("bool")) {
|
||||
return resources.addBool();
|
||||
}
|
||||
else if (type.equals("id")) {
|
||||
Item item = resources.addItem();
|
||||
item.getType().setValue("id");
|
||||
return item;
|
||||
}
|
||||
throw new IllegalArgumentException("Incorrect resource type");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -443,8 +436,15 @@ public class AndroidResourceUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getDefaultResourceFileName(@NotNull String resourceType) {
|
||||
return isValueResourceType(resourceType) ? resourceType + "s.xml" : null;
|
||||
public static String getDefaultResourceFileName(@NotNull ResourceType type) {
|
||||
if (VALUE_RESOURCE_TYPES.contains(type)) {
|
||||
return type.getName() + "s.xml";
|
||||
}
|
||||
if (ResourceType.ATTR == type ||
|
||||
ResourceType.STYLEABLE == type) {
|
||||
return "attrs.xml";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -667,12 +667,17 @@ public class AndroidResourceUtil {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Resources resources : resourcesElements) {
|
||||
final ResourceElement element = addValueResource(resourceType.getName(), resources);
|
||||
final ResourceElement element = addValueResource(resourceType, resources);
|
||||
element.getName().setValue(resourceName);
|
||||
|
||||
if (value.length() > 0) {
|
||||
element.setStringValue(value);
|
||||
}
|
||||
else if (resourceType == ResourceType.STYLEABLE ||
|
||||
resourceType == ResourceType.STYLE) {
|
||||
element.setStringValue("value");
|
||||
element.getXmlTag().getValue().setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -71,10 +71,12 @@ public class GitChangeProvider implements ChangeProvider {
|
||||
}
|
||||
|
||||
final Collection<VirtualFile> affected = dirtyScope.getAffectedContentRootsWithCheck();
|
||||
if (dirtyScope.getAffectedContentRoots().size() != affected.size()) {
|
||||
final Collection<VirtualFile> affectedContentRoots = dirtyScope.getAffectedContentRoots();
|
||||
if (affectedContentRoots.size() != affected.size()) {
|
||||
final Set<VirtualFile> set = new HashSet<VirtualFile>(affected);
|
||||
set.removeAll(dirtyScope.getAffectedContentRoots());
|
||||
set.removeAll(affectedContentRoots);
|
||||
for (VirtualFile file : set) {
|
||||
debug("adding git root for check: " + file.getPath());
|
||||
((VcsModifiableDirtyScope) dirtyScope).addDirtyDirRecursively(new FilePathImpl(file));
|
||||
}
|
||||
}
|
||||
@@ -84,13 +86,16 @@ public class GitChangeProvider implements ChangeProvider {
|
||||
final MyNonChangedHolder holder = new MyNonChangedHolder(myProject, dirtyScope.getDirtyFilesNoExpand(), addGate,
|
||||
myFileDocumentManager, myVcsManager);
|
||||
for (VirtualFile root : roots) {
|
||||
debug("checking root: " + root.getPath());
|
||||
GitChangesCollector collector = isNewGitChangeProviderAvailable()
|
||||
? GitNewChangesCollector.collect(myProject, myGit, myChangeListManager, myVcsManager,
|
||||
vcs, dirtyScope, root)
|
||||
: GitOldChangesCollector.collect(myProject, myChangeListManager, myVcsManager,
|
||||
vcs, dirtyScope, root);
|
||||
holder.changed(collector.getChanges());
|
||||
for (Change file : collector.getChanges()) {
|
||||
final Collection<Change> changes = collector.getChanges();
|
||||
holder.changed(changes);
|
||||
for (Change file : changes) {
|
||||
debug("process change: " + ChangesUtil.getFilePath(file).getPath());
|
||||
builder.processChange(file, GitVcs.getKey());
|
||||
}
|
||||
for (VirtualFile f : collector.getUnversionedFiles()) {
|
||||
@@ -101,6 +106,7 @@ public class GitChangeProvider implements ChangeProvider {
|
||||
}
|
||||
}
|
||||
catch (VcsException e) {
|
||||
PROFILE_LOG.info(e);
|
||||
// most probably the error happened because git is not configured
|
||||
vcs.getExecutableValidator().showNotificationOrThrow(e);
|
||||
}
|
||||
|
||||
@@ -45,10 +45,6 @@ class GitMockProjectRootManager extends ProjectRootManager {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
VirtualFile[] getFilesFromAllModules(OrderRootType type) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
OrderEnumerator orderEntries() {
|
||||
|
||||
+20
-2
@@ -28,6 +28,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
|
||||
|
||||
/**
|
||||
@@ -49,11 +50,11 @@ public class GrSplitDeclarationIntention extends Intention {
|
||||
element.getParent().addAfter(assignment, element);
|
||||
}
|
||||
}
|
||||
else if (variables.length>1) {
|
||||
else if (variables.length > 1) {
|
||||
String modifiers = ((GrVariableDeclaration)element).getModifierList().getText();
|
||||
GrStatement[] sts = new GrStatement[variables.length];
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
sts[i] = GroovyPsiElementFactory.getInstance(project).createStatementFromText(modifiers + " " + variables[i].getText());
|
||||
sts[i] = createVarDeclaration(project, variables[i], modifiers);
|
||||
}
|
||||
|
||||
element = GroovyRefactoringUtil.addBlockIntoParent(element);
|
||||
@@ -61,10 +62,27 @@ public class GrSplitDeclarationIntention extends Intention {
|
||||
for (int i = sts.length - 1; i >= 0; i--) {
|
||||
element.getParent().addAfter(sts[i], element);
|
||||
}
|
||||
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static GrStatement createVarDeclaration(Project project, GrVariable variable, String modifiers) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(modifiers).append(' ');
|
||||
GrTypeElement typeElement = variable.getTypeElementGroovy();
|
||||
if (typeElement != null) {
|
||||
builder.append(typeElement.getText()).append(' ');
|
||||
}
|
||||
builder.append(variable.getName());
|
||||
GrExpression initializer = variable.getInitializerGroovy();
|
||||
if (initializer != null) {
|
||||
builder.append('=').append(initializer.getText());
|
||||
}
|
||||
return GroovyPsiElementFactory.getInstance(project).createStatementFromText(builder.toString());
|
||||
}
|
||||
|
||||
private String myText = "";
|
||||
|
||||
@NotNull
|
||||
|
||||
+10
-13
@@ -298,14 +298,11 @@ public class GroovyEnterHandler extends EnterHandlerDelegateAdapter {
|
||||
TextRange literalRange = stringElement.getTextRange();
|
||||
|
||||
//the case of print '\<caret>'
|
||||
if (fileText.charAt(caretOffset) == '\'' && caretOffset > 0 && fileText.charAt(caretOffset - 1) == '\\') {
|
||||
convertEndToMultiline(caretOffset, document, fileText, '\'');
|
||||
}
|
||||
else {
|
||||
if (!isSlashBeforeCaret(caretOffset, fileText)) {
|
||||
convertEndToMultiline(literalRange.getEndOffset(), document, fileText, '\'');
|
||||
document.insertString(literalRange.getStartOffset(), "''");
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 2);
|
||||
}
|
||||
document.insertString(literalRange.getStartOffset(), "''");
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 2);
|
||||
EditorModificationUtil.insertStringAtCaret(editor, "\n");
|
||||
}
|
||||
else {
|
||||
@@ -331,15 +328,11 @@ public class GroovyEnterHandler extends EnterHandlerDelegateAdapter {
|
||||
boolean rightFromDollar = exprSibling instanceof GrExpression && exprSibling.getTextRange().getStartOffset() == caretOffset;
|
||||
if (rightFromDollar) caretOffset--;
|
||||
TextRange parentRange = parent.getTextRange();
|
||||
//the case of print '\<caret>'
|
||||
if (fileText.charAt(caretOffset) == '\"' && caretOffset > 0 && fileText.charAt(caretOffset - 1) == '\\') {
|
||||
convertEndToMultiline(caretOffset, document, fileText, '"');
|
||||
}
|
||||
else {
|
||||
if (rightFromDollar || !isSlashBeforeCaret(caretOffset, fileText)) {
|
||||
convertEndToMultiline(parent.getTextRange().getEndOffset(), document, fileText, '"');
|
||||
document.insertString(parentRange.getStartOffset(), "\"\"");
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 2);
|
||||
}
|
||||
document.insertString(parentRange.getStartOffset(), "\"\"");
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 2);
|
||||
EditorModificationUtil.insertStringAtCaret(editor, "\n");
|
||||
if (rightFromDollar) {
|
||||
editor.getCaretModel().moveCaretRelatively(1, 0, false, false, true);
|
||||
@@ -378,6 +371,10 @@ public class GroovyEnterHandler extends EnterHandlerDelegateAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSlashBeforeCaret(int caretOffset, String fileText) {
|
||||
return caretOffset > 0 && fileText.charAt(caretOffset - 1) == '\\';
|
||||
}
|
||||
|
||||
private static void insertLineFeedInString(Editor editor,
|
||||
DataContext dataContext,
|
||||
EditorActionHandler originalHandler,
|
||||
|
||||
+35
-3
@@ -30,6 +30,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
@@ -44,9 +45,11 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrM
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
|
||||
@@ -151,13 +154,42 @@ public class GroovyExpectedTypesProvider {
|
||||
|
||||
public void visitVariable(GrVariable variable) {
|
||||
if (myExpression.equals(variable.getInitializerGroovy())) {
|
||||
PsiType type = variable.getDeclaredType();
|
||||
if (type != null) {
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(type, type)};
|
||||
PsiType type = variable.getType();
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(type, type)};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamedArgument(GrNamedArgument argument) {
|
||||
PsiElement pparent = argument.getParent().getParent();
|
||||
if (pparent instanceof GrCall && resolvesToDefaultConstructor(((GrCall)pparent))) {
|
||||
GrArgumentLabel label = argument.getLabel();
|
||||
if (label != null) {
|
||||
PsiElement resolved = label.resolve();
|
||||
if (resolved instanceof PsiField) {
|
||||
PsiType type = ((PsiField)resolved).getType();
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(type, type)};
|
||||
}
|
||||
else if (resolved instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertySetter((PsiMethod)resolved)) {
|
||||
PsiType type = ((PsiMethod)resolved).getParameterList().getParameters()[0].getType();
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(type,type)};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean resolvesToDefaultConstructor(GrCall call) {
|
||||
PsiMethod method = call.resolveMethod();
|
||||
if (method != null && method.isConstructor() && method.getParameterList().getParametersCount() == 0) return true;
|
||||
|
||||
if (call instanceof GrConstructorCall) {
|
||||
PsiElement resolved = PsiImplUtil.extractUniqueResult(((GrConstructorCall)call).multiResolveClass()).getElement();
|
||||
if (resolved instanceof PsiClass) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void visitMethodCallExpression(GrMethodCallExpression methodCall) {
|
||||
final GrExpression invokedExpression = methodCall.getInvokedExpression();
|
||||
if (myExpression.equals(invokedExpression)) {
|
||||
|
||||
+3
-1
@@ -366,7 +366,8 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
public GroovyResolveResult[] resolve(@NotNull GrCodeReferenceElementImpl reference, boolean incompleteCode) {
|
||||
if (reference.getReferenceName() == null) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
final GroovyResolveResult[] results = _resolve(reference, reference.getManager(), reference.getKind(false));
|
||||
if (results == null) return results;
|
||||
if (results.length == 0) return results;
|
||||
|
||||
List<GroovyResolveResult> imported = new ArrayList<GroovyResolveResult>();
|
||||
final PsiType[] args = reference.getTypeArguments();
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
@@ -390,6 +391,7 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
return results;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static GroovyResolveResult[] _resolve(GrCodeReferenceElementImpl ref, PsiManager manager, ReferenceKind kind) {
|
||||
final String refName = ref.getReferenceName();
|
||||
if (refName == null) {
|
||||
|
||||
@@ -390,3 +390,84 @@ subpartition
|
||||
subpartitions
|
||||
subst
|
||||
substring
|
||||
subtree
|
||||
subtrees
|
||||
subview
|
||||
subviews
|
||||
superclass
|
||||
superclasses
|
||||
superview
|
||||
superviews
|
||||
symlink
|
||||
symlinks
|
||||
sysdate
|
||||
systimestamp
|
||||
tablespace
|
||||
taglib
|
||||
temptable
|
||||
throwable
|
||||
timestamp
|
||||
tinyblob
|
||||
tinyint
|
||||
tinytext
|
||||
todo
|
||||
toggleable
|
||||
tokenize
|
||||
tokenizer
|
||||
tooltip
|
||||
tooltips
|
||||
trebuchet
|
||||
twitter
|
||||
typedef
|
||||
typedefs
|
||||
unboxing
|
||||
uncomment
|
||||
uncommented
|
||||
underwave
|
||||
undoable
|
||||
undofile
|
||||
unhandled
|
||||
uninstall
|
||||
unpivot
|
||||
unprotect
|
||||
unwatch
|
||||
uploader
|
||||
urowid
|
||||
username
|
||||
utf
|
||||
util
|
||||
utils
|
||||
uuid
|
||||
validator
|
||||
validators
|
||||
vararg
|
||||
varargs
|
||||
varbinary
|
||||
varchar
|
||||
varcharacter
|
||||
varray
|
||||
verdana
|
||||
versa
|
||||
vertices
|
||||
watchlist
|
||||
webservice
|
||||
whitespace
|
||||
whitespaces
|
||||
wifi
|
||||
wiki
|
||||
wildcard
|
||||
wildcards
|
||||
wordwrap
|
||||
workflow
|
||||
wsdl
|
||||
xcode
|
||||
xcodeproj
|
||||
xhtml
|
||||
xmlschema
|
||||
xmlschemas
|
||||
xmltype
|
||||
xpath
|
||||
xslt
|
||||
youtube
|
||||
zend
|
||||
zerofill
|
||||
|
||||
@@ -588,7 +588,7 @@
|
||||
<category>Declaration</category>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.intention.impl.CreateAssignFieldsFromParametersAction</className>
|
||||
<className>com.intellij.codeInsight.intention.impl.BindFieldsFromParametersAction</className>
|
||||
<category>Declaration</category>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
@@ -710,6 +710,13 @@
|
||||
<category>Other</category>
|
||||
</intentionAction>
|
||||
|
||||
<!--<intentionAction>-->
|
||||
<!--<className>com.intellij.codeInsight.intention.impl.ReplaceCastAction</className>-->
|
||||
<!--<category>Other</category>-->
|
||||
<!--</intentionAction>-->
|
||||
|
||||
|
||||
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInspection.concurrencyAnnotations.JCiPOrderEntryFix</className>
|
||||
</intentionAction>
|
||||
|
||||
Reference in New Issue
Block a user