private static final boolean GENERATE_CLASSPATH_INDEX = "true".equals(System.getProperty("generate.classpath.index"));
private static final String PROP_PERFORM_INITIAL_REFRESH = "compiler.perform.outputs.refresh.on.start";
- private boolean myInitialRefreshPerformed = false;
+ private static final Key<Boolean> REFRESH_DONE_KEY = Key.create("_compiler.initial.refresh.done_");
private static final FileProcessingCompilerAdapterFactory FILE_PROCESSING_COMPILER_ADAPTER_FACTORY = new FileProcessingCompilerAdapterFactory() {
public FileProcessingCompilerAdapter create(CompileContext context, FileProcessingCompiler compiler) {
}
boolean needRecalcOutputDirs = false;
- if (Registry.is(PROP_PERFORM_INITIAL_REFRESH) || !myInitialRefreshPerformed) {
- myInitialRefreshPerformed = true;
+ if (Registry.is(PROP_PERFORM_INITIAL_REFRESH) || !Boolean.valueOf(REFRESH_DONE_KEY.get(myProject, Boolean.FALSE))) {
+ REFRESH_DONE_KEY.set(myProject, Boolean.TRUE);
final long refreshStart = System.currentTimeMillis();
//need this to make sure the VFS is built
import com.intellij.openapi.project.ProjectManagerAdapter;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.startup.StartupManager;
-import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.Trinity;
+import com.intellij.openapi.util.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.newvfs.FileAttribute;
}
public void updateOutputRootsLayout(Project project) {
- final TIntObjectHashMap<Pair<Integer, Integer>> map = buildOutputRootsLayout(project);
+ final TIntObjectHashMap<Pair<Integer, Integer>> map = buildOutputRootsLayout(new ProjectRef(project));
synchronized (myProjectOutputRoots) {
myProjectOutputRoots.put(getProjectId(project), map);
}
}
}
- private TIntObjectHashMap<Pair<Integer, Integer>> buildOutputRootsLayout(Project project) {
+ private TIntObjectHashMap<Pair<Integer, Integer>> buildOutputRootsLayout(ProjectRef projRef) {
final TIntObjectHashMap<Pair<Integer, Integer>> map = new TIntObjectHashMap<Pair<Integer, Integer>>();
- for (Module module : ModuleManager.getInstance(project).getModules()) {
+ for (Module module : ModuleManager.getInstance(projRef.get()).getModules()) {
final CompilerModuleExtension manager = CompilerModuleExtension.getInstance(module);
if (manager != null) {
final VirtualFile output = manager.getCompilerOutputPath();
}
// made public for tests
- public void scanSourceContent(final Project project, final Collection<VirtualFile> roots, final int totalRootCount, final boolean isNewRoots) {
+ public void scanSourceContent(final ProjectRef projRef, final Collection<VirtualFile> roots, final int totalRootCount, final boolean isNewRoots) {
if (roots.size() == 0) {
return;
}
- final int projectId = getProjectId(project);
+ final int projectId = getProjectId(projRef.get());
- final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
+ final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(projRef.get()).getFileIndex();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
int processed = 0;
for (VirtualFile srcRoot : roots) {
if (indicator != null) {
+ projRef.get();
indicator.setText2(srcRoot.getPresentableUrl());
indicator.setFraction(++processed / (double)totalRootCount);
}
}
}
}
+ else {
+ projRef.get();
+ }
return true;
}
});
final int fileId = getFileId(file);
if (fileId > 0 /*file is valid*/) {
if (file.isDirectory()) {
+ projRef.get();
for (VirtualFile child : file.getChildren()) {
processFile(child);
}
}
}
- private void markOldOutputRoots(final Project project, final TIntObjectHashMap<Pair<Integer, Integer>> currentLayout) {
- final int projectId = getProjectId(project);
+ private void markOldOutputRoots(final ProjectRef projRef, final TIntObjectHashMap<Pair<Integer, Integer>> currentLayout) {
+ final int projectId = getProjectId(projRef.get());
final TIntHashSet rootsToMark = new TIntHashSet();
synchronized (myProjectOutputRoots) {
public void run() {
new Task.Backgroundable(project, CompilerBundle.message("compiler.initial.scanning.progress.text"), false) {
public void run(@NotNull final ProgressIndicator indicator) {
+ final ProjectRef projRef = new ProjectRef(project);
try {
- if (project.isDisposed()) {
- return;
- }
final IntermediateOutputCompiler[] compilers =
- CompilerManager.getInstance(project).getCompilers(IntermediateOutputCompiler.class);
+ CompilerManager.getInstance(projRef.get()).getCompilers(IntermediateOutputCompiler.class);
final Set<VirtualFile> intermediateRoots = new HashSet<VirtualFile>();
if (compilers.length > 0) {
- final Module[] modules = ModuleManager.getInstance(project).getModules();
+ final Module[] modules = ModuleManager.getInstance(projRef.get()).getModules();
for (IntermediateOutputCompiler compiler : compilers) {
for (Module module : modules) {
if (module.isDisposed()) {
}
}
- final List<VirtualFile> projectRoots = Arrays.asList(ProjectRootManager.getInstance(project).getContentSourceRoots());
+ final List<VirtualFile> projectRoots = Arrays.asList(ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots());
final int totalRootsCount = projectRoots.size() + intermediateRoots.size();
- scanSourceContent(project, projectRoots, totalRootsCount, true);
+ scanSourceContent(projRef, projectRoots, totalRootsCount, true);
if (!intermediateRoots.isEmpty()) {
final FileProcessor processor = new FileProcessor() {
};
int processed = projectRoots.size();
for (VirtualFile root : intermediateRoots) {
+ projRef.get();
indicator.setText2(root.getPresentableUrl());
indicator.setFraction(++processed / (double)totalRootsCount);
processRecursively(root, false, processor);
}
}
-
- markOldOutputRoots(project, buildOutputRootsLayout(project));
+
+ markOldOutputRoots(projRef, buildOutputRootsLayout(projRef));
+ }
+ catch (ProjectRef.ProjectClosedException swallowed) {
}
finally {
synchronized (myInitializationLock) {
});
}
-
private class MyProjectManagerListener extends ProjectManagerAdapter {
final Map<Project, MessageBusConnection> myConnections = new HashMap<Project, MessageBusConnection>();
public void projectOpened(final Project project) {
final MessageBusConnection conn = project.getMessageBus().connect();
myConnections.put(project, conn);
+ final ProjectRef projRef = new ProjectRef(project);
conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
private VirtualFile[] myRootsBefore;
public void beforeRootsChange(final ModuleRootEvent event) {
- myRootsBefore = ProjectRootManager.getInstance(project).getContentSourceRoots();
+ try {
+ myRootsBefore = ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots();
+ }
+ catch (ProjectRef.ProjectClosedException e) {
+ myRootsBefore = null;
+ }
}
public void rootsChanged(final ModuleRootEvent event) {
- final VirtualFile[] rootsAfter = ProjectRootManager.getInstance(project).getContentSourceRoots();
-
- {
- final Set<VirtualFile> newRoots = new HashSet<VirtualFile>();
- ContainerUtil.addAll(newRoots, rootsAfter);
- if (myRootsBefore != null) {
- newRoots.removeAll(Arrays.asList(myRootsBefore));
- }
- scanSourceContent(project, newRoots, newRoots.size(), true);
- }
-
- {
- final Set<VirtualFile> oldRoots = new HashSet<VirtualFile>();
- if (myRootsBefore != null) {
- ContainerUtil.addAll(oldRoots, myRootsBefore);
+ try {
+ try {
+ final VirtualFile[] rootsAfter = ProjectRootManager.getInstance(projRef.get()).getContentSourceRoots();
+
+ {
+ final Set<VirtualFile> newRoots = new HashSet<VirtualFile>();
+ ContainerUtil.addAll(newRoots, rootsAfter);
+ if (myRootsBefore != null) {
+ newRoots.removeAll(Arrays.asList(myRootsBefore));
+ }
+ scanSourceContent(projRef, newRoots, newRoots.size(), true);
+ }
+
+ {
+ final Set<VirtualFile> oldRoots = new HashSet<VirtualFile>();
+ if (myRootsBefore != null) {
+ ContainerUtil.addAll(oldRoots, myRootsBefore);
+ }
+ if (!oldRoots.isEmpty()) {
+ oldRoots.removeAll(Arrays.asList(rootsAfter));
+ }
+ scanSourceContent(projRef, oldRoots, oldRoots.size(), false);
+ }
}
- if (!oldRoots.isEmpty()) {
- oldRoots.removeAll(Arrays.asList(rootsAfter));
+ finally {
+ myRootsBefore = null;
}
- scanSourceContent(project, oldRoots, oldRoots.size(), false);
- }
- myRootsBefore = null;
- markOldOutputRoots(project, buildOutputRootsLayout(project));
+ markOldOutputRoots(projRef, buildOutputRootsLayout(projRef));
+ }
+ catch (ProjectRef.ProjectClosedException e) {
+ LOG.info(e);
+ }
}
});
}
}
+ public static final class ProjectRef extends Ref<Project> {
+ static class ProjectClosedException extends RuntimeException {
+ }
+
+ public ProjectRef() {
+ }
+
+ public ProjectRef(Project project) {
+ super(project);
+ }
+
+ public Project get() {
+ final Project project = super.get();
+ if (project != null && project.isDisposed()) {
+ throw new ProjectClosedException();
+ }
+ return project;
+ }
+ }
+
}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.WriteAction;
+import com.intellij.openapi.module.ConfigurationErrorDescription;
+import com.intellij.openapi.project.Project;
+import com.intellij.packaging.artifacts.ArtifactManager;
+import com.intellij.packaging.artifacts.ModifiableArtifactModel;
+
+/**
+ * @author nik
+ */
+public class ArtifactLoadingErrorDescription extends ConfigurationErrorDescription {
+ private final Project myProject;
+ private final InvalidArtifact myArtifact;
+
+ public ArtifactLoadingErrorDescription(Project project, InvalidArtifact artifact) {
+ super(artifact.getName(), "artifact", artifact.getErrorMessage());
+ myProject = project;
+ myArtifact = artifact;
+ }
+
+ @Override
+ public void removeInvalidElement() {
+ final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel();
+ model.removeArtifact(myArtifact);
+ new WriteAction() {
+ protected void run(final Result result) {
+ model.commit();
+ }
+ }.execute();
+ }
+
+ @Override
+ public String getRemoveConfirmationMessage() {
+ return "Would you like to remove artifact '" + myArtifact.getName() + "?";
+ }
+
+ @Override
+ public boolean isValid() {
+ return ArtifactManager.getInstance(myProject).getAllArtifactsIncludingInvalid().contains(myArtifact);
+ }
+}
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.module.ProjectLoadingErrorsNotifier;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
import com.intellij.openapi.util.ModificationTracker;
return myModel.getArtifactsByType(type);
}
+ @Override
+ public List<? extends Artifact> getAllArtifactsIncludingInvalid() {
+ return myModel.getAllArtifactsIncludingInvalid();
+ }
+
public ArtifactManagerState getState() {
final ArtifactManagerState state = new ArtifactManagerState();
- for (Artifact artifact : getArtifacts()) {
- final ArtifactState artifactState = new ArtifactState();
- artifactState.setBuildOnMake(artifact.isBuildOnMake());
- artifactState.setName(artifact.getName());
- artifactState.setOutputPath(artifact.getOutputPath());
- artifactState.setRootElement(serializePackagingElement(artifact.getRootElement()));
- artifactState.setArtifactType(artifact.getArtifactType().getId());
- for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) {
- final ArtifactPropertiesState propertiesState = serializeProperties(provider, artifact.getProperties(provider));
- if (propertiesState != null) {
- artifactState.getPropertiesList().add(propertiesState);
- }
+ for (Artifact artifact : getAllArtifactsIncludingInvalid()) {
+ final ArtifactState artifactState;
+ if (artifact instanceof InvalidArtifact) {
+ artifactState = ((InvalidArtifact)artifact).getState();
}
- Collections.sort(artifactState.getPropertiesList(), new Comparator<ArtifactPropertiesState>() {
- public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) {
- return o1.getId().compareTo(o2.getId());
+ else {
+ artifactState = new ArtifactState();
+ artifactState.setBuildOnMake(artifact.isBuildOnMake());
+ artifactState.setName(artifact.getName());
+ artifactState.setOutputPath(artifact.getOutputPath());
+ artifactState.setRootElement(serializePackagingElement(artifact.getRootElement()));
+ artifactState.setArtifactType(artifact.getArtifactType().getId());
+ for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) {
+ final ArtifactPropertiesState propertiesState = serializeProperties(provider, artifact.getProperties(provider));
+ if (propertiesState != null) {
+ artifactState.getPropertiesList().add(propertiesState);
+ }
}
- });
+ Collections.sort(artifactState.getPropertiesList(), new Comparator<ArtifactPropertiesState>() {
+ public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) {
+ return o1.getId().compareTo(o2.getId());
+ }
+ });
+ }
state.getArtifacts().add(artifactState);
}
return state;
return element;
}
- private <T> PackagingElement<T> deserializeElement(Element element) {
+ private <T> PackagingElement<T> deserializeElement(Element element) throws UnknownPackagingElementTypeException {
final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE);
PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id);
+ if (type == null) {
+ throw new UnknownPackagingElementTypeException(id);
+ }
+
PackagingElement<T> packagingElement = (PackagingElement<T>)type.createEmpty(myProject);
T state = packagingElement.getState();
if (state != null) {
public void loadState(ArtifactManagerState managerState) {
final List<ArtifactImpl> artifacts = new ArrayList<ArtifactImpl>();
for (ArtifactState state : managerState.getArtifacts()) {
- final Element element = state.getRootElement();
- ArtifactType type = ArtifactType.findById(state.getArtifactType());
- if (type == null) {
- LOG.info("Unknown artifact type: " + state.getArtifactType());
- continue;
- }
-
- final String artifactName = state.getName();
- final CompositePackagingElement<?> rootElement;
- if (element != null) {
- rootElement = (CompositePackagingElement<?>)deserializeElement(element);
- }
- else {
- rootElement = type.createRootElement(artifactName);
- }
-
- final ArtifactImpl artifact = new ArtifactImpl(artifactName, type, state.isBuildOnMake(), rootElement, state.getOutputPath());
- final List<ArtifactPropertiesState> propertiesList = state.getPropertiesList();
- for (ArtifactPropertiesState propertiesState : propertiesList) {
- final ArtifactPropertiesProvider provider = ArtifactPropertiesProvider.findById(propertiesState.getId());
- if (provider != null) {
- deserializeProperties(artifact.getProperties(provider), propertiesState);
- }
- }
- artifacts.add(artifact);
+ artifacts.add(loadArtifact(state));
}
if (myLoaded) {
}
}
+ private ArtifactImpl loadArtifact(ArtifactState state) {
+ ArtifactType type = ArtifactType.findById(state.getArtifactType());
+ if (type == null) {
+ return createInvalidArtifact(state, "Unknown artifact type: " + state.getArtifactType());
+ }
+
+ final Element element = state.getRootElement();
+ final String artifactName = state.getName();
+ final CompositePackagingElement<?> rootElement;
+ if (element != null) {
+ try {
+ rootElement = (CompositePackagingElement<?>)deserializeElement(element);
+ }
+ catch (UnknownPackagingElementTypeException e) {
+ return createInvalidArtifact(state, "Unknown element: " + e.getTypeId());
+ }
+ }
+ else {
+ rootElement = type.createRootElement(artifactName);
+ }
+
+ final ArtifactImpl artifact = new ArtifactImpl(artifactName, type, state.isBuildOnMake(), rootElement, state.getOutputPath());
+ final List<ArtifactPropertiesState> propertiesList = state.getPropertiesList();
+ for (ArtifactPropertiesState propertiesState : propertiesList) {
+ final ArtifactPropertiesProvider provider = ArtifactPropertiesProvider.findById(propertiesState.getId());
+ if (provider != null) {
+ deserializeProperties(artifact.getProperties(provider), propertiesState);
+ }
+ else {
+ return createInvalidArtifact(state, "Unknown artifact properties: " + propertiesState.getId());
+ }
+ }
+ return artifact;
+ }
+
+ private InvalidArtifact createInvalidArtifact(ArtifactState state, String errorMessage) {
+ final InvalidArtifact artifact = new InvalidArtifact(state, errorMessage);
+ ProjectLoadingErrorsNotifier.getInstance(myProject).registerError(new ArtifactLoadingErrorDescription(myProject, artifact));
+ return artifact;
+ }
+
private static <S> void deserializeProperties(ArtifactProperties<S> artifactProperties, ArtifactPropertiesState propertiesState) {
final Element options = propertiesState.getOptions();
if (artifactProperties == null || options == null) {
*/
package com.intellij.packaging.impl.artifacts;
+import com.intellij.openapi.util.Condition;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactModel;
import com.intellij.packaging.artifacts.ArtifactType;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public abstract class ArtifactModelBase implements ArtifactModel {
private Map<String, Artifact> myArtifactsMap;
private Artifact[] myArtifactsArray;
+ public static final Condition<Artifact> VALID_ARTIFACT_CONDITION = new Condition<Artifact>() {
+ @Override
+ public boolean value(Artifact artifact) {
+ return !(artifact instanceof InvalidArtifact);
+ }
+ };
protected abstract List<? extends Artifact> getArtifactsList();
@NotNull
public Artifact[] getArtifacts() {
if (myArtifactsArray == null) {
- final List<? extends Artifact> artifacts = getArtifactsList();
- myArtifactsArray = artifacts.toArray(new Artifact[artifacts.size()]);
+ final List<? extends Artifact> validArtifacts = ContainerUtil.findAll(getArtifactsList(), VALID_ARTIFACT_CONDITION);
+ myArtifactsArray = validArtifacts.toArray(new Artifact[validArtifacts.size()]);
}
return myArtifactsArray;
}
+ @Override
+ public List<? extends Artifact> getAllArtifactsIncludingInvalid() {
+ return Collections.unmodifiableList(getArtifactsList());
+ }
+
public Artifact findArtifact(@NotNull String name) {
if (myArtifactsMap == null) {
myArtifactsMap = new HashMap<String, Artifact>();
--- /dev/null
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+import com.intellij.packaging.elements.PackagingElementFactory;
+
+/**
+ * @author nik
+ */
+public class InvalidArtifact extends ArtifactImpl {
+ private ArtifactState myState;
+ private final String myErrorMessage;
+
+ public InvalidArtifact(ArtifactState state, String errorMessage) {
+ super(state.getName(), InvalidArtifactType.getInstance(), false, PackagingElementFactory.getInstance().createArtifactRootElement(), "");
+ myState = state;
+ myErrorMessage = errorMessage;
+ }
+
+ public String getErrorMessage() {
+ return myErrorMessage;
+ }
+
+ public ArtifactState getState() {
+ return myState;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.packaging.artifacts.ArtifactType;
+import com.intellij.packaging.elements.CompositePackagingElement;
+import com.intellij.packaging.elements.PackagingElementFactory;
+import com.intellij.packaging.elements.PackagingElementOutputKind;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+/**
+ * @author nik
+ */
+public class InvalidArtifactType extends ArtifactType {
+ public static final Icon ICON = IconLoader.getIcon("/fileTypes/unknown.png");
+
+ public static InvalidArtifactType getInstance() {
+ return ServiceManager.getService(InvalidArtifactType.class);
+ }
+
+ public InvalidArtifactType() {
+ super("invalid", "Invalid");
+ }
+
+ @NotNull
+ @Override
+ public Icon getIcon() {
+ return ICON;
+ }
+
+ @Override
+ public String getDefaultPathFor(@NotNull PackagingElementOutputKind kind) {
+ return "";
+ }
+
+ @NotNull
+ @Override
+ public CompositePackagingElement<?> createRootElement(@NotNull String artifactName) {
+ return PackagingElementFactory.getInstance().createArtifactRootElement();
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+/**
+ * @author nik
+ */
+class UnknownPackagingElementTypeException extends Exception {
+ private final String myTypeId;
+
+ public UnknownPackagingElementTypeException(String typeId) {
+ myTypeId = typeId;
+ }
+
+ public String getTypeId() {
+ return myTypeId;
+ }
+}
package com.intellij.packaging.impl.elements;
import com.intellij.CommonBundle;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.application.ApplicationManager;
final TreeClassChooser chooser =
chooserFactory.createWithInnerClassesScopeChooser("Select Main Class", searchScope, new MainClassFilter(), aClass);
chooser.showDialog();
- return chooser.getSelectedClass();
+ return chooser.getSelected();
}
public static void setupMainClassField(final Project project, final TextFieldWithBrowseButton field) {
});
}
- private static class MainClassFilter implements TreeClassChooser.ClassFilter {
+ private static class MainClassFilter implements ClassFilter {
public boolean isAccepted(PsiClass aClass) {
return PsiMethodUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.hasMainMethod(aClass);
}
if (id.equals(ARTIFACT_ROOT_ELEMENT_TYPE.getId())) {
return ARTIFACT_ROOT_ELEMENT_TYPE;
}
- throw new AssertionError(id + " not registered");
+ return null;
}
@NotNull
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
+import java.util.List;
/**
* @author nik
Artifact getOriginalArtifact(@NotNull Artifact artifact);
Collection<? extends Artifact> getArtifactsByType(@NotNull ArtifactType type);
+
+ List<? extends Artifact> getAllArtifactsIncludingInvalid();
}
public PsiClass chooseClassDialog(String title, Project project) {
TreeClassChooser dialog = TreeClassChooserFactory.getInstance(project).createAllProjectScopeChooser(title);
dialog.showDialog();
- return dialog.getSelectedClass();
+ return dialog.getSelected();
}
public CompletionEditor createEditor(Project project, PsiElement context, String recentsId) {
}
}
chooser.showDialog();
- PsiClass selectedClass = chooser.getSelectedClass();
+ PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
myClassChooser.setText(selectedClass.getQualifiedName());
}
import com.intellij.debugger.ui.CompletionEditor;
import com.intellij.debugger.ui.DebuggerExpressionComboBox;
import com.intellij.debugger.ui.DebuggerStatementEditor;
-import com.intellij.ide.util.TreeClassChooser;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.psi.PsiElement;
import com.intellij.ui.FieldPanel;
import com.intellij.ui.MultiLineTooltipUI;
-import com.intellij.ui.classFilter.ClassFilter;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
private final FieldPanel myInstanceFiltersField;
private final FieldPanel myClassFiltersField;
- private ClassFilter[] myClassFilters;
- private ClassFilter[] myClassExclusionFilters;
+ private com.intellij.ui.classFilter.ClassFilter[] myClassFilters;
+ private com.intellij.ui.classFilter.ClassFilter[] myClassExclusionFilters;
private InstanceFilter[] myInstanceFilters;
private JCheckBox myLogExpressionCheckBox;
public void actionPerformed(ActionEvent e) {
reloadClassFilters();
- TreeClassChooser.ClassFilter classFilter;
+ ClassFilter classFilter;
classFilter = createClassConditionFilter();
EditClassFiltersDialog _dialog = new EditClassFiltersDialog(myProject, classFilter);
mySuspendNoneRadio.setFont(DebuggerSettings.SUSPEND_NONE.equals(defPolicy)? boldFont : font);
}
- protected TreeClassChooser.ClassFilter createClassConditionFilter() {
- TreeClassChooser.ClassFilter classFilter;
+ protected ClassFilter createClassConditionFilter() {
+ ClassFilter classFilter;
if(myBreakpointPsiClass != null) {
- classFilter = new TreeClassChooser.ClassFilter() {
+ classFilter = new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return myBreakpointPsiClass == aClass || aClass.isInheritor(myBreakpointPsiClass, true);
}
private void updateClassFilterEditor(boolean updateText) {
List<String> filters = new ArrayList<String>();
for (int i = 0; i < myClassFilters.length; i++) {
- ClassFilter classFilter = myClassFilters[i];
+ com.intellij.ui.classFilter.ClassFilter classFilter = myClassFilters[i];
if(classFilter.isEnabled()) {
filters.add(classFilter.getPattern());
}
}
List<String> excludeFilters = new ArrayList<String>();
for (int i = 0; i < myClassExclusionFilters.length; i++) {
- ClassFilter classFilter = myClassExclusionFilters[i];
+ com.intellij.ui.classFilter.ClassFilter classFilter = myClassExclusionFilters[i];
if(classFilter.isEnabled()) {
excludeFilters.add("-" + classFilter.getPattern());
}
private void reloadClassFilters() {
String filtersText = myClassFiltersField.getText();
- ArrayList<ClassFilter> classFilters = new ArrayList<ClassFilter>();
- ArrayList<ClassFilter> exclusionFilters = new ArrayList<ClassFilter>();
+ ArrayList<com.intellij.ui.classFilter.ClassFilter> classFilters = new ArrayList<com.intellij.ui.classFilter.ClassFilter>();
+ ArrayList<com.intellij.ui.classFilter.ClassFilter> exclusionFilters = new ArrayList<com.intellij.ui.classFilter.ClassFilter>();
int startFilter = -1;
for(int i = 0; i <= filtersText.length(); i++) {
if(i < filtersText.length() && !Character.isWhitespace(filtersText.charAt(i))){
} else {
if(startFilter >=0) {
if(filtersText.charAt(startFilter) == '-'){
- exclusionFilters.add(new ClassFilter(filtersText.substring(startFilter + 1, i)));
+ exclusionFilters.add(new com.intellij.ui.classFilter.ClassFilter(filtersText.substring(startFilter + 1, i)));
} else {
- classFilters.add(new ClassFilter(filtersText.substring(startFilter, i)));
+ classFilters.add(new com.intellij.ui.classFilter.ClassFilter(filtersText.substring(startFilter, i)));
}
startFilter = -1;
}
}
}
for (int i = 0; i < myClassFilters.length; i++) {
- ClassFilter classFilter = myClassFilters[i];
+ com.intellij.ui.classFilter.ClassFilter classFilter = myClassFilters[i];
if(!classFilter.isEnabled()) classFilters.add(classFilter);
}
for (int i = 0; i < myClassExclusionFilters.length; i++) {
- ClassFilter classFilter = myClassExclusionFilters[i];
+ com.intellij.ui.classFilter.ClassFilter classFilter = myClassExclusionFilters[i];
if(!classFilter.isEnabled()) exclusionFilters.add(classFilter);
}
- myClassFilters = classFilters .toArray(new ClassFilter[classFilters .size()]);
- myClassExclusionFilters = exclusionFilters.toArray(new ClassFilter[exclusionFilters.size()]);
+ myClassFilters = classFilters .toArray(new com.intellij.ui.classFilter.ClassFilter[classFilters .size()]);
+ myClassExclusionFilters = exclusionFilters.toArray(new com.intellij.ui.classFilter.ClassFilter[exclusionFilters.size()]);
}
public void setEnabled(boolean enabled) {
*/
package com.intellij.debugger.ui.breakpoints;
-import com.intellij.ui.classFilter.ClassFilter;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ui.classFilter.ClassFilterEditor;
import com.intellij.debugger.DebuggerBundle;
-import com.intellij.ide.util.TreeClassChooser;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.IdeBorderFactory;
private ClassFilterEditor myClassFilterEditor;
private ClassFilterEditor myClassExclusionFilterEditor;
private Project myProject;
- private TreeClassChooser.ClassFilter myChooserFilter;
+ private ClassFilter myChooserFilter;
public EditClassFiltersDialog(Project project) {
this(project, null);
}
- public EditClassFiltersDialog(Project project, TreeClassChooser.ClassFilter filter) {
+ public EditClassFiltersDialog(Project project, ClassFilter filter) {
super(project, true);
myChooserFilter = filter;
myProject = project;
super.dispose();
}
- public void setFilters(ClassFilter[] filters, ClassFilter[] inverseFilters) {
+ public void setFilters(com.intellij.ui.classFilter.ClassFilter[] filters, com.intellij.ui.classFilter.ClassFilter[] inverseFilters) {
myClassFilterEditor.setFilters(filters);
myClassExclusionFilterEditor.setFilters(inverseFilters);
}
return "#com.intellij.debugger.ui.breakpoints.EditClassFiltersDialog";
}
- public ClassFilter[] getFilters() {
+ public com.intellij.ui.classFilter.ClassFilter[] getFilters() {
return myClassFilterEditor.getFilters();
}
- public ClassFilter[] getExclusionFilters() {
+ public com.intellij.ui.classFilter.ClassFilter[] getExclusionFilters() {
return myClassExclusionFilterEditor.getFilters();
}
}
\ No newline at end of file
DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), GlobalSearchScope.allScope(myProject),
throwableClass, true, true, null);
chooser.showDialog();
- PsiClass selectedClass = chooser.getSelectedClass();
+ PsiClass selectedClass = chooser.getSelected();
String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass);
if (qName != null && qName.length() > 0) {
package com.intellij.debugger.ui.breakpoints;
import com.intellij.debugger.DebuggerBundle;
-import com.intellij.ide.util.TreeClassChooser;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.openapi.project.Project;
import javax.swing.*;
super(project, ExceptionBreakpoint.CATEGORY);
}
- protected TreeClassChooser.ClassFilter createClassConditionFilter() {
+ protected ClassFilter createClassConditionFilter() {
return null;
}
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.ShortcutSet;
+import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.Alarm;
// ignored
}
}
- }, 100);
+ }, 100, ModalityState.NON_MODAL);
}
else {
myRefreshNeeded = true;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.configuration.BrowseModuleValueActionListener;
import com.intellij.execution.configurations.ConfigurationUtil;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.module.Module;
@Nullable
protected String showDialog() {
- final TreeClassChooser.ClassFilterWithScope classFilter;
+ final ClassFilter.ClassFilterWithScope classFilter;
try {
classFilter = getFilter();
}
final TreeClassChooser dialog = createClassChooser(classFilter);
configureDialog(dialog);
dialog.showDialog();
- final PsiClass psiClass = dialog.getSelectedClass();
+ final PsiClass psiClass = dialog.getSelected();
if (psiClass == null) return null;
onClassChoosen(psiClass);
return JavaExecutionUtil.getRuntimeQualifiedName(psiClass);
}
- protected TreeClassChooser createClassChooser(TreeClassChooser.ClassFilterWithScope classFilter) {
+ protected TreeClassChooser createClassChooser(ClassFilter.ClassFilterWithScope classFilter) {
return TreeClassChooserFactory.getInstance(getProject()).createWithInnerClassesScopeChooser(myTitle, classFilter.getScope(), classFilter, null);
}
- protected abstract TreeClassChooser.ClassFilterWithScope getFilter() throws NoFilterException;
+ protected abstract ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException;
protected void onClassChoosen(final PsiClass psiClass) { }
if (psiClass == null) return;
final PsiDirectory directory = psiClass.getContainingFile().getContainingDirectory();
if (directory != null) dialog.selectDirectory(directory);
- dialog.selectClass(psiClass);
+ dialog.select(psiClass);
}
protected abstract PsiClass findClass(String className);
public static ClassBrowser createApplicationClassBrowser(final Project project,
final ConfigurationModuleSelector moduleSelector) {
- final TreeClassChooser.ClassFilter applicationClass = new TreeClassChooser.ClassFilter() {
+ final ClassFilter applicationClass = new ClassFilter() {
public boolean isAccepted(final PsiClass aClass) {
return ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null;
}
};
return new MainClassBrowser(project, moduleSelector, ExecutionBundle.message("choose.main.class.dialog.title")){
- protected TreeClassChooser.ClassFilter createFilter(final Module module) {
+ protected ClassFilter createFilter(final Module module) {
return applicationClass;
}
};
return new MainClassBrowser(project, moduleSelector, title) {
@Override
- protected TreeClassChooser createClassChooser(TreeClassChooser.ClassFilterWithScope classFilter) {
+ protected TreeClassChooser createClassChooser(ClassFilter.ClassFilterWithScope classFilter) {
final Module module = moduleSelector.getModule();
final GlobalSearchScope scope =
module == null ? GlobalSearchScope.allScope(myProject) : GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
return myModuleSelector.findClass(className);
}
- protected TreeClassChooser.ClassFilterWithScope getFilter() throws NoFilterException {
+ protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
final Module module = myModuleSelector.getModule();
final GlobalSearchScope scope;
if (module == null) scope = GlobalSearchScope.allScope(myProject);
else scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
- final TreeClassChooser.ClassFilter filter = createFilter(module);
- return new TreeClassChooser.ClassFilterWithScope() {
+ final ClassFilter filter = createFilter(module);
+ return new ClassFilter.ClassFilterWithScope() {
public GlobalSearchScope getScope() {
return scope;
}
};
}
- protected TreeClassChooser.ClassFilter createFilter(final Module module) { return null; }
+ protected ClassFilter createFilter(final Module module) { return null; }
}
public static class NoFilterException extends Exception {
package com.intellij.openapi.roots.ui.configuration.artifacts;
import com.intellij.openapi.options.ConfigurationException;
-import com.intellij.openapi.project.ProjectBundle;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectStructureElementConfigurable;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.Comparing;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactType;
-import org.jetbrains.annotations.Nls;
import javax.swing.*;
import java.awt.*;
/**
* @author nik
*/
-public class ArtifactConfigurable extends ProjectStructureElementConfigurable<Artifact> {
- private final Artifact myOriginalArtifact;
- private final ArtifactsStructureConfigurableContext myArtifactsStructureContext;
+public class ArtifactConfigurable extends ArtifactConfigurableBase {
private final ArtifactEditorImpl myEditor;
private boolean myIsInUpdateName;
- private final ProjectStructureElement myProjectStructureElement;
public ArtifactConfigurable(Artifact originalArtifact, ArtifactsStructureConfigurableContextImpl artifactsStructureContext, final Runnable updateTree) {
- super(true, updateTree);
- myOriginalArtifact = originalArtifact;
- myArtifactsStructureContext = artifactsStructureContext;
+ super(originalArtifact, artifactsStructureContext, updateTree, true);
myEditor = artifactsStructureContext.getOrCreateEditor(originalArtifact);
- myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact);
}
public void setDisplayName(String name) {
}
}
- @Override
- public ProjectStructureElement getProjectStructureElement() {
- return myProjectStructureElement;
- }
-
@Override
public void updateName() {
myIsInUpdateName = true;
}
}
- private Artifact getArtifact() {
- return myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
- }
-
- public Artifact getEditableObject() {
- return getArtifact();
- }
-
- public String getBannerSlogan() {
- return ProjectBundle.message("banner.slogan.artifact.0", getDisplayName());
- }
-
public JComponent createOptionsPanel() {
return myEditor.createMainComponent();
}
- @Nls
- public String getDisplayName() {
- return getArtifact().getName();
- }
-
- public Icon getIcon() {
- return getArtifact().getArtifactType().getIcon();
- }
-
- public String getHelpTopic() {
- return myEditor.getHelpTopic();
- }
-
@Override
protected JComponent createTopRightComponent() {
final ComboBox artifactTypeBox = new ComboBox();
public void reset() {
}
- public void disposeUIResources() {
+ public String getHelpTopic() {
+ return myEditor.getHelpTopic();
}
-
}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.openapi.roots.ui.configuration.artifacts;
+
+import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectStructureElementConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
+import com.intellij.packaging.artifacts.Artifact;
+import org.jetbrains.annotations.Nls;
+
+import javax.swing.*;
+
+/**
+ * @author nik
+ */
+public abstract class ArtifactConfigurableBase extends ProjectStructureElementConfigurable<Artifact> {
+ protected final Artifact myOriginalArtifact;
+ protected final ArtifactsStructureConfigurableContext myArtifactsStructureContext;
+ protected final ProjectStructureElement myProjectStructureElement;
+
+ public ArtifactConfigurableBase(Artifact originalArtifact,
+ ArtifactsStructureConfigurableContextImpl artifactsStructureContext,
+ Runnable updateTree,
+ final boolean nameEditable) {
+ super(nameEditable, updateTree);
+ myOriginalArtifact = originalArtifact;
+ myArtifactsStructureContext = artifactsStructureContext;
+ myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact);
+ }
+
+ @Override
+ public ProjectStructureElement getProjectStructureElement() {
+ return myProjectStructureElement;
+ }
+
+ protected Artifact getArtifact() {
+ return myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
+ }
+
+ public Artifact getEditableObject() {
+ return getArtifact();
+ }
+
+ public String getBannerSlogan() {
+ return ProjectBundle.message("banner.slogan.artifact.0", getDisplayName());
+ }
+
+ @Nls
+ public String getDisplayName() {
+ return getArtifact().getName();
+ }
+
+ public Icon getIcon() {
+ return getArtifact().getArtifactType().getIcon();
+ }
+
+ public void disposeUIResources() {
+ }
+}
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.openapi.ui.MasterDetailsStateService;
+import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
+import com.intellij.packaging.impl.artifacts.InvalidArtifact;
import com.intellij.packaging.impl.artifacts.PackagingElementPath;
import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
import com.intellij.packaging.impl.elements.LibraryElementType;
protected void loadTree() {
myTree.setRootVisible(false);
myTree.setShowsRootHandles(false);
- for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) {
+ for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) {
addArtifactNode(artifact);
}
}
@Override
protected Collection<? extends ProjectStructureElement> getProjectStructureElements() {
final List<ProjectStructureElement> elements = new ArrayList<ProjectStructureElement>();
- for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) {
+ for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) {
elements.add(myPackagingEditorContext.getOrCreateArtifactElement(artifact));
}
return elements;
}
private MyNode addArtifactNode(final Artifact artifact) {
- final MyNode node = new MyNode(new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER));
+ final NamedConfigurable<Artifact> configurable;
+ if (artifact instanceof InvalidArtifact) {
+ configurable = new InvalidArtifactConfigurable((InvalidArtifact)artifact, myPackagingEditorContext, TREE_UPDATER);
+ }
+ else {
+ configurable = new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER);
+ }
+ final MyNode node = new MyNode(configurable);
addNode(node, myRoot);
return node;
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.artifacts.InvalidArtifactConfigurable.InvalidArtifactComponent">
+ <grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <xy x="20" y="20" width="500" height="400"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <vspacer id="b67c4">
+ <constraints>
+ <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+ </constraints>
+ </vspacer>
+ <component id="2bf31" class="javax.swing.JLabel">
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Cannot load artifact"/>
+ </properties>
+ </component>
+ <component id="b6c83" class="javax.swing.JLabel" binding="myIconLabel">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value=""/>
+ </properties>
+ </component>
+ <component id="f350" class="com.intellij.openapi.ui.ex.MultiLineLabel" binding="myDescriptionLabel">
+ <constraints>
+ <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ </component>
+ </children>
+ </grid>
+</form>
--- /dev/null
+/*
+ * Copyright 2000-2010 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.openapi.roots.ui.configuration.artifacts;
+
+import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.ui.ex.MultiLineLabel;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.packaging.impl.artifacts.InvalidArtifact;
+
+import javax.swing.*;
+
+/**
+ * @author nik
+ */
+public class InvalidArtifactConfigurable extends ArtifactConfigurableBase {
+ private String myErrorMessage;
+
+ public InvalidArtifactConfigurable(InvalidArtifact originalArtifact,
+ ArtifactsStructureConfigurableContextImpl artifactsStructureContext,
+ Runnable updateTree) {
+ super(originalArtifact, artifactsStructureContext, updateTree, false);
+ myErrorMessage = originalArtifact.getErrorMessage();
+ }
+
+ @Override
+ public void setDisplayName(String name) {
+ }
+
+ @Override
+ public JComponent createOptionsPanel() {
+ return new InvalidArtifactComponent(myErrorMessage).myMainPanel;
+ }
+
+ @Override
+ public String getHelpTopic() {
+ return null;
+ }
+
+ @Override
+ public boolean isModified() {
+ return false;
+ }
+
+ @Override
+ public void apply() throws ConfigurationException {
+ }
+
+ @Override
+ public void reset() {
+ }
+
+ private static class InvalidArtifactComponent {
+ private JPanel myMainPanel;
+ private MultiLineLabel myDescriptionLabel;
+ private JLabel myIconLabel;
+
+ private InvalidArtifactComponent(String errorMessage) {
+ myIconLabel.setIcon(IconLoader.getIcon("/runConfigurations/configurationWarning.png"));
+ myDescriptionLabel.setText(errorMessage);
+ }
+ }
+}
myRemoveButton.addActionListener(new RemoveAction());
final LibraryTableAttachHandler[] handlers = LibraryTableAttachHandler.EP_NAME.getExtensions();
- if (handlers.length == 0 || myProject == null || myDescriptor != null) {
+ if (handlers.length == 0 || myProject == null || getLibraryEditor().getType() != null) {
myAttachMoreButton.setVisible(false);
}
else {
<orderEntry type="module" module-name="icons" />
<orderEntry type="library" name="jcip" level="project" />
<orderEntry type="library" name="Groovy" level="project" />
+ <orderEntry type="library" name="Guava" level="project" />
</component>
<component name="copyright">
<Base>
}
@Override public void visitAnnotationArrayInitializer(PsiArrayInitializerMemberValue initializer) {
- final PsiType type = getAnnotationMethodType((PsiNameValuePair)initializer.getParent());
+ final PsiElement parent = initializer.getParent();
+ final PsiType type;
+ if (parent instanceof PsiNameValuePair) {
+ type = getAnnotationMethodType((PsiNameValuePair)parent);
+ }
+ else {
+ type = ((PsiAnnotationMethod)parent).getReturnType();
+ }
if (type instanceof PsiArrayType) {
myResult = new ExpectedTypeInfo[]{createInfoImpl(((PsiArrayType)type).getComponentType(), ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, TailType.UNKNOWN)};
}
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.lookup.LookupItemUtil;
-import com.intellij.codeInsight.lookup.TailTypeDecorator;
import com.intellij.psi.*;
import com.intellij.psi.filters.ContextGetter;
import com.intellij.util.IncorrectOperationException;
return TailType.NONE;
}
- protected void addLookupItem(Set<LookupElement> set, TailType tailType, @NotNull Object completion, final PsiFile file, final CompletionVariant variant) {
+ protected void addLookupItem(Set<LookupElement> set, final TailType tailType, @NotNull Object completion, final PsiFile file, final CompletionVariant variant) {
if (completion instanceof LookupElement && !(completion instanceof LookupItem)) {
set.add((LookupElement)completion);
return;
ret.setInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
- final TailType type = analyzeItem(item.getObject(), context.getFile().findElementAt(context.getStartOffset()));
- new DefaultInsertHandler().handleInsert(context, item);
+ TailType type = analyzeItem(item.getObject(), context.getFile().findElementAt(context.getStartOffset()));
+ if (type == TailType.NONE) {
+ type = tailType;
+ }
+ //new DefaultInsertHandler().handleInsert(context, item);
if (type != TailType.NONE) {
context.setAddCompletionChar(false);
type.processTail(context.getEditor(), context.getTailOffset());
ret.setAttribute(key, itemProperties.get(key));
}
- if ((insertHandler == null || ret.getInsertHandler() != null) && tailType != TailType.NONE) {
- set.add(TailTypeDecorator.withTail(ret, tailType));
- } else {
- set.add(ret);
- }
+ set.add(ret);
}
protected void addKeywords(final Set<LookupElement> set, final PsiElement position, final PrefixMatcher matcher, final PsiFile file,
return null;
}
+ if (JavaCompletionData.START_FOR.accepts(position)) {
+ return ElementClassFilter.VARIABLE;
+ }
+
if (psiElement().afterLeaf(psiElement().withText("(").withParent(PsiTryStatement.class)).accepts(position)) {
return new OrFilter(new ThisOrAnyInnerFilter(new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE)), ElementClassFilter.PACKAGE_FILTER);
}
final static ElementFilter CLASS_BODY = new OrFilter(
new AfterElementFilter(new TextFilter("{")),
new ScopeFilter(new ClassFilter(JspClassLevelDeclarationStatement.class)));
+ public static final ElementPattern<PsiElement> START_FOR =
+ psiElement().afterLeaf(psiElement().withText("(").afterLeaf("for")).withParents(PsiJavaCodeReferenceElement.class, PsiExpressionStatement.class, PsiForStatement.class);
public JavaCompletionData(){
declareCompletionSpaces();
variant.addCompletion(PsiKeyword.IF, TailTypes.IF_LPARENTH);
variant.addCompletion(PsiKeyword.TRY, TailType.createSimpleTailType('{'));
variant.addCompletion(PsiKeyword.THROW, TailType.SPACE);
- variant.addCompletion(PsiKeyword.RETURN, TailType.SPACE);
+ variant.addCompletion(PsiKeyword.RETURN, TailType.NONE);
variant.addCompletion(PsiKeyword.NEW, TailType.SPACE);
variant.addCompletion(PsiKeyword.ASSERT, TailType.SPACE);
variant.addCompletion(PsiKeyword.SYNCHRONIZED, TailTypes.SYNCHRONIZED_LPARENTH);
result.addElement(createKeyword(position, PsiKeyword.FALSE));
}
- if (psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiExpressionStatement.class, PsiForStatement.class).accepts(position)) {
+ if (START_FOR.accepts(position)) {
for (String primitiveType : PRIMITIVE_TYPES) {
if (!PsiKeyword.VOID.equals(primitiveType)) {
result.addElement(TailTypeDecorator.withTail(createKeyword(position, primitiveType), TailType.SPACE));
}
+ result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
}
}
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.VariableLookupItem;
import com.intellij.psi.*;
+import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
final PsiReferenceExpression ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiReferenceExpression.class, false);
if (ref != null) {
ref.bindToElementViaStaticImport(containingClass);
+ PostprocessReformattingAspect.getInstance(ref.getProject()).doPostponedFormatting();
}
super.handleInsert(context);
}
rTypeParams = psiClass == null ? PsiTypeParameter.EMPTY_ARRAY : psiClass.getTypeParameters();
}
-
int typeParamColumns = Math.max(lTypeParams.length, rTypeParams.length);
- @Language("HTML") @NonNls String requredRow = "";
+ @Language("HTML") @NonNls String requiredRow = "";
@Language("HTML") @NonNls String foundRow = "";
for (int i = 0; i < typeParamColumns; i++) {
PsiTypeParameter lTypeParameter = i >= lTypeParams.length ? null : lTypeParams[i];
PsiTypeParameter rTypeParameter = i >= rTypeParams.length ? null : rTypeParams[i];
- PsiType lSubstedType = lTypeParameter == null ? null : lTypeSubstitutor.substitute(lTypeParameter);
- PsiType rSubstedType = rTypeParameter == null ? null : rTypeSubstitutor.substitute(rTypeParameter);
- boolean matches = Comparing.equal(lSubstedType, rSubstedType);
+ PsiType lSubstitutedType = lTypeParameter == null ? null : lTypeSubstitutor.substitute(lTypeParameter);
+ PsiType rSubstitutedType = rTypeParameter == null ? null : rTypeSubstitutor.substitute(rTypeParameter);
+ boolean matches = Comparing.equal(lSubstitutedType, rSubstitutedType);
@NonNls String openBrace = i == 0 ? "<" : "";
@NonNls String closeBrace = i == typeParamColumns - 1 ? ">" : ",";
- requredRow += "<td>" + (lTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(lSubstedType, matches) +
- (i < lTypeParams.length ? closeBrace : "") + "</td>";
- foundRow += "<td>" + (rTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(rSubstedType, matches) +
+ requiredRow += "<td>" + (lTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(lSubstitutedType, matches) +
+ (i < lTypeParams.length ? closeBrace : "") + "</td>";
+ foundRow += "<td>" + (rTypeParams.length == 0 ? "" : openBrace) + redIfNotMatch(rSubstitutedType, matches) +
(i < rTypeParams.length ? closeBrace : "") + "</td>";
}
PsiType lRawType = lType1 instanceof PsiClassType ? ((PsiClassType)lType1).rawType() : lType1;
boolean assignable = lRawType == null || rRawType == null || TypeConversionUtil.isAssignable(lRawType, rRawType);
String toolTip = JavaErrorMessages.message("incompatible.types.html.tooltip",
- redIfNotMatch(lRawType, assignable), requredRow,
+ redIfNotMatch(lRawType, assignable), requiredRow,
redIfNotMatch(rRawType, assignable), foundRow);
String description = JavaErrorMessages.message("incompatible.types", formatType(lType1), formatType(rType1));
@NotNull
public TreeClassChooser createWithInnerClassesScopeChooser(String title,
GlobalSearchScope scope,
- final TreeClassChooser.ClassFilter classFilter,
+ final ClassFilter classFilter,
PsiClass initialClass) {
- return TreeClassChooserDialog.withInnerClasses(title, myProject, scope, classFilter, initialClass);
+ return TreeJavaClassChooserDialog.withInnerClasses(title, myProject, scope, classFilter, initialClass);
}
@NotNull
public TreeClassChooser createNoInnerClassesScopeChooser(String title,
GlobalSearchScope scope,
- TreeClassChooser.ClassFilter classFilter,
+ ClassFilter classFilter,
PsiClass initialClass) {
- return new TreeClassChooserDialog(title, myProject, scope, classFilter, initialClass);
+ return new TreeJavaClassChooserDialog(title, myProject, scope, classFilter, initialClass);
}
@NotNull
public TreeClassChooser createProjectScopeChooser(String title, PsiClass initialClass) {
- return new TreeClassChooserDialog(title, myProject, initialClass);
+ return new TreeJavaClassChooserDialog(title, myProject, initialClass);
}
@NotNull
public TreeClassChooser createProjectScopeChooser(String title) {
- return new TreeClassChooserDialog(title, myProject);
+ return new TreeJavaClassChooserDialog(title, myProject);
}
@NotNull
public TreeClassChooser createAllProjectScopeChooser(String title) {
- return new TreeClassChooserDialog(title, myProject, GlobalSearchScope.allScope(myProject), null, null);
+ return new TreeJavaClassChooserDialog(title, myProject, GlobalSearchScope.allScope(myProject), null, null);
}
@NotNull
boolean acceptsSelf,
boolean acceptInner,
Condition<? super PsiClass> additionalCondition) {
- TreeClassChooser.ClassFilter classFilter = new TreeClassChooserDialog.InheritanceClassFilterImpl(base, acceptsSelf, acceptInner, additionalCondition);
- return new TreeClassChooserDialog(title, myProject, scope, classFilter, base, null, null);
+ ClassFilter classFilter = new TreeJavaClassChooserDialog.InheritanceJavaClassFilterImpl(base, acceptsSelf, acceptInner, additionalCondition);
+ return new TreeJavaClassChooserDialog(title, myProject, scope, classFilter, base, null, false);
}
@NotNull
@NotNull
public TreeClassChooser createInheritanceClassChooser(String title, GlobalSearchScope scope, PsiClass base, PsiClass initialClass,
- TreeClassChooser.ClassFilter classFilter) {
- return new TreeClassChooserDialog(title, myProject, scope, classFilter, base, initialClass, null);
+ ClassFilter classFilter) {
+ return new TreeJavaClassChooserDialog(title, myProject, scope, classFilter, base, initialClass, false);
}
@NotNull
--- /dev/null
+/*
+ * Copyright 2000-2010 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.ide.util;
+
+import com.google.common.collect.Lists;
+import com.intellij.ide.projectView.impl.nodes.ClassTreeNode;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.Conditions;
+import com.intellij.psi.JavaPsiFacade;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiJavaFile;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.search.PsiShortNamesCache;
+import com.intellij.psi.search.searches.ClassInheritorsSearch;
+import com.intellij.util.Query;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import java.util.List;
+
+/**
+ * @author traff
+ */
+public class TreeJavaClassChooserDialog extends AbstractTreeClassChooserDialog<PsiClass> implements TreeClassChooser {
+ public TreeJavaClassChooserDialog(String title, Project project) {
+ super(title, project);
+ }
+
+ public TreeJavaClassChooserDialog(String title, Project project, @Nullable PsiClass initialClass) {
+ super(title, project, initialClass);
+ }
+
+ public TreeJavaClassChooserDialog(String title,
+ Project project,
+ GlobalSearchScope scope,
+ final ClassFilter classFilter, @Nullable PsiClass initialClass) {
+ super(title, project, scope, createFilter(classFilter), initialClass);
+ }
+
+
+ @Override
+ @Nullable
+ protected PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) {
+ Object userObject = node.getUserObject();
+ if (!(userObject instanceof ClassTreeNode)) return null;
+ ClassTreeNode descriptor = (ClassTreeNode)userObject;
+ return descriptor.getPsiClass();
+ }
+
+ public TreeJavaClassChooserDialog(String title,
+ Project project,
+ GlobalSearchScope scope,
+ final ClassFilter classFilter,
+ PsiClass baseClass,
+ @Nullable PsiClass initialClass, boolean isShowMembers) {
+ super(title, project, scope, createFilter(classFilter), baseClass, initialClass, isShowMembers);
+ }
+
+ public static TreeJavaClassChooserDialog withInnerClasses(String title,
+ Project project,
+ GlobalSearchScope scope,
+ final ClassFilter classFilter,
+ @Nullable PsiClass initialClass) {
+ return new TreeJavaClassChooserDialog(title, project, scope, classFilter, null, initialClass, true);
+ }
+
+ @Nullable
+ private static Filter<PsiClass> createFilter(@Nullable final ClassFilter classFilter) {
+ if (classFilter == null) {
+ return null;
+ }
+ else {
+ return new Filter<PsiClass>() {
+ @Override
+ public boolean isAccepted(PsiClass element) {
+ return classFilter.isAccepted(element);
+ }
+ };
+ }
+ }
+
+ @NotNull
+ protected List<PsiClass> getClassesByName(final String name,
+ final boolean checkBoxState,
+ final String pattern,
+ final GlobalSearchScope searchScope) {
+ final PsiShortNamesCache cache = JavaPsiFacade.getInstance(getProject()).getShortNamesCache();
+ PsiClass[] classes =
+ cache.getClassesByName(name, checkBoxState ? searchScope : GlobalSearchScope.projectScope(getProject()).intersectWith(searchScope));
+ return Lists.newArrayList(classes);
+ }
+
+ @NotNull
+ @Override
+ protected BaseClassInheritorsProvider<PsiClass> getInheritorsProvider() {
+ return new JavaInheritorsProvider(getProject(), getBaseClass(), getScope());
+ }
+
+ private static class JavaInheritorsProvider extends BaseClassInheritorsProvider<PsiClass> {
+ private final Project myProject;
+
+ public JavaInheritorsProvider(Project project, PsiClass baseClass, GlobalSearchScope scope) {
+ super(baseClass, scope);
+ myProject = project;
+ }
+
+ @NotNull
+ @Override
+ protected Query<PsiClass> searchForInheritors(PsiClass baseClass, GlobalSearchScope searchScope, boolean checkDeep) {
+ return ClassInheritorsSearch.search(baseClass, searchScope, checkDeep);
+ }
+
+ @Override
+ protected boolean isInheritor(PsiClass clazz, PsiClass baseClass, boolean checkDeep) {
+ return clazz.isInheritor(baseClass, checkDeep);
+ }
+
+ @Override
+ protected String[] getNames() {
+ return JavaPsiFacade.getInstance(myProject).getShortNamesCache().getAllClassNames();
+ }
+ }
+
+ public static class InheritanceJavaClassFilterImpl implements ClassFilter {
+ private final PsiClass myBase;
+ private final boolean myAcceptsSelf;
+ private final boolean myAcceptsInner;
+ private final Condition<? super PsiClass> myAdditionalCondition;
+
+ public InheritanceJavaClassFilterImpl(PsiClass base,
+ boolean acceptsSelf,
+ boolean acceptInner,
+ Condition<? super PsiClass> additionalCondition) {
+ myAcceptsSelf = acceptsSelf;
+ myAcceptsInner = acceptInner;
+ if (additionalCondition == null) {
+ additionalCondition = Conditions.alwaysTrue();
+ }
+ myAdditionalCondition = additionalCondition;
+ myBase = base;
+ }
+
+ public boolean isAccepted(PsiClass aClass) {
+ if (!myAcceptsInner && !(aClass.getParent() instanceof PsiJavaFile)) return false;
+ if (!myAdditionalCondition.value(aClass)) return false;
+ // we've already checked for inheritance
+ return myAcceptsSelf || !aClass.getManager().areElementsEquivalent(aClass, myBase);
+ }
+ }
+}
chooser.showDialog();
- PsiClass aClass = chooser.getSelectedClass();
+ PsiClass aClass = chooser.getSelected();
if (aClass == null) return null;
List<PsiElement> classesToSearch = new LinkedList<PsiElement>();
}
// adding a reference, not simple tokens allows "Browse ..." to work well
- final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, true, false, false);
+ final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, true, false, false, false);
if (ref == null) {
builder.advanceLexer();
}
}
// adding a reference, not simple tokens allows "Browse .." to work well
- final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, true, false, false);
+ final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, true, false, false, false);
if (ref == null && builder.getTokenType() != null) {
builder.advanceLexer();
}
final PsiBuilder.Marker anno = builder.mark();
builder.advanceLexer();
- final PsiBuilder.Marker classRef = ReferenceParser.parseJavaCodeReference(builder, true, false, false, false);
+ final PsiBuilder.Marker classRef = ReferenceParser.parseJavaCodeReference(builder, true, false, false, false, false);
if (classRef == null) {
error(builder, JavaErrorMessages.message("expected.class.reference"));
}
final PsiBuilder.Marker copy = startMarker.precede();
startMarker.rollbackTo();
- final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, false, true, false, false);
+ final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, false, true, false, false, false);
if (ref == null || builder.getTokenType() != JavaTokenType.DOT) {
copy.rollbackTo();
return parsePrimary(builder, BreakPoint.P2, -1);
final IElementType tokenType = builder.getTokenType();
if (tokenType == JavaTokenType.IDENTIFIER || parseAnnotations) {
- refOrType = ReferenceParser.parseJavaCodeReference(builder, true, true, parseAnnotations, parseDiamonds);
+ refOrType = ReferenceParser.parseJavaCodeReference(builder, true, true, parseAnnotations, true, parseDiamonds);
if (refOrType == null) {
error(builder, JavaErrorMessages.message("expected.identifier"));
newExpr.done(JavaElementType.NEW_EXPRESSION);
}
}
- final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, false, false, false);
+ final PsiBuilder.Marker ref = ReferenceParser.parseJavaCodeReference(builder, true, false, false, false, false);
if (ref == null) {
statement.rollbackTo();
return null;
typeInfo.isPrimitive = true;
}
else if (tokenType == JavaTokenType.IDENTIFIER) {
- parseJavaCodeReference(builder, eatLastDot, true, annotationsSupported, false, false, diamonds, typeInfo);
+ parseJavaCodeReference(builder, eatLastDot, true, annotationsSupported, false, false, false, diamonds, typeInfo);
}
else if (wildcard && tokenType == JavaTokenType.QUEST) {
type.drop();
}
@Nullable
- public static PsiBuilder.Marker parseJavaCodeReference(final PsiBuilder builder, final boolean eatLastDot,
- final boolean parameterList, final boolean annotations, final boolean diamonds) {
- return parseJavaCodeReference(builder, eatLastDot, parameterList, annotations, false, false, diamonds, new TypeInfo());
+ public static PsiBuilder.Marker parseJavaCodeReference(final PsiBuilder builder, final boolean eatLastDot, final boolean parameterList,
+ final boolean annotations, final boolean isNew, final boolean diamonds) {
+ return parseJavaCodeReference(builder, eatLastDot, parameterList, annotations, false, false, isNew, diamonds, new TypeInfo());
}
public static boolean parseImportCodeReference(final PsiBuilder builder, final boolean isStatic) {
final TypeInfo typeInfo = new TypeInfo();
- parseJavaCodeReference(builder, true, false, false, true, isStatic, false, typeInfo);
+ parseJavaCodeReference(builder, true, false, false, true, isStatic, false, false, typeInfo);
return !typeInfo.hasErrors;
}
@Nullable
- private static PsiBuilder.Marker parseJavaCodeReference(final PsiBuilder builder, final boolean eatLastDot,
- final boolean parameterList, final boolean annotations,
- final boolean isImport, final boolean isStaticImport,
- final boolean diamonds, final TypeInfo typeInfo) {
+ private static PsiBuilder.Marker parseJavaCodeReference(final PsiBuilder builder, final boolean eatLastDot, final boolean parameterList,
+ final boolean annotations, final boolean isImport, final boolean isStaticImport,
+ final boolean isNew, final boolean diamonds, final TypeInfo typeInfo) {
PsiBuilder.Marker refElement = builder.mark();
if (annotations) {
while (builder.getTokenType() == JavaTokenType.DOT) {
refElement.done(JavaElementType.JAVA_CODE_REFERENCE);
+ if (isNew && typeInfo.isParameterized) {
+ return refElement;
+ }
+
final PsiBuilder.Marker dotPos = builder.mark();
builder.advanceLexer();
if (expect(builder, start)) {
while (true) {
- final PsiBuilder.Marker classReference = parseJavaCodeReference(builder, true, true, true, false);
+ final PsiBuilder.Marker classReference = parseJavaCodeReference(builder, true, true, true, false, false);
if (classReference == null) {
error(builder, JavaErrorMessages.message("expected.identifier"));
}
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collection;
return InheritanceImplUtil.isInheritor(this, baseClass, checkDeep);
}
+ @Nullable
public PsiClass getSourceMirrorClass() {
PsiElement parent = getParent();
final String name = getName();
if (parent instanceof PsiFile) {
+ if (!(parent instanceof PsiClassOwner)) return null;
+
PsiClassOwner fileNavigationElement = (PsiClassOwner)parent.getNavigationElement();
for (PsiClass aClass : fileNavigationElement.getClasses()) {
if (name.equals(aClass.getName())) return aClass;
return JavaParserUtil.parseFragment(chameleon,
new JavaParserUtil.ParserWrapper() {
public void parse(final PsiBuilder builder) {
- ReferenceParser.parseJavaCodeReference(builder, false, true, false, false);
+ ReferenceParser.parseJavaCodeReference(builder, false, true, false, false, false);
}
});
}
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.completion.JavaCompletionUtil;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
private class ChooseClassAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
- TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createWithInnerClassesScopeChooser(RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myProject), new TreeClassChooser.ClassFilter() {
+ TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createWithInnerClassesScopeChooser(RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myProject), new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return aClass.getParent() instanceof PsiJavaFile || aClass.hasModifierProperty(PsiModifier.STATIC);
}
chooser.selectDirectory(myTargetClass.getContainingFile().getContainingDirectory());
}
chooser.showDialog();
- PsiClass aClass = chooser.getSelectedClass();
+ PsiClass aClass = chooser.getSelected();
if (aClass != null) {
myTfTargetClassName.setText(aClass.getQualifiedName());
}
final TypeExpression expression = new TypeExpression(project, typeSelectorManager.getTypesForAll());
final RangeMarker exprMarker = editor.getDocument().createRangeMarker(expr.getTextRange());
final SuggestedNameInfo suggestedName = getSuggestedName(settings.getSelectedType(), expr);
+ final List<RangeMarker> occurrenceMarkers = new ArrayList<RangeMarker>();
+ for (PsiExpression occurrence : occurrences) {
+ occurrenceMarkers.add(editor.getDocument().createRangeMarker(occurrence.getTextRange()));
+ }
final Runnable runnable =
introduce(project, expr, editor, anchorStatement, tempContainer, occurrences, anchorStatementIfAll, settings, variable);
CommandProcessor.getInstance().executeCommand(
editor.getCaretModel().moveToOffset(elementToRename.getTextOffset());
final PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(elementToRename, PsiDeclarationStatement.class);
editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, declarationStatement);
+ editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY,
+ occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()]));
final VariableInplaceRenamer renamer = new VariableInplaceRenamer(elementToRename, editor){
@Override
protected void addAdditionalVariables(TemplateBuilderImpl builder) {
editor.getCaretModel().moveToOffset(startOffset);
}
editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, null);
+ for (RangeMarker occurrenceMarker : occurrenceMarkers) {
+ occurrenceMarker.dispose();
+ }
+ editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY, null);
typeSelectorManager.typeSelected(ReassignVariableUtil.getVariableType(declarationStatement));
exprMarker.dispose();
}
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.psi.*;
import com.intellij.psi.scope.processor.VariablesProcessor;
import com.intellij.psi.scope.util.PsiScopesUtil;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
import com.intellij.refactoring.ui.TypeSelectorManager;
*/
public class ReassignVariableUtil {
static final Key<PsiDeclarationStatement> DECLARATION_KEY = Key.create("var.type");
+ static final Key<RangeMarker[]> OCCURRENCES_KEY = Key.create("occurrences");
+
+ private ReassignVariableUtil() {
+ }
static boolean reassign(final Editor editor) {
final PsiDeclarationStatement declaration = editor.getUserData(DECLARATION_KEY);
return proc;
}
- static void replaceWithAssignment(final PsiDeclarationStatement declaration, final PsiVariable variable, Editor editor) {
+ static void replaceWithAssignment(final PsiDeclarationStatement declaration, final PsiVariable variable, final Editor editor) {
final PsiVariable var = (PsiVariable)declaration.getDeclaredElements()[0];
final PsiExpression initializer = var.getInitializer();
new WriteCommandAction(declaration.getProject()) {
@Override
protected void run(Result result) throws Throwable {
+ final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(variable.getProject());
+ final String chosenVariableName = variable.getName();
//would generate red code for final variables
- declaration.replace(JavaPsiFacade.getElementFactory(variable.getProject())
- .createStatementFromText(variable.getName() + " = " + initializer.getText() + ";", declaration));
+ PsiElement newDeclaration = elementFactory.createStatementFromText(chosenVariableName + " = " + initializer.getText() + ";",
+ declaration);
+ newDeclaration = declaration.replace(newDeclaration);
+ final PsiFile containingFile = newDeclaration.getContainingFile();
+ final RangeMarker[] occurrenceMarkers = editor.getUserData(OCCURRENCES_KEY);
+ if (occurrenceMarkers != null) {
+ for (RangeMarker marker : occurrenceMarkers) {
+ final PsiElement refVariableElement = containingFile.findElementAt(marker.getStartOffset());
+ final PsiExpression expression = PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class);
+ if (expression != null) {
+ expression.replace(elementFactory.createExpressionFromText(chosenVariableName, newDeclaration));
+ }
+ }
+ }
}
}.execute();
finishTemplate(editor);
*/
package com.intellij.refactoring.introduceparameterobject;
-import com.intellij.ide.util.TreeClassChooserDialog;
+import com.intellij.ide.util.TreeJavaClassChooserDialog;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.options.ConfigurationException;
public void actionPerformed(ActionEvent e) {
final Project project = sourceMethod.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
- final TreeClassChooserDialog chooser =
- new TreeClassChooserDialog(RefactorJBundle.message("select.wrapper.class"), project, scope, null, null);
+ final TreeJavaClassChooserDialog chooser =
+ new TreeJavaClassChooserDialog(RefactorJBundle.message("select.wrapper.class"), project, scope, null, null);
final String classText = existingClassField.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(project).findClass(classText, GlobalSearchScope.allScope(project));
if (currentClass != null) {
- chooser.selectClass(currentClass);
+ chooser.select(currentClass);
}
chooser.show();
- final PsiClass selectedClass = chooser.getSelectedClass();
+ final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
final String className = selectedClass.getQualifiedName();
existingClassField.setText(className);
*/
package com.intellij.refactoring.move.moveMembers;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.PackageUtil;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
private class ChooseClassAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createWithInnerClassesScopeChooser(
- RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myProject), new TreeClassChooser.ClassFilter() {
+ RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myProject), new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return aClass.getParent() instanceof PsiFile || aClass.hasModifierProperty(PsiModifier.STATIC);
}
}
chooser.showDialog();
- PsiClass aClass = chooser.getSelectedClass();
+ PsiClass aClass = chooser.getSelected();
if (aClass != null) {
myTfTargetClassName.setText(aClass.getQualifiedName());
myMemberInfoModel.updateTargetClass();
final String classText = myExistentClassTF.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(myProject).findClass(classText, GlobalSearchScope.allScope(myProject));
if (currentClass != null) {
- chooser.selectClass(currentClass);
+ chooser.select(currentClass);
}
chooser.showDialog();
- final PsiClass selectedClass = chooser.getSelectedClass();
+ final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
myExistentClassTF.setText(selectedClass.getQualifiedName());
}
RefactoringBundle.message("choose.destination.class"));
chooser.selectDirectory(myContainingClass.getContainingFile().getContainingDirectory());
chooser.showDialog();
- PsiClass aClass = chooser.getSelectedClass();
+ PsiClass aClass = chooser.getSelected();
if (aClass != null) {
myTfTargetClassName.setText(aClass.getQualifiedName());
}
*/
package com.intellij.refactoring.ui;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.editor.Document;
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createWithInnerClassesScopeChooser(myChooserTitle,
GlobalSearchScope.projectScope(myProject),
- new TreeClassChooser.ClassFilter() {
+ new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return aClass.getParent() instanceof PsiJavaFile || aClass.hasModifierProperty(PsiModifier.STATIC);
}
chooser.selectDirectory(mySelectedClass.getContainingFile().getContainingDirectory());
}
chooser.showDialog();
- mySelectedClass = chooser.getSelectedClass();
+ mySelectedClass = chooser.getSelected();
if (mySelectedClass != null) {
setText(mySelectedClass.getQualifiedName());
}
final String classText = existingClassField.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(myProject).findClass(classText, GlobalSearchScope.allScope(myProject));
if (currentClass != null) {
- chooser.selectClass(currentClass);
+ chooser.select(currentClass);
}
chooser.showDialog();
- final PsiClass selectedClass = chooser.getSelectedClass();
+ final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
existingClassField.setText(selectedClass.getQualifiedName());
}
TreeClassChooser dialog =
f.createAllProjectScopeChooser(CodeInsightBundle.message("intention.create.test.dialog.choose.super.class"));
dialog.showDialog();
- PsiClass aClass = dialog.getSelectedClass();
+ PsiClass aClass = dialog.getSelected();
if (aClass != null) {
mySuperClassField.setText(aClass.getQualifiedName());
}
*/
package com.intellij.util.xml.ui;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.editor.Document;
final DomElement domElement = control.getDomElement();
ExtendClass extend = domElement.getAnnotation(ExtendClass.class);
PsiClass baseClass = null;
- TreeClassChooser.ClassFilter filter = null;
+ ClassFilter filter = null;
if (extend != null) {
baseClass = JavaPsiFacade.getInstance(control.getProject()).findClass(extend.value(), resolveScope);
if (extend.instantiatable()) {
- filter = TreeClassChooser.INSTANTIATABLE;
+ filter = ClassFilter.INSTANTIABLE;
}
}
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(control.getProject())
.createInheritanceClassChooser(UIBundle.message("choose.class"), resolveScope, baseClass, initialClass, filter);
chooser.showDialog();
- final PsiClass psiClass = chooser.getSelectedClass();
+ final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
control.setValue(psiClass.getQualifiedName());
}
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject)
.createInheritanceClassChooser(UIBundle.message("choose.class"), mySearchScope, null, true, true, Conditions.alwaysTrue());
chooser.showDialog();
- final PsiClass psiClass = chooser.getSelectedClass();
+ final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
myEditor.setText(psiClass.getQualifiedName());
}
--- /dev/null
+public class Foooo {
+
+ {
+ for (fin<caret>x)
+ }
+
+}
--- /dev/null
+public abstract class Zzza {
+
+ int foo() {
+ ret<caret>x
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+public abstract class Zzza {
+
+ int foo() {
+ return <caret>x
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+PsiJavaFile:New15.java
+ PsiMethodCallExpression:new C<?>.B()
+ PsiReferenceExpression:new C<?>.B
+ PsiNewExpression:new C<?>
+ PsiKeyword:new('new')
+ PsiReferenceParameterList
+ <empty list>
+ PsiWhiteSpace(' ')
+ PsiJavaCodeReferenceElement:C<?>
+ PsiIdentifier:C('C')
+ PsiReferenceParameterList
+ PsiJavaToken:LT('<')
+ PsiTypeElement:?
+ PsiJavaToken:QUEST('?')
+ PsiJavaToken:GT('>')
+ PsiErrorElement:'(' or '[' expected
+ <empty list>
+ PsiJavaToken:DOT('.')
+ PsiReferenceParameterList
+ <empty list>
+ PsiIdentifier:B('B')
+ PsiExpressionList
+ PsiJavaToken:LPARENTH('(')
+ PsiJavaToken:RPARENTH(')')
\ No newline at end of file
configureByFile(getTestName(false) + ".java")
}
+ public void testFinalInForLoop() throws Throwable {
+ configure()
+ checkResultByFile(getTestName(false) + ".java")
+ assertOrderedEquals myFixture.lookupElementStrings, 'final'
+ }
+
public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }
public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() }
public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() }
public void testSecondAnonymousClassParameter() throws Throwable { doTest(); }
+ public void testSpaceAfterReturn() throws Throwable {
+ configure()
+ type '\n'
+ checkResultByFile(getTestName(false) + "_after.java")
+ }
+
public void testCastInstanceofedQualifier() throws Throwable { doTest(); }
public void testCastComplexInstanceofedQualifier() throws Throwable { doTest(); }
public void testNew12() { doParserTest("new int[1][2]"); }
public void testNew13() { doParserTest("new int[1][][2]"); }
public void testNew14() { doParserTest("Q.new A()"); }
+ public void testNew15() { doParserTest("new C<?>.B()"); }
public void testExprList0() { doParserTest("f(1,2)"); }
public void testExprList1() { doParserTest("f("); }
doParserTest(text, new TestParser() {
@Override
public void parse(final PsiBuilder builder) {
- ReferenceParser.parseJavaCodeReference(builder, incomplete, false, false, false);
+ ReferenceParser.parseJavaCodeReference(builder, incomplete, false, false, false, false);
}
});
}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.ide.util;
+
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.util.PsiUtil;
+
+/**
+* @author traff
+*/
+public interface ClassFilter {
+ ClassFilter INSTANTIABLE = new ClassFilter() {
+ public boolean isAccepted(PsiClass aClass) {
+ return PsiUtil.isInstantiatable(aClass);
+ }
+ };
+
+ boolean isAccepted(PsiClass aClass);
+ ClassFilter ALL = new ClassFilter() {
+ public boolean isAccepted(PsiClass aClass) {
+ return true;
+ }
+ };
+
+ interface ClassFilterWithScope extends ClassFilter {
+ GlobalSearchScope getScope();
+ }
+}
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.psi.search.GlobalSearchScope;
/**
* User: anna
* Date: Jan 24, 2005
*/
-public interface TreeClassChooser{
- ClassFilter INSTANTIATABLE = new ClassFilter() {
- public boolean isAccepted(PsiClass aClass) {
- return PsiUtil.isInstantiatable(aClass);
- }
- };
+public interface TreeClassChooser extends TreeChooser<PsiClass> {
+ PsiClass getSelected();
- PsiClass getSelectedClass();
-
- void selectClass(final PsiClass aClass);
+ void select(final PsiClass aClass);
void selectDirectory(final PsiDirectory directory);
void showDialog();
void showPopup();
-
- interface ClassFilter {
- boolean isAccepted(PsiClass aClass);
- ClassFilter ALL = new ClassFilter() {
- public boolean isAccepted(PsiClass aClass) {
- return true;
- }
- };
- }
-
- interface ClassFilterWithScope extends ClassFilter {
- GlobalSearchScope getScope();
- }
-
- interface InheritanceClassFilter extends ClassFilter{
- }
}
@NotNull
public abstract TreeClassChooser createWithInnerClassesScopeChooser(String title,
GlobalSearchScope scope,
- final TreeClassChooser.ClassFilter classFilter,
+ final ClassFilter classFilter,
@Nullable PsiClass initialClass);
@NotNull
public abstract TreeClassChooser createNoInnerClassesScopeChooser(String title,
GlobalSearchScope scope,
- TreeClassChooser.ClassFilter classFilter,
+ ClassFilter classFilter,
@Nullable PsiClass initialClass);
GlobalSearchScope scope,
PsiClass base,
PsiClass initialClass,
- TreeClassChooser.ClassFilter classFilter);
+ ClassFilter classFilter);
@NotNull
*/
package com.intellij.ui.classFilter;
-import com.intellij.ide.util.TreeClassChooser;
-import com.intellij.ide.util.TreeClassChooserFactory;
+import com.intellij.ide.util.*;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
protected JButton myAddPatternButton;
private JButton myRemoveButton;
protected Project myProject;
- private TreeClassChooser.ClassFilter myChooserFilter;
+ private ClassFilter myChooserFilter;
public ClassFilterEditor(Project project) {
this (project, null);
}
- public ClassFilterEditor(Project project, TreeClassChooser.ClassFilter classFilter) {
+ public ClassFilterEditor(Project project, com.intellij.ide.util.ClassFilter classFilter) {
super(new GridBagLayout());
myAddClassButton = new JButton(getAddButtonText());
myAddPatternButton = new JButton(getAddPatternButtonText());
return UIBundle.message("button.add.pattern");
}
- public void setFilters(ClassFilter[] filters) {
+ public void setFilters(com.intellij.ui.classFilter.ClassFilter[] filters) {
myTableModel.setFilters(filters);
}
- public ClassFilter[] getFilters() {
+ public com.intellij.ui.classFilter.ClassFilter[] getFilters() {
return myTableModel.getFilters();
}
}
protected final class FilterTableModel extends AbstractTableModel implements ItemRemovable{
- private final List<ClassFilter> myFilters = new LinkedList<ClassFilter>();
+ private final List<com.intellij.ui.classFilter.ClassFilter> myFilters = new LinkedList<com.intellij.ui.classFilter.ClassFilter>();
public static final int CHECK_MARK = 0;
public static final int FILTER = 1;
- public final void setFilters(ClassFilter[] filters) {
+ public final void setFilters(com.intellij.ui.classFilter.ClassFilter[] filters) {
myFilters.clear();
if (filters != null) {
ContainerUtil.addAll(myFilters, filters);
fireTableDataChanged();
}
- public ClassFilter[] getFilters() {
- for (Iterator<ClassFilter> it = myFilters.iterator(); it.hasNext();) {
- ClassFilter filter = it.next();
+ public com.intellij.ui.classFilter.ClassFilter[] getFilters() {
+ for (Iterator<com.intellij.ui.classFilter.ClassFilter> it = myFilters.iterator(); it.hasNext();) {
+ com.intellij.ui.classFilter.ClassFilter filter = it.next();
String pattern = filter.getPattern();
if (pattern == null || "".equals(pattern)) {
it.remove();
}
}
- return myFilters.toArray(new ClassFilter[myFilters.size()]);
+ return myFilters.toArray(new com.intellij.ui.classFilter.ClassFilter[myFilters.size()]);
}
- public ClassFilter getFilterAt(int index) {
+ public com.intellij.ui.classFilter.ClassFilter getFilterAt(int index) {
return myFilters.get(index);
}
- public int getFilterIndex(ClassFilter filter) {
+ public int getFilterIndex(com.intellij.ui.classFilter.ClassFilter filter) {
return myFilters.indexOf(filter);
}
- public void addRow(ClassFilter filter) {
+ public void addRow(com.intellij.ui.classFilter.ClassFilter filter) {
myFilters.add(filter);
int row = myFilters.size() - 1;
fireTableRowsInserted(row, row);
}
public Object getValueAt(int rowIndex, int columnIndex) {
- ClassFilter filter = myFilters.get(rowIndex);
+ com.intellij.ui.classFilter.ClassFilter filter = myFilters.get(rowIndex);
if (columnIndex == FILTER) {
return filter;
}
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
- ClassFilter filter = myFilters.get(rowIndex);
+ com.intellij.ui.classFilter.ClassFilter filter = myFilters.get(rowIndex);
if (columnIndex == FILTER) {
filter.setPattern(aValue != null? aValue.toString() : "");
}
((JLabel)component).setBorder(noFocusBorder);
}
UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
- ClassFilter filter = (ClassFilter)table.getValueAt(row, FilterTableModel.FILTER);
+ com.intellij.ui.classFilter.ClassFilter filter = (com.intellij.ui.classFilter.ClassFilter)table.getValueAt(row, FilterTableModel.FILTER);
component.setEnabled(ClassFilterEditor.this.isEnabled() && filter.isEnabled());
return component;
}
}
@NotNull
- protected ClassFilter createFilter(String pattern){
- return new ClassFilter(pattern);
+ protected com.intellij.ui.classFilter.ClassFilter createFilter(String pattern){
+ return new com.intellij.ui.classFilter.ClassFilter(pattern);
}
protected void addPatternFilter() {
if (dialog.isOK()) {
String pattern = dialog.getPattern();
if (pattern != null) {
- ClassFilter filter = createFilter(pattern);
+ com.intellij.ui.classFilter.ClassFilter filter = createFilter(pattern);
myTableModel.addRow(filter);
int row = myTableModel.getRowCount() - 1;
myTable.getSelectionModel().setSelectionInterval(row, row);
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createNoInnerClassesScopeChooser(
UIBundle.message("class.filter.editor.choose.class.title"), GlobalSearchScope.allScope(myProject), myChooserFilter, null);
chooser.showDialog();
- PsiClass selectedClass = chooser.getSelectedClass();
+ PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
- ClassFilter filter = createFilter(getJvmClassName(selectedClass));
+ com.intellij.ui.classFilter.ClassFilter filter = createFilter(getJvmClassName(selectedClass));
myTableModel.addRow(filter);
int row = myTableModel.getRowCount() - 1;
myTable.getSelectionModel().setSelectionInterval(row, row);
}
public void addPattern(String pattern) {
- ClassFilter filter = createFilter(pattern);
+ com.intellij.ui.classFilter.ClassFilter filter = createFilter(pattern);
myTableModel.addRow(filter);
}
}
}
chooser.showDialog();
- PsiClass selectedClass = chooser.getSelectedClass();
+ PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
myClassName.setText(selectedClass.getQualifiedName());
}
*/
package com.intellij.util.xml.actions;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.application.ApplicationManager;
if (!ApplicationManager.getApplication().isUnitTestMode()) {
PsiClass baseClass = getBaseClass(context, project, myBaseClass);
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project)
- .createInheritanceClassChooser(getChooserTitle(), GlobalSearchScope.allScope(project), baseClass, null, new TreeClassChooser.ClassFilter() {
+ .createInheritanceClassChooser(getChooserTitle(), GlobalSearchScope.allScope(project), baseClass, null, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return !aClass.isInterface() && !aClass.hasModifierProperty(PsiModifier.ABSTRACT);
}
});
chooser.showDialog();
- selectedClass = chooser.getSelectedClass();
+ selectedClass = chooser.getSelected();
}
else {
selectedClass = getBaseClass(context, project, myBaseClass == null ? "java.lang.Object" : myBaseClass);
*/
package com.intellij.codeInsight.completion;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Nullable
public abstract Boolean shouldFocusLookup(@NotNull CompletionParameters parameters);
-
+ @Nullable
+ public Boolean shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
+ return null;
+ }
}
};
if (autopopup) {
CommandProcessor.getInstance().runUndoTransparentAction(initCmd);
+
+ int offset = editor.getCaretModel().getOffset();
+
+ PsiElement elementAt = InjectedLanguageUtil.findInjectedElementNoCommit(psiFile, offset);
+ if (elementAt == null) {
+ elementAt = psiFile.findElementAt(offset);
+ if (elementAt == null && offset > 0) {
+ elementAt = psiFile.findElementAt(offset - 1);
+ }
+ }
+
+ Language language = elementAt != null ? PsiUtilBase.findLanguageFromElement(elementAt):psiFile.getLanguage();
+
+ for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
+ final Boolean result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API
+ if (result == Boolean.TRUE) return;
+ }
} else {
CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
}
final String newPrefix = text.subSequence(pair.first, caretOffset).toString();
if (pair.second.accepts(newPrefix)) {
scheduleRestart();
+ myRestartingPrefixConditions.clear();
return;
}
}
final int offset = myEditor.getCaretModel().getOffset();
final long stamp = myEditor.getDocument().getModificationStamp();
final Project project = getProject();
+ final boolean wasDumb = DumbService.getInstance(project).isDumb();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
return;
}
+ if (!wasDumb && DumbService.getInstance(project).isDumb()) {
+ return;
+ }
+
if (myEditor.getCaretModel().getOffset() != offset || myEditor.getDocument().getModificationStamp() != stamp) {
return;
}
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.openapi.actionSystem.IdeActions;
-import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileNameMatcher;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
-import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
final PsiElement e = parameters.getPosition();
final Project project = e.getProject();
- final PsiReference psiReference = ApplicationManager.getApplication().runReadAction(new Computable<PsiReference>() {
- public PsiReference compute() {
- //noinspection ConstantConditions
- return parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
- }
- });
+ final PsiReference psiReference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
final Pair<FileReference, Boolean> fileReferencePair = getReference(psiReference);
if (fileReferencePair != null) {
final FileReferenceSet set = first.getFileReferenceSet();
String prefix = set.getPathString().substring(0, parameters.getOffset() - set.getElement().getTextRange().getStartOffset() - set.getStartInElement());
+ final String textBeforePosition = e.getContainingFile().getText().substring(0, parameters.getOffset());
+ if (!textBeforePosition.endsWith(prefix)) {
+ final int len = textBeforePosition.length();
+ final String fragment = len > 100 ? textBeforePosition.substring(len - 100) : textBeforePosition;
+ throw new AssertionError("prefix should be some actual file string just before caret: " + prefix + "\n text=" + fragment + ";\npathString=" + set.getPathString() + ";\nelementText=" + e.getParent().getText());
+ }
- final List<String>[] pathPrefixParts = new List[] {null};
+ List<String> pathPrefixParts = null;
int lastSlashIndex;
if ((lastSlashIndex = prefix.lastIndexOf('/')) != -1) {
- pathPrefixParts[0] = StringUtil.split(prefix.substring(0, lastSlashIndex), "/");
+ pathPrefixParts = StringUtil.split(prefix.substring(0, lastSlashIndex), "/");
prefix = prefix.substring(lastSlashIndex + 1);
}
for (final String name : resultNames) {
ProgressManager.checkCanceled();
- final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {
- public PsiFile[] compute() {
- return FilenameIndex.getFilesByName(project, name, scope);
- }
- });
+ final PsiFile[] files = FilenameIndex.getFilesByName(project, name, scope);
if (files.length > 0) {
for (final PsiFile file : files) {
ProgressManager.checkCanceled();
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- public void run() {
- final VirtualFile virtualFile = file.getVirtualFile();
- if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) {
- if (contextHelper.isMine(project, virtualFile)) {
- if (pathPrefixParts[0] == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts[0])) {
- __result.addElement(new FilePathLookupItem(file, contextHelper));
- }
- }
+ final VirtualFile virtualFile = file.getVirtualFile();
+ if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) {
+ if (contextHelper.isMine(project, virtualFile)) {
+ if (pathPrefixParts == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) {
+ __result.addElement(new FilePathLookupItem(file, contextHelper));
}
}
- });
+ }
}
}
}
final ChooseByNameContributor[] nameContributors = ChooseByNameContributor.FILE_EP_NAME.getExtensions();
for (final ChooseByNameContributor contributor : nameContributors) {
try {
- names.addAll(ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends String>>() {
- public Collection<? extends String> compute() {
- return Arrays.asList(contributor.getNames(project, false));
- }
- }));
+ names.addAll(Arrays.asList(contributor.getNames(project, false)));
}
catch (ProcessCanceledException ex) {
// index corruption detected, ignore
return true;
}
- final CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
- if (completion == null || !completion.isAutopopupCompletion()) {
+ if (parameters.getInvocationCount() > 0) {
return true;
}
}
if (element == null && file != null) {
- final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset());
- if (ref instanceof PsiPolyVariantReference) {
- element = ref.getElement();
+ try {
+ final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset());
+ if (ref instanceof PsiPolyVariantReference) {
+ element = ref.getElement();
+ }
+ }
+ catch (IndexNotReadyException e) {
+ element = null;
}
}
}
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.fileTypes.FileType;
+import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiFile;
if (project.isDisposed() || !file.isValid()) return;
if (editor.isDisposed() || isMainEditor && FileEditorManager.getInstance(project).getSelectedTextEditor() != editor) return;
if (ApplicationManager.getApplication().isWriteAccessAllowed()) return; //it will fail anyway
+ if (DumbService.getInstance(project).isDumb()) return;
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(project, editor);
for(EnterHandlerDelegate delegate: Extensions.getExtensions(EnterHandlerDelegate.EP_NAME)) {
EnterHandlerDelegate.Result result = delegate.preprocessEnter(file, editor, caretOffsetRef, caretAdvanceRef, dataContext, myOriginalHandler);
+ if (caretOffsetRef.get() > document.getTextLength()) {
+ throw new AssertionError("Wrong caret offset change by " + delegate);
+ }
+
if (result == EnterHandlerDelegate.Result.Stop) return;
if (result != EnterHandlerDelegate.Result.Continue) {
text = document.getCharsSequence();
private void addInvalidFacet(final FacetState state, ModifiableFacetModel model, final Facet underlyingFacet, final String errorMessage) {
final InvalidFacetManager invalidFacetManager = InvalidFacetManager.getInstance(myModule.getProject());
- final String typeId = StringUtil.notNullize(state.getFacetType());
final InvalidFacetType type = InvalidFacetType.getInstance();
final InvalidFacetConfiguration configuration = new InvalidFacetConfiguration(state, errorMessage);
final InvalidFacet facet = createFacet(type, StringUtil.notNullize(state.getName()), configuration, underlyingFacet);
private final MyFileStatusListener myFileStatusListener;
private final CopyPasteUtil.DefaultCopyPasteListener myCopyPasteListener;
- //private final PropertiesFileListener myPropertiesFileListener;
private final WolfTheProblemSolver.ProblemListener myProblemListener;
public ProjectTreeBuilder(final Project project, JTree tree, DefaultTreeModel treeModel, Comparator<NodeDescriptor> comparator, ProjectAbstractTreeStructureBase treeStructure) {
myCopyPasteListener = new CopyPasteUtil.DefaultCopyPasteListener(getUpdater());
CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener);
- /*myPropertiesFileListener = new PropertiesFileListener();
- final PropertiesFilesManager propertiesFilesManager = PropertiesFilesManager.getInstance();
- if (propertiesFilesManager != null) {
- propertiesFilesManager.addPropertiesFileListener(myPropertiesFileListener);
- }*/
myProblemListener = new MyProblemListener();
WolfTheProblemSolver.getInstance(project).addProblemListener(myProblemListener);
PsiManager.getInstance(myProject).removePsiTreeChangeListener(myPsiTreeChangeListener);
FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener);
CopyPasteManager.getInstance().removeContentChangedListener(myCopyPasteListener);
- /* final PropertiesFilesManager propertiesFilesManager = PropertiesFilesManager.getInstance();
- if (propertiesFilesManager != null) {
- propertiesFilesManager.removePropertiesFileListener(myPropertiesFileListener);
- }*/
WolfTheProblemSolver.getInstance(myProject).removeProblemListener(myProblemListener);
}
return element;
}
- /* private class PropertiesFileListener implements PropertiesFilesManager.PropertiesFileListener {
- public void fileAdded(VirtualFile propertiesFile) {
- fileChanged(propertiesFile, null);
- }
-
- public void fileRemoved(VirtualFile propertiesFile) {
- fileChanged(propertiesFile, null);
- }
-
- public void fileChanged(VirtualFile propertiesFile, final VirtualFilePropertyEvent event) {
- if (!myProject.isDisposed()) {
- VirtualFile parent = propertiesFile.getParent();
- if (parent != null && parent.isValid()) {
- PsiDirectory dir = PsiManager.getInstance(myProject).findDirectory(parent);
- myUpdater.addSubtreeToUpdateByElement(dir);
- }
- }
- }
- }*/
-
private class MyProblemListener extends WolfTheProblemSolver.ProblemListener {
private final Alarm myUpdateProblemAlarm = new Alarm();
private final Collection<VirtualFile> myFilesToRefresh = new THashSet<VirtualFile>();
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 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.
import com.intellij.ide.IdeBundle;
import com.intellij.ide.projectView.BaseProjectTreeBuilder;
-import com.intellij.ide.projectView.PsiClassChildrenSource;
import com.intellij.ide.projectView.impl.AbstractProjectTreeStructure;
import com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase;
import com.intellij.ide.projectView.impl.ProjectTreeBuilder;
-import com.intellij.ide.projectView.impl.nodes.ClassTreeNode;
import com.intellij.ide.util.gotoByName.*;
import com.intellij.ide.util.treeView.AlphaComparator;
import com.intellij.ide.util.treeView.NodeRenderer;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.Condition;
-import com.intellij.openapi.util.Conditions;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
import com.intellij.pom.Navigatable;
-import com.intellij.psi.*;
+import com.intellij.psi.PsiDirectory;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.search.PsiShortNamesCache;
-import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
+import com.intellij.util.Query;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
-public class TreeClassChooserDialog extends DialogWrapper implements TreeClassChooser{
+abstract public class AbstractTreeClassChooserDialog<T extends PsiNamedElement> extends DialogWrapper implements TreeChooser<T> {
private Tree myTree;
- private PsiClass mySelectedClass = null;
+ private T mySelectedClass = null;
private final Project myProject;
private BaseProjectTreeBuilder myBuilder;
private TabbedPaneWrapper myTabbedPane;
private ChooseByNamePanel myGotoByNamePanel;
private final GlobalSearchScope myScope;
- @NotNull private final ClassFilter myClassFilter;
- private final PsiClass myBaseClass;
- private PsiClass myInitialClass;
- private final PsiClassChildrenSource myClassChildren;
+ @NotNull private final Filter<T> myClassFilter;
+ private final T myBaseClass;
+ private T myInitialClass;
+ private final boolean myIsShowMembers;
- public TreeClassChooserDialog(String title, Project project) {
+ public AbstractTreeClassChooserDialog(String title, Project project) {
this(title, project, null);
}
- public TreeClassChooserDialog(String title, Project project, @Nullable PsiClass initialClass) {
+ public AbstractTreeClassChooserDialog(String title, Project project, @Nullable T initialClass) {
this(title, project, GlobalSearchScope.projectScope(project), null, initialClass);
}
- public TreeClassChooserDialog(String title, Project project, GlobalSearchScope scope, @Nullable ClassFilter classFilter, @Nullable PsiClass initialClass) {
- this(title, project, scope, classFilter, null, initialClass, PsiClassChildrenSource.NONE);
+ public AbstractTreeClassChooserDialog(String title,
+ Project project,
+ GlobalSearchScope scope,
+ @Nullable Filter<T> classFilter,
+ @Nullable T initialClass) {
+ this(title, project, scope, classFilter, null, initialClass, false);
}
- public TreeClassChooserDialog(String title,
- Project project,
- GlobalSearchScope scope,
- @Nullable ClassFilter classFilter,
- PsiClass baseClass,
- @Nullable PsiClass initialClass,
- PsiClassChildrenSource classChildren) {
+ public AbstractTreeClassChooserDialog(String title,
+ Project project,
+ GlobalSearchScope scope,
+ @Nullable Filter<T> classFilter,
+ T baseClass,
+ @Nullable T initialClass,
+ boolean isShowMembers) {
super(project, true);
myScope = scope;
- myClassFilter = classFilter == null ? ClassFilter.ALL : classFilter;
+ myClassFilter = classFilter == null ? allFilter() : classFilter;
myBaseClass = baseClass;
myInitialClass = initialClass;
- myClassChildren = classChildren;
+ myIsShowMembers = isShowMembers;
setTitle(title);
myProject = project;
init();
if (initialClass != null) {
- selectClass(initialClass);
+ select(initialClass);
}
handleSelectionChanged();
}
- public static TreeClassChooserDialog withInnerClasses(String title,
- Project project,
- GlobalSearchScope scope,
- final ClassFilter classFilter,
- @Nullable PsiClass initialClass) {
- return new TreeClassChooserDialog(title, project, scope, classFilter, null, initialClass, new PsiClassChildrenSource() {
- public void addChildren(PsiClass psiClass, List<PsiElement> children) {
- ArrayList<PsiElement> innerClasses = new ArrayList<PsiElement>();
- PsiClassChildrenSource.CLASSES.addChildren(psiClass, innerClasses);
- for (PsiElement innerClass : innerClasses) {
- if (classFilter.isAccepted((PsiClass)innerClass)) children.add(innerClass);
- }
+ private Filter<T> allFilter() {
+ return new Filter<T>() {
+ public boolean isAccepted(T element) {
+ return true;
}
- });
+ };
}
protected JComponent createCenterPanel() {
}
public boolean isShowMembers() {
- return myClassChildren != PsiClassChildrenSource.NONE;
+ return myIsShowMembers;
}
public boolean isHideEmptyMiddlePackages() {
}
protected ChooseByNameModel createChooseByNameModel() {
- return myBaseClass == null ? new MyGotoClassModel(myProject) : new SubclassGotoClassModel(myProject);
+ if (myBaseClass == null) {
+ return new MyGotoClassModel(myProject, this);
+ }
+ else {
+ BaseClassInheritorsProvider<T> inheritorsProvider = getInheritorsProvider();
+ if (inheritorsProvider != null) {
+ return new SubclassGotoClassModel(myProject, this, inheritorsProvider);
+ }
+ else {
+ throw new IllegalStateException("inheritors provider is null");
+ }
+ }
}
- private void handleSelectionChanged(){
- PsiClass selection = calcSelectedClass();
+ @Nullable
+ protected abstract BaseClassInheritorsProvider<T> getInheritorsProvider();
+
+ private void handleSelectionChanged() {
+ T selection = calcSelectedClass();
setOKActionEnabled(selection != null);
}
protected void doOKAction() {
mySelectedClass = calcSelectedClass();
if (mySelectedClass == null) return;
- if (!myClassFilter.isAccepted(mySelectedClass)){
- Messages.showErrorDialog(myTabbedPane.getComponent(), SymbolPresentationUtil.getSymbolPresentableText(mySelectedClass) + " is not acceptable");
+ if (!myClassFilter.isAccepted(mySelectedClass)) {
+ Messages.showErrorDialog(myTabbedPane.getComponent(),
+ SymbolPresentationUtil.getSymbolPresentableText(mySelectedClass) + " is not acceptable");
return;
}
super.doOKAction();
}
- public PsiClass getSelectedClass() {
+ public T getSelected() {
return mySelectedClass;
}
- public void selectClass(@NotNull final PsiClass aClass) {
+ public void select(@NotNull final T aClass) {
selectElementInTree(aClass);
}
ChooseByNamePopup popup = ChooseByNamePopup.createPopup(myProject, createChooseByNameModel(), getContext());
popup.invoke(new ChooseByNamePopupComponent.Callback() {
public void elementChosen(Object element) {
- mySelectedClass = (PsiClass)element;
+ mySelectedClass = (T)element;
((Navigatable)element).navigate(true);
}
}, getModalityState(), true);
}
- private PsiClass getContext() {
+ private T getContext() {
return myBaseClass != null ? myBaseClass : myInitialClass != null ? myInitialClass : null;
}
- private void selectElementInTree(@NotNull final PsiElement element) {
+ private <E extends PsiElement> void selectElementInTree(@NotNull final PsiElement element) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (myBuilder == null) return;
return ModalityState.stateForComponent(getRootPane());
}
+
@Nullable
- private PsiClass calcSelectedClass() {
- if (myTabbedPane.getSelectedIndex() == 0) {
- return (PsiClass)myGotoByNamePanel.getChosenElement();
+ protected T calcSelectedClass() {
+ if (getTabbedPane().getSelectedIndex() == 0) {
+ return (T)getGotoByNamePanel().getChosenElement();
}
else {
- TreePath path = myTree.getSelectionPath();
+ TreePath path = getTree().getSelectionPath();
if (path == null) return null;
DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
- Object userObject = node.getUserObject();
- if (!(userObject instanceof ClassTreeNode)) return null;
- ClassTreeNode descriptor = (ClassTreeNode)userObject;
- return descriptor.getPsiClass();
+ return getSelectedFromTreeUserObject(node);
}
}
+ protected abstract T getSelectedFromTreeUserObject(DefaultMutableTreeNode node);
+
public void dispose() {
if (myBuilder != null) {
return myGotoByNamePanel.getPreferredFocusedComponent();
}
- private class MyGotoClassModel extends GotoClassModel2 {
- public MyGotoClassModel(Project project) {
+ protected Project getProject() {
+ return myProject;
+ }
+
+ GlobalSearchScope getScope() {
+ return myScope;
+ }
+
+ @NotNull
+ protected Filter<T> getFilter() {
+ return myClassFilter;
+ }
+
+ T getBaseClass() {
+ return myBaseClass;
+ }
+
+ T getInitialClass() {
+ return myInitialClass;
+ }
+
+ protected TabbedPaneWrapper getTabbedPane() {
+ return myTabbedPane;
+ }
+
+ protected Tree getTree() {
+ return myTree;
+ }
+
+ protected ChooseByNamePanel getGotoByNamePanel() {
+ return myGotoByNamePanel;
+ }
+
+ protected static class MyGotoClassModel<T extends PsiNamedElement> extends GotoClassModel2 {
+ private final AbstractTreeClassChooserDialog<T> myTreeClassChooserDialog;
+
+ AbstractTreeClassChooserDialog<T> getTreeClassChooserDialog() {
+ return myTreeClassChooserDialog;
+ }
+
+ public MyGotoClassModel(Project project,
+ AbstractTreeClassChooserDialog<T> treeClassChooserDialog) {
super(project);
+ myTreeClassChooserDialog = treeClassChooserDialog;
}
public Object[] getElementsByName(final String name, final boolean checkBoxState, final String pattern) {
- final PsiShortNamesCache cache = JavaPsiFacade.getInstance(myProject).getShortNamesCache();
- PsiClass[] classes = cache.getClassesByName(name, checkBoxState ? myScope : GlobalSearchScope.projectScope(myProject).intersectWith(myScope));
- if (classes.length == 0) return ArrayUtil.EMPTY_OBJECT_ARRAY;
- if (classes.length == 1) {
- return isAccepted(classes[0]) ? classes : ArrayUtil.EMPTY_OBJECT_ARRAY;
+ List<T> classes = myTreeClassChooserDialog.getClassesByName(name, checkBoxState, pattern, myTreeClassChooserDialog.getScope());
+ if (classes.size() == 0) return ArrayUtil.EMPTY_OBJECT_ARRAY;
+ if (classes.size() == 1) {
+ return isAccepted(classes.get(0)) ? classes.toArray(new Object[classes.size()]) : ArrayUtil.EMPTY_OBJECT_ARRAY;
}
- List<PsiClass> list = new ArrayList<PsiClass>(classes.length);
- for (PsiClass aClass : classes) {
+ List<T> list = new ArrayList<T>(classes.size());
+ for (T aClass : classes) {
if (isAccepted(aClass)) {
list.add(aClass);
}
}
- return list.toArray(new PsiClass[list.size()]);
+ return list.toArray(new Object[list.size()]);
}
@Nullable
return null;
}
- protected boolean isAccepted(PsiClass aClass) {
- return myClassFilter.isAccepted(aClass);
+ protected boolean isAccepted(T aClass) {
+ return myTreeClassChooserDialog.getFilter().isAccepted(aClass);
+ }
+ }
+
+
+ @NotNull
+ abstract protected List<T> getClassesByName(final String name,
+ final boolean checkBoxState,
+ final String pattern,
+ final GlobalSearchScope searchScope);
+
+ public static abstract class BaseClassInheritorsProvider<T> {
+ private final T myBaseClass;
+ private final GlobalSearchScope myScope;
+
+ public T getBaseClass() {
+ return myBaseClass;
+ }
+
+ public GlobalSearchScope getScope() {
+ return myScope;
+ }
+
+ public BaseClassInheritorsProvider(T baseClass, GlobalSearchScope scope) {
+ myBaseClass = baseClass;
+ myScope = scope;
+ }
+
+ @NotNull
+ abstract protected Query<T> searchForInheritors(T baseClass, GlobalSearchScope searchScope, boolean checkDeep);
+
+ abstract protected boolean isInheritor(T clazz, T baseClass, boolean checkDeep);
+
+ abstract protected String[] getNames();
+
+ protected Query<T> searchForInheritorsOfBaseClass() {
+ return searchForInheritors(myBaseClass, myScope, true);
+ }
+
+ protected boolean isInheritorOfBaseClass(T aClass) {
+ return isInheritor(aClass, myBaseClass, true);
}
}
- private class SubclassGotoClassModel extends MyGotoClassModel {
+ private static class SubclassGotoClassModel<T extends PsiNamedElement> extends MyGotoClassModel<T> {
+ private final BaseClassInheritorsProvider<T> myInheritorsProvider;
private boolean myFastMode = true;
- public SubclassGotoClassModel(final Project project) {
- super(project);
- assert myBaseClass != null;
+ public SubclassGotoClassModel(@NotNull final Project project,
+ @NotNull final AbstractTreeClassChooserDialog<T> treeClassChooserDialog,
+ @NotNull BaseClassInheritorsProvider<T> inheritorsProvider) {
+ super(project, treeClassChooserDialog);
+ myInheritorsProvider = inheritorsProvider;
+ assert myInheritorsProvider.getBaseClass() != null;
}
public String[] getNames(boolean checkBoxState) {
if (!myFastMode) {
- return JavaPsiFacade.getInstance(myProject).getShortNamesCache().getAllClassNames();
+ return myInheritorsProvider.getNames();
}
final List<String> names = new ArrayList<String>();
- myFastMode = ClassInheritorsSearch.search(myBaseClass, myScope, true).forEach(new Processor<PsiClass>() {
+
+ myFastMode = myInheritorsProvider.searchForInheritorsOfBaseClass().forEach(new Processor<T>() {
private int count;
+
@Override
- public boolean process(PsiClass aClass) {
+ public boolean process(T aClass) {
if (count++ > 1000) {
return false;
}
- if ((myClassFilter.isAccepted(aClass)) && aClass.getName() != null) {
+ if ((getTreeClassChooserDialog().getFilter().isAccepted(aClass)) && aClass.getName() != null) {
names.add(aClass.getName());
}
return true;
if (!myFastMode) {
return getNames(checkBoxState);
}
- if ((myClassFilter.isAccepted(myBaseClass)) && myBaseClass.getName() != null) {
- names.add(myBaseClass.getName());
+ if ((getTreeClassChooserDialog().getFilter().isAccepted(myInheritorsProvider.getBaseClass())) &&
+ myInheritorsProvider.getBaseClass().getName() != null) {
+ names.add(myInheritorsProvider.getBaseClass().getName());
}
return names.toArray(new String[names.size()]);
}
- protected boolean isAccepted(PsiClass aClass) {
+
+ protected boolean isAccepted(T aClass) {
if (myFastMode) {
- return myClassFilter.isAccepted(aClass);
+ return getTreeClassChooserDialog().getFilter().isAccepted(aClass);
}
else {
- return (aClass == myBaseClass || aClass.isInheritor(myBaseClass, true)) && myClassFilter.isAccepted(aClass);
+ return (aClass == getTreeClassChooserDialog().getBaseClass() ||
+ myInheritorsProvider.isInheritorOfBaseClass(aClass)) &&
+ getTreeClassChooserDialog().getFilter().isAccepted(
+ aClass);
}
}
}
+
private class MyCallback extends ChooseByNamePopupComponent.Callback {
public void elementChosen(Object element) {
- mySelectedClass = (PsiClass)element;
+ mySelectedClass = (T)element;
close(OK_EXIT_CODE);
}
}
-
- public static class InheritanceClassFilterImpl implements InheritanceClassFilter{
- private final PsiClass myBase;
- private final boolean myAcceptsSelf;
- private final boolean myAcceptsInner;
- private final Condition<? super PsiClass> myAdditionalCondition;
-
- public InheritanceClassFilterImpl(PsiClass base,
- boolean acceptsSelf,
- boolean acceptInner,
- Condition<? super PsiClass> additionalCondition) {
- myAcceptsSelf = acceptsSelf;
- myAcceptsInner = acceptInner;
- if (additionalCondition == null) {
- additionalCondition = Conditions.alwaysTrue();
- }
- myAdditionalCondition = additionalCondition;
- myBase = base;
- }
-
- public boolean isAccepted(PsiClass aClass) {
- if (!myAcceptsInner && !(aClass.getParent() instanceof PsiJavaFile)) return false;
- if (!myAdditionalCondition.value(aClass)) return false;
- // we've already checked for inheritance
- return myAcceptsSelf || !aClass.getManager().areElementsEquivalent(aClass, myBase);
- }
- }
}
protected void doClose(final boolean ok) {
if (myDisposedFlag) return;
- if (posponeCloseWhenListReady(ok)) return;
+ if (postponeCloseWhenListReady(ok)) return;
cancelListUpdater();
close(ok);
myListUpdater.cancelAll();
}
- private boolean posponeCloseWhenListReady(boolean ok) {
+ private boolean postponeCloseWhenListReady(boolean ok) {
if (!isToFixLostTyping()) return false;
final String text = myTextField.getText();
VirtualFile parent = file.getParent();
if (parent == null) return;
- IndexState state = myState.copy();
+ IndexState newState = myState.copy();
+ updateStateWithNewFile(file, parent, newState);
+ myState = newState;
+ }
+ private void updateStateWithNewFile(VirtualFile file, VirtualFile parent, IndexState state) {
DirectoryInfo parentInfo = state.myDirToInfoMap.get(parent);
// fill info for all nested roots
if (!parentInfo.getOrderEntries().isEmpty()) {
state.fillMapWithOrderEntries(file, parentInfo.getOrderEntries(), null, null, null, parentInfo, null);
}
- myState = state;
}
public void beforeFileDeletion(VirtualFileEvent event) {
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadActionProcessor;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
public boolean processFilesWithWord(@NotNull final Processor<PsiFile> psiFileProcessor, @NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively) {
final Set<VirtualFile> vFiles = new THashSet<VirtualFile>();
final GlobalSearchScope projectScope = GlobalSearchScope.allScope(myProject);
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- public void run() {
- FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
- public boolean process(final VirtualFile file, final Integer value) {
- ProgressManager.checkCanceled();
- final int mask = value.intValue();
- if ((mask & occurrenceMask) != 0) {
- vFiles.add(file);
+ try {
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ public void run() {
+ FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
+ public boolean process(final VirtualFile file, final Integer value) {
+ ProgressManager.checkCanceled();
+ final int mask = value.intValue();
+ if ((mask & occurrenceMask) != 0) {
+ vFiles.add(file);
+ }
+ return true;
}
- return true;
- }
- }, projectScope);
- }
- });
+ }, projectScope);
+ }
+ });
+ }
+ catch (IndexNotReadyException e) {
+ throw new ProcessCanceledException();
+ }
if (vFiles.isEmpty()) return true;
}
else {
final ASTNode parent = oldNode.getTreeParent();
+ assert parent != null : "old:" + oldNode + " new:" + newNode;
TreeUtil.ensureParsed(oldNode);
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.ui.impl.DialogWrapperPeerImpl;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
text = doClone ?
RefactoringBundle.message("copy.files.clone.file.0", file.getVirtualFile().getPresentableUrl()) :
RefactoringBundle.message("copy.files.copy.file.0", file.getVirtualFile().getPresentableUrl());
- myNewNameField.setText(file.getName());
+ final String fileName = file.getName();
+ myNewNameField.setText(fileName);
+ final int dotIdx = fileName.lastIndexOf(".");
+ if (dotIdx > -1) {
+ myNewNameField.select(0, dotIdx);
+ myNewNameField.putClientProperty(DialogWrapperPeerImpl.HAVE_INITIAL_SELECTION, true);
+ }
}
else {
PsiDirectory directory = (PsiDirectory)elements[0];
public static synchronized IdeaPluginDescriptor[] getPlugins() {
if (ourPlugins == null) {
initializePlugins();
- getLogger().info("Loaded plugins:" + StringUtil.join(ourPlugins, new Function<IdeaPluginDescriptorImpl, String>() {
- public String fun(IdeaPluginDescriptorImpl descriptor) {
- final String version = descriptor.getVersion();
- return descriptor.getName() + (version != null ? " (" + version + ")" : "");
- }
- }, ", "));
+ logPlugins();
ClassloaderUtil.clearJarURLCache();
}
return ourPlugins;
}
+ private static void logPlugins() {
+ List<String> loaded = new ArrayList<String>();
+ List<String> disabled = new ArrayList<String>();
+ for (IdeaPluginDescriptorImpl descriptor : ourPlugins) {
+ final String version = descriptor.getVersion();
+ String s = descriptor.getName() + (version != null ? " (" + version + ")" : "");
+ if (descriptor.isEnabled()) {
+ loaded.add(s);
+ }
+ else {
+ disabled.add(s);
+ }
+ }
+ getLogger().info("Loaded plugins:" + StringUtil.join(loaded, ", "));
+ if (!disabled.isEmpty()) {
+ getLogger().info("Disabled plugins: " + StringUtil.join(disabled, ", "));
+ }
+ }
+
public static void invalidatePlugins() {
ourPlugins = null;
ourDisabledPlugins = null;
--- /dev/null
+/*
+ * Copyright 2000-2010 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.ide.util;
+
+import com.intellij.psi.PsiDirectory;
+
+public interface TreeChooser<T> {
+ T getSelected();
+
+ void select(final T aClass);
+
+ void selectDirectory(final PsiDirectory directory);
+
+ void showDialog();
+
+ void showPopup();
+
+ interface Filter<T> {
+ boolean isAccepted(T element);
+ }
+}
if (!force) {
if (!showConfirmation()) {
saveAll();
+ myExitCode = 0;
return;
}
}
saveSettings();
- if (!canExit()) return;
+ if (!canExit()) {
+ myExitCode = 0;
+ return;
+ }
- boolean success = disposeSelf();
- if (success && !isUnitTestMode()) {
- System.exit(myExitCode);
+ final boolean success = disposeSelf();
+ if (!success || isUnitTestMode()) {
+ myExitCode = 0;
+ return;
}
+
+ System.exit(myExitCode);
}
};
-
+
if (!isDispatchThread()) {
invokeLater(runnable, ModalityState.NON_MODAL);
}
import java.util.Iterator;
import java.util.List;
-@SuppressWarnings({"ForLoopReplaceableByForEach"}) // Way too many garbage in AbrstractList.iterator() produced otherwise.
+@SuppressWarnings({"ForLoopReplaceableByForEach"}) // Way too many garbage in AbstractList.iterator() produced otherwise.
public final class IterationState {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.IterationState");
private final TextAttributes myMergedAttributes = new TextAttributes();
title.upgrade.needed=Upgrade Needed
message.evaluation.has.expired=Your {0} evaluation has expired. Your session will be limited to 30 minutes.<br>{1}
title.evaluation.license.expired=Evaluation License Expired
+message.evaluation.license.expired=Your evaluation license has expired. {0} will now exit.
message.license.expired=Your license has expired
title.license.expired=License Expired
message.license.is.corrupt=License is corrupt
message.evaluation.N.days={0} days
message.evaluation.one.day=1 day
message.evaluation.less.than.one.day=less than 1 day
-message.evaluation.will.expire=Thank you for evaluating {0}.<br>Your evaluation license expires in {1}<br><br>{2}<br>You can then register the commercial license using the Help menu.
+message.evaluation.will.expire=Thank you for evaluating {0}.<br>Your evaluation license expires in {1}<br><br>{2}
title.license.will.expire={0} License Expires Soon
message.license.will.expire=Your {0} license expires in {1}.
error.saving.license.data=Error saving license data.\n{0}
link.purchase.commercial.license=To purchase a commercial license, please visit
license.panel.expirable.license.description=The license will expire on {0,date,MMMM dd, yyyy}
license.panel.maintenance.aware.license.description=Entitled for free updates and upgrades until {0,date,MMMM dd, yyyy}
+license.panel.perpetual.license.description=Perpetual license
license.panel.current.permanent.ticket.description=Permanent ticket obtained
license.panel.current.floating.ticket.description=Floating ticket obtained
license.panel.buildit.evaluation.expires.in.one=1 day left
* Returns null if no escapement necessary.
*/
@Nullable
- private static String escapeChar(char c, boolean escapeLineEnds) {
+ private static String escapeChar(char c, boolean escapeSpaces, boolean escapeLineEnds) {
switch (c) {
case '\n': return escapeLineEnds ? " " : null;
case '\r': return escapeLineEnds ? " " : null;
case '\t': return escapeLineEnds ? "	" : null;
+ case ' ' : return escapeSpaces ? "" : null;
case '<': return "<";
case '>': return ">";
case '\"': return """;
@NotNull
public static String escapeText(String text) {
- return escapeText(text, false);
+ return escapeText(text, false, false);
}
@NotNull
- private static String escapeText(String text, boolean escapeLineEnds) {
+ public static String escapeText(String text, boolean escapeSpaces, boolean escapeLineEnds) {
StringBuffer buffer = null;
for (int i = 0; i < text.length(); i++) {
final char ch = text.charAt(i);
- final String quotation = escapeChar(ch, escapeLineEnds);
+ final String quotation = escapeChar(ch, escapeSpaces, escapeLineEnds);
if (buffer == null) {
if (quotation != null) {
public static class MyXMLOutputter extends XMLOutputter {
public String escapeAttributeEntities(String str) {
- return escapeText(str, true);
+ return escapeText(str, false, true);
}
public String escapeElementEntities(String str) {
- return escapeText(str, false);
+ return escapeText(str, false, false);
}
}
}
private static String calcCanonicalTempPath() {
- final String prop = System.getProperty("java.io.tmpdir");
+ final File file = new File(System.getProperty("java.io.tmpdir"));
try {
- return new File(prop).getCanonicalPath();
+ final String canonical = file.getCanonicalPath();
+ if (!SystemInfo.isWindows || !canonical.contains(" ")) {
+ return canonical;
+ }
}
- catch (IOException e) {
- return prop;
+ catch (IOException ignore) {
}
+ return file.getAbsolutePath();
}
public static void asyncDelete(@NotNull File file) {
non.static.inner.class.in.secure.context.display.name=Non-static inner class in secure context
tail.recursion.display.name=Tail recursion
finally.block.cannot.complete.normally.display.name='finally' block which can not complete normally
-arithmetic.on.volatile.field.display.name=Arithmetic operation on volatile field
+non.atomic.operation.on.volatile.field.display.name=Non-atomic operation on volatile field
public.static.collection.field.display.name='public static' collection field
non.exception.name.ends.with.exception.display.name=Non-exception class name ends with 'Exception'
synchronized.method.display.name='synchronized' method
serializable.inner.class.with.non.serializable.outer.class.problem.descriptor=Inner class <code>#ref</code> is serializable while its outer class is not #loc
busy.wait.problem.descriptor=Call to <code>Thread.#ref()</code> in a loop, probably busy-waiting #loc
sleep.while.holding.lock.problem.descriptor=Call to <code>Thread.#ref()</code> while synchronized #loc
-arithmetic.on.volatile.field.problem.descriptor=Arithmetic operation on volatile field <code>#ref</code> #loc
+non.atomic.operation.on.volatile.field.problem.descriptor=Non-atomic operation on volatile field <code>#ref</code> #loc
call.to.native.method.while.locked.problem.descriptor=Call to native method <code>#ref()</code> in a synchronized context #loc
object.notify.problem.descriptor=<code>#ref</code> should probably be replaced with 'notifyAll()' #loc
condition.signal.problem.descriptor=<code>#ref</code> should probably be replaced with 'signalAll()' #loc
private void registerThreadingInspections() {
m_inspectionClasses.add(AccessToNonThreadSafeStaticFieldFromInstanceInspection.class);
m_inspectionClasses.add(AccessToStaticFieldLockedOnInstanceInspection.class);
- m_inspectionClasses.add(ArithmeticOnVolatileFieldInspection.class);
m_inspectionClasses.add(AwaitNotInLoopInspection.class);
m_inspectionClasses.add(AwaitWithoutCorrespondingSignalInspection.class);
m_inspectionClasses.add(BusyWaitInspection.class);
m_inspectionClasses.add(MethodMayBeSynchronizedInspection.class);
m_inspectionClasses.add(NakedNotifyInspection.class);
m_inspectionClasses.add(NestedSynchronizedStatementInspection.class);
+ m_inspectionClasses.add(NonAtomicOperationOnVolatileFieldInspection.class);
m_inspectionClasses.add(NonSynchronizedMethodOverridesSynchronizedMethodInspection.class);
m_inspectionClasses.add(NotifyCalledOnConditionInspection.class);
m_inspectionClasses.add(NotifyNotInSynchronizedContextInspection.class);
/*
- * Copyright 2006-2008 Bas Leijdekkers
+ * Copyright 2006-2010 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
if (context instanceof PsiSynchronizedStatement) {
return true;
}
- if (context != null) {
- final PsiModifierListOwner modifierListOwner =
- (PsiModifierListOwner)context;
- if (modifierListOwner.hasModifierProperty(
- PsiModifier.SYNCHRONIZED)) {
- return true;
- }
+ if (context == null) {
+ return false;
}
- return false;
+ final PsiModifierListOwner modifierListOwner =
+ (PsiModifierListOwner)context;
+ return modifierListOwner.hasModifierProperty(PsiModifier.SYNCHRONIZED);
}
}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
- *
- * 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.siyeh.ig.threading;
-
-import com.intellij.psi.*;
-import com.intellij.psi.tree.IElementType;
-import com.siyeh.InspectionGadgetsBundle;
-import com.siyeh.ig.BaseInspection;
-import com.siyeh.ig.BaseInspectionVisitor;
-import com.siyeh.ig.psiutils.WellFormednessUtils;
-import org.jetbrains.annotations.NotNull;
-
-public class ArithmeticOnVolatileFieldInspection extends BaseInspection {
-
- @NotNull
- public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "arithmetic.on.volatile.field.display.name");
- }
-
- @NotNull
- protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "arithmetic.on.volatile.field.problem.descriptor");
- }
-
- public BaseInspectionVisitor buildVisitor() {
- return new AritmeticOnVolatileFieldInspection();
- }
-
- private static class AritmeticOnVolatileFieldInspection
- extends BaseInspectionVisitor {
-
- @Override public void visitBinaryExpression(
- @NotNull PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
- if (expression.getROperand() == null) {
- return;
- }
- final PsiJavaToken sign = expression.getOperationSign();
- final IElementType tokenType = sign.getTokenType();
- if (!JavaTokenType.ASTERISK.equals(tokenType) &&
- !JavaTokenType.DIV.equals(tokenType) &&
- !JavaTokenType.PLUS.equals(tokenType) &&
- !JavaTokenType.MINUS.equals(tokenType) &&
- !JavaTokenType.PERC.equals(tokenType)) {
- return;
- }
- final PsiExpression lhs = expression.getLOperand();
- checkForVolatile(lhs);
- final PsiExpression rhs = expression.getROperand();
- checkForVolatile(rhs);
- }
-
- @Override public void visitAssignmentExpression(
- @NotNull PsiAssignmentExpression expression) {
- super.visitAssignmentExpression(expression);
- if (!WellFormednessUtils.isWellFormed(expression)) {
- return;
- }
- final PsiJavaToken sign = expression.getOperationSign();
- final IElementType tokenType = sign.getTokenType();
- if (!JavaTokenType.ASTERISKEQ.equals(tokenType) &&
- !JavaTokenType.DIVEQ.equals(tokenType) &&
- !JavaTokenType.PLUSEQ.equals(tokenType) &&
- !JavaTokenType.MINUSEQ.equals(tokenType) &&
- !JavaTokenType.PERCEQ.equals(tokenType)) {
- return;
- }
- final PsiExpression lhs = expression.getLExpression();
- checkForVolatile(lhs);
- final PsiExpression rhs = expression.getRExpression();
- checkForVolatile(rhs);
- }
-
- private void checkForVolatile(PsiExpression expression) {
- if (!(expression instanceof PsiReferenceExpression)) {
- return;
- }
- final PsiReferenceExpression reference =
- (PsiReferenceExpression)expression;
- final PsiElement referent = reference.resolve();
- if (!(referent instanceof PsiField)) {
- return;
- }
- final PsiField field = (PsiField)referent;
- if (field.hasModifierProperty(PsiModifier.VOLATILE)) {
- registerError(expression);
- }
- }
- }
-}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
+ *
+ * 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.siyeh.ig.threading;
+
+import com.intellij.psi.*;
+import com.intellij.psi.tree.IElementType;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.psiutils.SynchronizationUtil;
+import com.siyeh.ig.psiutils.VariableAccessUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class NonAtomicOperationOnVolatileFieldInspection
+ extends BaseInspection {
+
+ @Override
+ @NotNull
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message(
+ "non.atomic.operation.on.volatile.field.display.name");
+ }
+
+ @Override
+ @NotNull
+ protected String buildErrorString(Object... infos) {
+ return InspectionGadgetsBundle.message(
+ "non.atomic.operation.on.volatile.field.problem.descriptor");
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new NonAtomicOperationOnVolatileFieldVisitor();
+ }
+
+ private static class NonAtomicOperationOnVolatileFieldVisitor
+ extends BaseInspectionVisitor {
+
+ @Override public void visitAssignmentExpression(
+ @NotNull PsiAssignmentExpression expression) {
+ super.visitAssignmentExpression(expression);
+ final PsiExpression rhs = expression.getRExpression();
+ if (rhs == null) {
+ return;
+ }
+ final PsiExpression lhs = expression.getLExpression();
+ final PsiField volatileField = findNonSynchronizedVolatileField(lhs);
+ if (volatileField == null) {
+ return;
+ }
+ final IElementType tokenType = expression.getOperationTokenType();
+ if (tokenType.equals(JavaTokenType.PLUSEQ) ||
+ tokenType.equals(JavaTokenType.MINUSEQ) ||
+ tokenType.equals(JavaTokenType.ASTERISKEQ) ||
+ tokenType.equals(JavaTokenType.DIVEQ) ||
+ tokenType.equals(JavaTokenType.ANDEQ) ||
+ tokenType.equals(JavaTokenType.OREQ)||
+ tokenType.equals(JavaTokenType.XOREQ)||
+ tokenType.equals(JavaTokenType.PERCEQ)||
+ tokenType.equals(JavaTokenType.LTLTEQ)||
+ tokenType.equals(JavaTokenType.GTGTEQ)||
+ tokenType.equals(JavaTokenType.GTGTGTEQ)) {
+ registerError(lhs);
+ return;
+ }
+ if (VariableAccessUtils.variableIsUsed(volatileField, rhs)) {
+ registerError(lhs);
+ }
+ }
+
+ @Override
+ public void visitPrefixExpression(PsiPrefixExpression expression) {
+ super.visitPrefixExpression(expression);
+ final PsiExpression operand = expression.getOperand();
+ if (operand == null) {
+ return;
+ }
+ final PsiField volatileField =
+ findNonSynchronizedVolatileField(operand);
+ if (volatileField == null) {
+ return;
+ }
+ registerError(operand);
+ }
+
+ @Override
+ public void visitPostfixExpression(PsiPostfixExpression expression) {
+ super.visitPostfixExpression(expression);
+ final PsiExpression operand = expression.getOperand();
+ final PsiField volatileField =
+ findNonSynchronizedVolatileField(operand);
+ if (volatileField == null) {
+ return;
+ }
+ registerError(operand);
+ }
+
+ @Nullable
+ private static PsiField findNonSynchronizedVolatileField(
+ PsiExpression expression) {
+ if (!(expression instanceof PsiReferenceExpression)) {
+ return null;
+ }
+ final PsiReferenceExpression reference =
+ (PsiReferenceExpression)expression;
+ if (SynchronizationUtil.isInSynchronizedContext(reference)) {
+ return null;
+ }
+ final PsiElement referent = reference.resolve();
+ if (!(referent instanceof PsiField)) {
+ return null;
+ }
+ final PsiField field = (PsiField)referent;
+ if (!field.hasModifierProperty(PsiModifier.VOLATILE)) {
+ return null;
+ }
+ return field;
+ }
+ }
+}
\ No newline at end of file
import com.intellij.codeInspection.ui.ListTable;
import com.intellij.codeInspection.ui.ListWrappingTableModel;
import com.intellij.ide.DataManager;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.actionSystem.DataContext;
}
final TreeClassChooserFactory chooserFactory =
TreeClassChooserFactory.getInstance(project);
- final TreeClassChooser.ClassFilter filter;
+ final ClassFilter filter;
if (ancestorClasses.length == 0) {
- filter = TreeClassChooser.ClassFilter.ALL;
+ filter = ClassFilter.ALL;
} else {
- filter = new TreeClassChooser.ClassFilter() {
+ filter = new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
for (String ancestorClass : ancestorClasses) {
if (ClassUtils.isSubclass(aClass, ancestorClass)) {
chooserFactory.createWithInnerClassesScopeChooser(chooserTitle,
GlobalSearchScope.allScope(project), filter, null);
classChooser.showDialog();
- final PsiClass selectedClass = classChooser.getSelectedClass();
+ final PsiClass selectedClass = classChooser.getSelected();
if (selectedClass == null) {
return;
}
import com.intellij.codeInspection.ui.ListTable;
import com.intellij.codeInspection.ui.ListWrappingTableModel;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.actionSystem.*;
public static ActionToolbar createAddRemoveTreeClassChooserToolbar(
ListTable table, String chooserTitle,
@NonNls String... ancestorClasses) {
- final TreeClassChooser.ClassFilter filter;
+ final ClassFilter filter;
if (ancestorClasses.length == 0) {
- filter = TreeClassChooser.ClassFilter.ALL;
+ filter = ClassFilter.ALL;
} else {
filter = new SubclassFilter(ancestorClasses);
}
public static ActionToolbar createAddRemoveTreeAnnotationChooserToolbar(
ListTable table, String chooserTitle) {
- final TreeClassChooser.ClassFilter filter =
- new TreeClassChooser.ClassFilter() {
+ final ClassFilter filter =
+ new ClassFilter() {
public boolean isAccepted(PsiClass psiClass) {
return psiClass.isAnnotationType();
}
private final ListTable table;
private final String chooserTitle;
- private final TreeClassChooser.ClassFilter filter;
+ private final ClassFilter myFilter;
public TreeClassChooserAction(
@NotNull ListTable table, @NotNull String chooserTitle,
- @NotNull TreeClassChooser.ClassFilter filter) {
+ @NotNull ClassFilter filter) {
super(InspectionGadgetsBundle.message("button.add"), "",
Icons.ADD_ICON);
this.table = table;
this.chooserTitle = chooserTitle;
- this.filter = filter;
+ this.myFilter = filter;
}
@Override
TreeClassChooserFactory.getInstance(project);
final TreeClassChooser classChooser =
chooserFactory.createWithInnerClassesScopeChooser(chooserTitle,
- GlobalSearchScope.allScope(project), filter, null);
+ GlobalSearchScope.allScope(project), myFilter, null);
classChooser.showDialog();
- final PsiClass selectedClass = classChooser.getSelectedClass();
+ final PsiClass selectedClass = classChooser.getSelected();
if (selectedClass == null) {
return;
}
}
}
- private static class SubclassFilter implements TreeClassChooser.ClassFilter {
+ private static class SubclassFilter implements ClassFilter {
private final String[] ancestorClasses;
+++ /dev/null
-<html>
-<body><table> <tr> <td valign="top" height="150">
-<font face="verdana" size="-1">
-This inspection reports any uses of volatile fields in arithmetic operations.
-It's a common misconception that such operations are effectively atomic, but the
-Java Memory Model only specifies that loads and stores on volatile variables are
-atomic. This can lead to unexpected results, including lost updates, when using
-volatile fields in arithmetic operations.
-</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
-</html>
\ No newline at end of file
--- /dev/null
+<html>
+<body><table> <tr> <td valign="top" height="150">
+<font face="verdana" size="-1">
+This inspection reports any non-atomic operations on volatile fields. Non-atomic
+operations on volatile fields are operations where the volatile field is read and
+the value is used to update the volatile field. It is possible for the value of the
+field to change between the read and write, making the operation possibly invalid.
+In such cases it is better to surround the operation with a synchronized block or
+make use of one of the <b><font color="#000080">Atomic*</font></b> or
+ <b><font color="#000080">Atomic*FieldUpdater</font></b> classes
+from the <b><font color="#000080">java.util.concurrent.atomic</font></b> package.
+</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">New in 10, Powered by InspectionGadgets</font> </td> </tr> </table> </body>
+</html>
\ No newline at end of file
package org.intellij.plugins.intelliLang;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.editor.Document;
final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
final PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(myField.getText(), scope);
final TreeClassChooser chooser =
- factory.createNoInnerClassesScopeChooser("Select Annotation Class", scope, new TreeClassChooser.ClassFilter() {
+ factory.createNoInnerClassesScopeChooser("Select Annotation Class", scope, new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return aClass.isAnnotationType();
}
}, aClass);
chooser.showDialog();
- final PsiClass psiClass = chooser.getSelectedClass();
+ final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
myField.setText(psiClass.getQualifiedName());
}
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.*;
-import java.util.List;
public class MethodParameterPanel extends AbstractInjectionPanel<MethodParameterInjection> {
final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
final TreeClassChooser chooser = factory.createAllProjectScopeChooser("Select Class");
chooser.showDialog();
- final PsiClass psiClass = chooser.getSelectedClass();
+ final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
setPsiClass(psiClass.getQualifiedName());
updateParamTree();
public XmlLanguageInjector(Configuration configuration) {
myConfiguration = configuration;
- mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.JAVA_SUPPORT_ID);
+ mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.XML_SUPPORT_ID);
}
@NotNull
android.facet.settings.apk.path.label=APK path:
android.run.confguration.deploy.and.install.check.box=Deplo&y application
android.manifest.debuggable.attribute.not.true.warning=The manifest 'debuggable' attribute isn't set to 'true'.\nYou have to set it to true in order to debug on a device.\nWould you like to do it?
-android.logcat.no.android.facets.error=There is no Android facets in the project
\ No newline at end of file
+android.logcat.no.android.facets.error=There is no Android facets in the project
+android.facet.compiler.settings.manifest.title=Manifest
+android.facet.settings.compiler.manifest.from.structure=Use AndroidManifest.xml file specified at "Structure" section
+android.facet.settings.compiler.manifest.use.custom=Use custom manifest file:
\ No newline at end of file
if (target != null) {
AndroidCompileUtil.createSourceRootIfNotExist(sourceRootPath, module);
String assetsDirPath = assetsDir != null ? assetsDir.getPath() : null;
- VirtualFile manifestFile = AndroidRootUtil.getManifestFile(module);
- assert manifestFile != null;
- String manifestPath = manifestFile.getPath();
- items.add(new AptGenerationItem(module, manifestPath, resPaths, assetsDirPath, sourceRootPath, target,
- packageName, false));
-
- for (String libPackage : AndroidUtils.getDepLibsPackages(module)) {
+ VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
+ if (manifestFile != null) {
+ String manifestPath = manifestFile.getPath();
items.add(new AptGenerationItem(module, manifestPath, resPaths, assetsDirPath, sourceRootPath, target,
- libPackage, true));
+ packageName, false));
+
+ for (String libPackage : AndroidUtils.getDepLibsPackages(module)) {
+ items.add(new AptGenerationItem(module, manifestPath, resPaths, assetsDirPath, sourceRootPath, target,
+ libPackage, true));
+ }
}
}
}
for (Module module : affectedModules) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && !facet.getConfiguration().LIBRARY_PROJECT) {
- VirtualFile manifestFile = AndroidRootUtil.getManifestFile(module);
+ VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module);
if (manifestFile != null) {
AndroidFacetConfiguration configuration = facet.getConfiguration();
for (Module module : affectedModules) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && !facet.getConfiguration().LIBRARY_PROJECT) {
- VirtualFile manifestFile = AndroidRootUtil.getManifestFile(module);
+ VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
VirtualFile assetsDir = AndroidRootUtil.getAssetsDir(module);
if (manifestFile != null) {
AndroidFacetConfiguration configuration = facet.getConfiguration();
IAndroidTarget target = platform != null ? platform.getTarget() : null;
myAndroidTargetName = target != null ? target.getFullName() : "";
- VirtualFile manifestFile = AndroidRootUtil.getManifestFile(module);
+ VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
if (manifestFile != null) {
myResourceTimestamps.put(manifestFile.getPath(), manifestFile.getTimeStamp());
}
collectFiles(resourcesDir);
}
for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, true)) {
- VirtualFile depManifest = AndroidRootUtil.getManifestFile(depFacet.getModule());
+ VirtualFile depManifest = AndroidRootUtil.getManifestFileForCompiler(depFacet);
if (depManifest != null) {
myResourceTimestamps.put(depManifest.getPath(), depManifest.getTimeStamp());
}
public boolean USE_CUSTOM_APK_RESOURCE_FOLDER = false;
public String CUSTOM_APK_RESOURCE_FOLDER = "";
+ public boolean USE_CUSTOM_COMPILER_MANIFEST = false;
+ public String CUSTOM_COMPILER_MANIFEST = "";
+
public String APK_PATH = "";
public boolean ADD_ANDROID_LIBRARY = true;
<grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <xy x="20" y="20" width="460" height="545"/>
+ <xy x="20" y="20" width="512" height="625"/>
</constraints>
<properties/>
<border type="none"/>
</vspacer>
</children>
</grid>
- <grid id="84519" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <grid id="84519" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<tabbedpane title="Compiler"/>
<grid id="1f282" binding="myAaptCompilerPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="4" bottom="0" right="0"/>
<constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="android.apt.settings.title"/>
<grid id="4c810" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="4" bottom="0" right="0"/>
<constraints>
- <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="android.aidl.settings.title"/>
<grid id="3e085" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="4" bottom="0" right="0"/>
<constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="android.apk.settings.title"/>
</grid>
<vspacer id="e716a">
<constraints>
- <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+ <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="63343" class="javax.swing.JCheckBox" binding="myCopyResourcesFromArtifacts">
<text resource-bundle="messages/AndroidBundle" key="copy.resources.from.artifacts.setting"/>
</properties>
</component>
+ <grid id="50185" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ <border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="android.facet.compiler.settings.manifest.title"/>
+ <children>
+ <component id="f22e9" class="javax.swing.JRadioButton" binding="myUseCompilerManifestFromStructureRadio">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text resource-bundle="messages/AndroidBundle" key="android.facet.settings.compiler.manifest.from.structure"/>
+ </properties>
+ </component>
+ <component id="39195" class="javax.swing.JRadioButton" binding="myUseCustomCompilerManifestRadio">
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <selected value="false"/>
+ <text resource-bundle="messages/AndroidBundle" key="android.facet.settings.compiler.manifest.use.custom"/>
+ </properties>
+ </component>
+ <component id="ec790" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myCustomCompilerManifestPathField">
+ <constraints>
+ <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ </component>
+ </children>
+ </grid>
</children>
</grid>
</children>
<member id="d83b5"/>
<member id="df739"/>
</group>
+ <group name="buttonGroup2">
+ <member id="f22e9"/>
+ <member id="39195"/>
+ </group>
</buttonGroups>
</form>
private JCheckBox myGenerateUnsignedApk;
private ComboboxWithBrowseButton myApkPathCombo;
private JLabel myApkPathLabel;
+ private JRadioButton myUseCompilerManifestFromStructureRadio;
+ private JRadioButton myUseCustomCompilerManifestRadio;
+ private TextFieldWithBrowseButton myCustomCompilerManifestPathField;
public AndroidFacetEditorTab(FacetEditorContext context, AndroidFacetConfiguration androidFacetConfiguration) {
final Project project = context.getProject();
myCustomAptSourceDirField.getButton().addActionListener(new MyFolderFieldListener(myCustomAptSourceDirField,
AndroidAptCompiler.getCustomResourceDirForApt(facet),
false));
+ myCustomCompilerManifestPathField.getButton().addActionListener(new MyFolderFieldListener(myCustomCompilerManifestPathField,
+ AndroidRootUtil.getManifestFileForCompiler(facet),
+ true));
myPlatformChooser.addListener(new AndroidPlatformChooserListener() {
@Override
myUseCustomSourceDirectoryRadio.addActionListener(listener);
myUseAptResDirectoryFromPathRadio.addActionListener(listener);
+ listener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ myCustomCompilerManifestPathField.setEnabled(myUseCustomCompilerManifestRadio.isSelected());
+ }
+ };
+ myUseCustomCompilerManifestRadio.addActionListener(listener);
+ myUseCompilerManifestFromStructureRadio.addActionListener(listener);
+
myIsLibraryProjectCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (myUseCustomSourceDirectoryRadio.isSelected() != myConfiguration.USE_CUSTOM_APK_RESOURCE_FOLDER) {
return true;
}
-
if (checkRelativePath(myConfiguration.CUSTOM_APK_RESOURCE_FOLDER, myCustomAptSourceDirField.getText())) {
return true;
}
+
+ if (myUseCustomCompilerManifestRadio.isSelected() != myConfiguration.USE_CUSTOM_COMPILER_MANIFEST) {
+ return true;
+ }
+ if (checkRelativePath(myConfiguration.CUSTOM_COMPILER_MANIFEST, myCustomCompilerManifestPathField.getText())) {
+ return true;
+ }
+
if (myCopyResourcesFromArtifacts.isSelected() != myConfiguration.COPY_RESOURCES_FROM_ARTIFACTS) {
return true;
}
}
myConfiguration.USE_CUSTOM_APK_RESOURCE_FOLDER = useCustomAptSrc;
+ boolean useCustomCompilerManifest = myUseCustomCompilerManifestRadio.isSelected();
+ if (myConfiguration.USE_CUSTOM_COMPILER_MANIFEST != useCustomCompilerManifest) {
+ runApt = true;
+ }
+ myConfiguration.USE_CUSTOM_COMPILER_MANIFEST = useCustomCompilerManifest;
+
if (myConfiguration.REGENERATE_R_JAVA != myGenerateRJavaWhenChanged.isSelected()) {
runApt = true;
}
myConfiguration.CUSTOM_APK_RESOURCE_FOLDER = relPath != null ? '/' + relPath : "";
}
+ String absCompilerManifestPath = myCustomCompilerManifestPathField.getText().trim();
+ if (useCustomCompilerManifest) {
+ if (absCompilerManifestPath.length() == 0) {
+ throw new ConfigurationException("AndroidManifest.xml path not specified in \"Compiler\" section");
+ }
+ String newCustomCompilerManifestPath = '/' + getAndCheckRelativePath(absCompilerManifestPath, false);
+ if (!SdkConstants.FN_ANDROID_MANIFEST_XML.equals(AndroidUtils.getSimpleNameByRelativePath(newCustomCompilerManifestPath))) {
+ throw new ConfigurationException("Manifest file must have name AndroidManifest.xml");
+ }
+ if (!newCustomCompilerManifestPath.equals(myConfiguration.CUSTOM_COMPILER_MANIFEST)) {
+ runApt = true;
+ }
+ myConfiguration.CUSTOM_COMPILER_MANIFEST = newCustomCompilerManifestPath;
+ }
+ else {
+ String relPath = toRelativePath(absCompilerManifestPath);
+ myConfiguration.CUSTOM_COMPILER_MANIFEST = relPath != null ? '/' + relPath : "";
+ }
+
final AndroidPlatform platform = myPlatformChooser.getSelectedPlatform();
myConfiguration.setAndroidPlatform(platform);
final AndroidFacet facet = myConfiguration.getFacet();
myCustomAptSourceDirField.setText(aptSourceAbsPath != null ? aptSourceAbsPath : "");
myCustomAptSourceDirField.setEnabled(configuration.USE_CUSTOM_APK_RESOURCE_FOLDER);
+ myUseCustomCompilerManifestRadio.setSelected(configuration.USE_CUSTOM_COMPILER_MANIFEST);
+ myUseCompilerManifestFromStructureRadio.setSelected(!configuration.USE_CUSTOM_COMPILER_MANIFEST);
+
+ String compilerManifestPath = configuration.CUSTOM_COMPILER_MANIFEST;
+ String compilerManifestAbsPath = compilerManifestPath.length() > 0 ? toAbsolutePath(compilerManifestPath) : "";
+ myCustomCompilerManifestPathField.setText(compilerManifestAbsPath != null ? compilerManifestAbsPath : "");
+ myCustomCompilerManifestPathField.setEnabled(configuration.USE_CUSTOM_COMPILER_MANIFEST);
+
String apkPath = configuration.APK_PATH;
String apkAbsPath = apkPath.length() > 0 ? toAbsolutePath(apkPath) : "";
myApkPathCombo.getComboBox().getEditor().setItem(apkAbsPath != null ? apkAbsPath : "");
public static VirtualFile getManifestFile(@NotNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
return facet == null ? null : getFileByRelativeModulePath(module, facet.getConfiguration().MANIFEST_FILE_RELATIVE_PATH, true);
+ }
- /*VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
- for (VirtualFile contentRoot : files) {
- VirtualFile manifest = contentRoot.findChild(SdkConstants.FN_ANDROID_MANIFEST_XML);
- if (manifest != null) return manifest;
- }
- return null;*/
+ @Nullable
+ public static VirtualFile getCustomManifestFileForCompiler(@NotNull AndroidFacet facet) {
+ return getFileByRelativeModulePath(facet.getModule(), facet.getConfiguration().CUSTOM_COMPILER_MANIFEST, false);
+ }
+
+ @Nullable
+ public static VirtualFile getManifestFileForCompiler(AndroidFacet facet) {
+ return facet.getConfiguration().USE_CUSTOM_COMPILER_MANIFEST
+ ? getCustomManifestFileForCompiler(facet)
+ : getManifestFile(facet.getModule());
}
@Nullable
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.configuration.BrowseModuleValueActionListener;
import com.intellij.execution.ui.ConfigurationModuleSelector;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.module.Module;
public class AndroidClassBrowser extends BrowseModuleValueActionListener {
private final ConfigurationModuleSelector myModuleSelector;
private final String myBaseClassName;
- private final TreeClassChooser.ClassFilter myAdditionalFilter;
+ private final ClassFilter myAdditionalFilter;
private final String myDialogTitle;
private final boolean myIncludeLibraryClasses;
String baseClassName,
String dialogTitle,
boolean includeLibraryClasses,
- @Nullable TreeClassChooser.ClassFilter additionalFilter) {
+ @Nullable ClassFilter additionalFilter) {
super(project);
myModuleSelector = moduleSelector;
myBaseClassName = baseClassName;
myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
PsiClass initialSelection = facade.findClass(getText(), scope);
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project)
- .createInheritanceClassChooser(myDialogTitle, scope, baseClass, initialSelection, new TreeClassChooser.ClassFilter() {
+ .createInheritanceClassChooser(myDialogTitle, scope, baseClass, initialSelection, new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
if (aClass.getManager().areElementsEquivalent(aClass, baseClass)) {
return false;
}
});
chooser.showDialog();
- PsiClass selClass = chooser.getSelectedClass();
+ PsiClass selClass = chooser.getSelected();
return selClass != null ? selClass.getQualifiedName() : null;
}
}
if (!activateDdmsIfNeccessary(facet)) {
return null;
}
- if (!CHOOSE_DEVICE_MANUALLY) {
- checkDebuggableOption(facet);
+ if (!CHOOSE_DEVICE_MANUALLY && PREFERRED_AVD.length() == 0) {
+ if (!checkDebuggableOption(facet)) {
+ return null;
+ }
}
}
IDevice[] devices = chooseDevicesManually(facet);
if (devices.length > 0) {
if (debug && containsRealDevice(devices)) {
- checkDebuggableOption(facet);
+ if (!checkDebuggableOption(facet)) {
+ return null;
+ }
}
deviceSerialNumbers = new String[devices.length];
for (int i = 0; i < devices.length; i++) {
return null;
}
- private static void checkDebuggableOption(@NotNull AndroidFacet facet) {
+ private static boolean checkDebuggableOption(@NotNull AndroidFacet facet) {
Manifest manifest = facet.getManifest();
// validated in checkConfiguration()
assert manifest != null;
BooleanValueConverter booleanValueConverter = BooleanValueConverter.getInstance(true);
if (debuggable == null || !booleanValueConverter.isTrue(debuggable)) {
Project project = facet.getModule().getProject();
- int result = Messages.showYesNoDialog(project, AndroidBundle.message("android.manifest.debuggable.attribute.not.true.warning"),
+ int result = Messages.showYesNoCancelDialog(project, AndroidBundle.message("android.manifest.debuggable.attribute.not.true.warning"),
CommonBundle.getWarningTitle(),
Messages.getWarningIcon());
if (result == 0) {
}
});
}
+ return result != 2;
}
}
+ return true;
}
private static boolean activateDdmsIfNeccessary(@NotNull AndroidFacet facet) {
private volatile ProcessHandler myProcessHandler;
private final Object myLock = new Object();
- private boolean myDeploy;
+ private boolean myDeploy = true;
public void setDebugMode(boolean debugMode) {
myDebugMode = debugMode;
if (!isAndroidSdk15OrHigher()) {
return true;
}
- String avdName = device.getAvdName();
+ String avdName = device.isEmulator() ? device.getAvdName() : null;
if (myAvdName != null) {
return myAvdName.equals(avdName);
}
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.ui.ConfigurationModuleSelector;
+import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.module.Module;
private final ConfigurationModuleSelector myModuleSelector;
- private class ActivityClassFilter implements TreeClassChooser.ClassFilter {
+ private class ActivityClassFilter implements ClassFilter {
public boolean isAccepted(PsiClass c) {
Module module = myModuleSelector.getModule();
if (module != null) {
.createInheritanceClassChooser("Select activity class", module.getModuleWithDependenciesScope(), activityBaseClass,
initialSelection, new ActivityClassFilter());
chooser.showDialog();
- PsiClass selClass = chooser.getSelectedClass();
+ PsiClass selClass = chooser.getSelected();
if (selClass != null) {
myActivityField.setText(selClass.getQualifiedName());
}