Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Kirill.Safonov
2010-04-05 19:14:46 +04:00
43 changed files with 758 additions and 380 deletions
@@ -70,6 +70,7 @@ import java.util.*;
*/
public class IncrementalArtifactsCompiler implements PackagingCompiler {
private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.compiler.IncrementalArtifactsCompiler");
private static final Key<Set<String>> WRITTEN_PATHS_KEY = Key.create("artifacts_written_paths");
private static final Key<List<String>> FILES_TO_DELETE_KEY = Key.create("artifacts_files_to_delete");
private static final Key<Set<Artifact>> AFFECTED_ARTIFACTS = Key.create("affected_artifacts");
private static final Key<ArtifactsProcessingItemsBuilderContext> BUILDER_CONTEXT_KEY = Key.create("artifacts_builder_context");
@@ -212,6 +213,7 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
}.execute();
removeInvalidItems(processedItems);
updateOutputCache(context.getProject(), processedItems);
context.putUserData(WRITTEN_PATHS_KEY, writtenPaths);
return processedItems.toArray(new ProcessingItem[processedItems.size()]);
}
@@ -325,6 +327,11 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
return compileContext.getUserData(AFFECTED_ARTIFACTS);
}
@Nullable
public static Set<String> getWrittenPaths(@NotNull CompileContext context) {
return context.getUserData(WRITTEN_PATHS_KEY);
}
@NotNull
public String getDescription() {
return "Artifacts Packaging Compiler";
@@ -8,6 +8,7 @@ import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -32,6 +33,10 @@ public class ModuleProjectStructureElement extends ProjectStructureElement {
public void check(ProjectStructureProblemsHolder problemsHolder) {
final ModifiableModuleModel moduleModel = myContext.getModulesConfigurator().getModuleModel();
final Module[] all = moduleModel.getModules();
if (!ArrayUtil.contains(myModule, all)) {
return;//module has been deleted
}
for (Module each : all) {
if (each != myModule && myContext.getRealName(each).equals(myContext.getRealName(myModule))) {
problemsHolder.registerError(ProjectBundle.message("project.roots.module.duplicate.name.message"));
@@ -39,18 +39,18 @@ public class DFAEngine<E> {
}
public List<DFAMap<E>> performDFA() {
final ArrayList<DFAMap<E>> info = new ArrayList<DFAMap<E>>(myFlow.length);
public List<E> performDFA() {
final ArrayList<E> info = new ArrayList<E>(myFlow.length);
return performDFA(info);
}
public List<DFAMap<E>> performDFA(final List<DFAMap<E>> info) {
public List<E> performDFA(final List<E> info) {
if (LOG.isDebugEnabled()){
LOG.debug("Perfoming DFA\n" + "Instance: " + myDfa + " Semilattice: " + mySemilattice);
}
// initializing dfa
final DFAMap<E> initial = myDfa.initial();
final E initial = myDfa.initial();
for (int i = 0; i < myFlow.length; i++) {
info.add(i, initial);
}
@@ -104,12 +104,12 @@ public class DFAEngine<E> {
}
final int currentNumber = currentInstruction.num();
final DFAMap<E> oldE = info.get(currentNumber);
final DFAMap<E> joinedE = join(currentInstruction, info);
final DFAMap<E> newE = myDfa.fun(joinedE, currentInstruction);
final E oldE = info.get(currentNumber);
final E joinedE = join(currentInstruction, info);
final E newE = myDfa.fun(joinedE, currentInstruction);
if (!mySemilattice.eq(newE, oldE)) {
if (LOG.isDebugEnabled()){
LOG.debug("Number: " + currentNumber + " old: " + oldE.keySet() + " new: " + newE.keySet());
LOG.debug("Number: " + currentNumber + " old: " + oldE.toString() + " new: " + newE.toString());
}
info.set(currentNumber, newE);
for (Instruction next : getNext(currentInstruction)) {
@@ -148,9 +148,9 @@ public class DFAEngine<E> {
return allPred * 2;
}
private DFAMap<E> join(final Instruction instruction, final List<DFAMap<E>> info) {
private E join(final Instruction instruction, final List<E> info) {
final Iterable<? extends Instruction> prev = myDfa.isForward() ? instruction.allPred() : instruction.allSucc();
final ArrayList<DFAMap<E>> prevInfos = new ArrayList<DFAMap<E>>();
final ArrayList<E> prevInfos = new ArrayList<E>();
for (Instruction i : prev) {
prevInfos.add(info.get(i.num()));
}
@@ -21,10 +21,10 @@ public interface DfaInstance<E> {
// Please ensure that E has correctly implemented equals method
// Invariant: fun must create new instance of DFAMap if modifies it
DFAMap<E> fun(DFAMap<E> e, Instruction instruction);
E fun(E e, Instruction instruction);
@NotNull
DFAMap<E> initial();
E initial();
boolean isForward();
}
@@ -17,9 +17,7 @@ package com.intellij.codeInsight.dataflow;
import java.util.ArrayList;
public interface Semilattice<E> {
// Invariant: join can return unmodified ins(0) or empty DFAMap
// DfaInstance must create new one before modifying
DFAMap<E> join(ArrayList<DFAMap<E>> ins);
E join(ArrayList<E> ins);
boolean eq(DFAMap<E> e1, DFAMap<E> e2);
boolean eq(E e1, E e2);
}
@@ -1,5 +1,6 @@
package com.intellij.codeInsight.dataflow;
package com.intellij.codeInsight.dataflow.map;
import com.intellij.codeInsight.dataflow.SetUtil;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -0,0 +1,25 @@
/*
* 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.codeInsight.dataflow.map;
import com.intellij.codeInsight.controlflow.Instruction;
import com.intellij.codeInsight.dataflow.DFAEngine;
public class DFAMapEngine<E> extends DFAEngine<DFAMap<E>>{
public DFAMapEngine(final Instruction[] flow, final DfaMapInstance<E> dfa, final MapSemilattice<E> dfaMapSemilattice) {
super(flow, dfa, dfaMapSemilattice);
}
}
@@ -0,0 +1,21 @@
/*
* 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.codeInsight.dataflow.map;
import com.intellij.codeInsight.dataflow.DfaInstance;
public interface DfaMapInstance<E> extends DfaInstance<DFAMap<E>> {
}
@@ -0,0 +1,22 @@
/*
* Copyright 2000-2007 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.codeInsight.dataflow.map;
import com.intellij.codeInsight.dataflow.Semilattice;
public interface MapSemilattice<E> extends Semilattice<DFAMap<E>>{
// Invariant: join can return unmodified ins(0) or empty DFAMap
// DfaInstance must create new one before modifying
}
@@ -36,6 +36,7 @@ import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.awt.RelativeRectangle;
import com.intellij.util.ui.UIUtil;
@@ -717,37 +718,41 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
public void updateActionsImmediately() {
ApplicationManager.getApplication().assertIsDispatchThread();
myNewVisibleActions.clear();
final DataContext dataContext = getDataContext();
IdeFocusManager.getInstance(null).doWhenFocusSettlesDown(new Runnable() {
public void run() {
myNewVisibleActions.clear();
final DataContext dataContext = getDataContext();
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager);
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager);
if (!myNewVisibleActions.equals(myVisibleActions)) {
// should rebuild UI
if (!myNewVisibleActions.equals(myVisibleActions)) {
// should rebuild UI
final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
final ArrayList<AnAction> temp = myVisibleActions;
myVisibleActions = myNewVisibleActions;
myNewVisibleActions = temp;
final ArrayList<AnAction> temp = myVisibleActions;
myVisibleActions = myNewVisibleActions;
myNewVisibleActions = temp;
removeAll();
mySecondaryActions.removeAll();
mySecondaryActionsButton = null;
fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
removeAll();
mySecondaryActions.removeAll();
mySecondaryActionsButton = null;
fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
if (changeBarVisibility) {
revalidate();
}
else {
final Container parent = getParent();
if (parent != null) {
parent.invalidate();
parent.validate();
if (changeBarVisibility) {
revalidate();
}
else {
final Container parent = getParent();
if (parent != null) {
parent.invalidate();
parent.validate();
}
}
repaint();
}
}
repaint();
}
});
}
public void setTargetComponent(final JComponent component) {
@@ -40,16 +40,7 @@ class UndoRedoStacksHolder {
myUndo = isUndo;
}
public LinkedList<UndoableGroup> getStack(Document d) {
return getStack(createReferenceOrGetOriginal(d));
}
private static DocumentReference createReferenceOrGetOriginal(Document d) {
Document original = UndoManagerImpl.getOriginal(d);
return DocumentReferenceManager.getInstance().create(original);
}
public LinkedList<UndoableGroup> getStack(@NotNull DocumentReference r) {
private LinkedList<UndoableGroup> getStack(@NotNull DocumentReference r) {
return r.getFile() != null ? doGetStackForFile(r) : doGetStackForDocument(r);
}
@@ -161,15 +152,15 @@ class UndoRedoStacksHolder {
public void clearStacks(boolean clearGlobal, Set<DocumentReference> affectedDocuments) {
if (clearGlobal) myGlobalStack.clear();
for (DocumentReference each : affectedDocuments) {
List<UndoableGroup> stack = getStack(each);
for (DocumentReference ref : affectedDocuments) {
List<UndoableGroup> stack = getStack(ref);
stack.clear();
if (each.getFile() != null) {
myDocumentStacks.remove(each);
if (ref.getFile() != null) {
myDocumentStacks.remove(ref);
}
else {
Document d = each.getDocument();
Document d = ref.getDocument();
d.putUserData(STACK_IN_DOCUMENT_KEY, null);
myDocumentsWithStacks.remove(d);
}
@@ -23,6 +23,7 @@
package com.intellij.openapi.vfs.encoding;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
@@ -71,23 +72,47 @@ public class EncodingManagerImpl extends EncodingManager implements PersistentSt
private final Queue<Document> myChangedDocuments = new ConcurrentLinkedQueue<Document>();
private final Runnable myEncodingUpdateRunnable = new Runnable() {
public void run() {
Document document = myChangedDocuments.poll();
if (document == null) return;
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
if (virtualFile == null) return;
Project project = guessProject(virtualFile);
if (project != null && project.isDisposed()) return;
Charset charset = LoadTextUtil.charsetFromContentOrNull(project, virtualFile, document.getText());
document.putUserData(CACHED_CHARSET_FROM_CONTENT, charset);
for (int i=0; i<50;i++) {
if (!pollAndHandleDocument()) return;
}
// requeue myself to handle the tail of the queue in next request
addCacheEncodingAlarm();
}
};
private boolean pollAndHandleDocument() {
final Document document = myChangedDocuments.poll();
if (document == null) return false;
ApplicationManager.getApplication().runReadAction(new Runnable(){
public void run() {
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
if (virtualFile == null) return;
Project project = guessProject(virtualFile);
if (project != null && project.isDisposed()) return;
Charset charset = LoadTextUtil.charsetFromContentOrNull(project, virtualFile, document.getText());
document.putUserData(CACHED_CHARSET_FROM_CONTENT, charset);
}
});
return true;
}
public void dispose() {
updateEncodingFromContent.cancelAllRequests();
drainDocumentQueue();
}
public void drainDocumentQueue() {
while (pollAndHandleDocument()) {
// loop until empty
}
}
public void updateEncodingFromContent(Document document) {
myChangedDocuments.offer(document);
addCacheEncodingAlarm();
}
private void addCacheEncodingAlarm() {
updateEncodingFromContent.cancelAllRequests();
updateEncodingFromContent.addRequest(myEncodingUpdateRunnable, 400);
}
@@ -61,6 +61,8 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.openapi.vfs.encoding.EncodingManagerImpl;
import com.intellij.openapi.vfs.newvfs.ManagingFS;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.profile.codeInspection.InspectionProfileManager;
@@ -411,10 +413,14 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
e.printStackTrace();
}
}
EncodingManager encodingManager = EncodingManager.getInstance();
if (encodingManager instanceof EncodingManagerImpl) ((EncodingManagerImpl)encodingManager).drainDocumentQueue();
FileDocumentManager manager = FileDocumentManager.getInstance();
if (manager instanceof FileDocumentManagerImpl) {
((FileDocumentManagerImpl)manager).dropAllUnsavedDocuments();
}
ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flash posponed formatting if any.
manager.saveAllDocuments();
}
@@ -1761,5 +1761,7 @@ remove.try.finally.block.quickfix=Remove try-finally block
remove.finally.block.quickfix=Remove finally block
remove.leading.zero.to.make.decimal.quickfix=Remove leading zero to make decimal
convert.octal.literal.to.decimal.literal.quickfix=Convert octal literal to decimal literal
ignore.single.field.static.imports=Ignore single &field static imports
ignore.single.method.static.imports=Ignore single &method static imports
ignore.single.field.static.imports.option=Ignore single &field static imports
ignore.single.method.static.imports.option=Ignore single &method static imports
ignore.methods.with.boolean.return.type.option=Ignore methods with &Boolean return type
ignore.boolean.methods.in.an.interface.option=Ignore boolean methods in an @&interface
@@ -60,10 +60,10 @@ public class StaticImportInspection extends BaseInspection {
final MultipleCheckboxOptionsPanel panel =
new MultipleCheckboxOptionsPanel(this);
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.single.field.static.imports"),
"ignore.single.field.static.imports.option"),
"ignoreSingleFieldImports");
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.single.method.static.imports"),
"ignore.single.method.static.imports.option"),
"ignoreSingeMethodImports");
return panel;
}
@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.naming.BooleanMethodNameMustStartWithQuestionInspection.Form">
<grid id="88823" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="92" y="33" width="295" height="162"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="14807">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2273d" class="com.siyeh.ig.ui.IGTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="52926" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.add"/>
</properties>
</component>
<component id="f6174" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.remove"/>
</properties>
</component>
<vspacer id="6a13b">
<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>
</children>
</grid>
</form>
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.naming;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import com.siyeh.InspectionGadgetsBundle;
@@ -25,21 +26,29 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.RenameFix;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.AddAction;
import com.siyeh.ig.ui.IGTable;
import com.siyeh.ig.ui.ListWrappingTableModel;
import com.siyeh.ig.ui.RemoveAction;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
public class BooleanMethodNameMustStartWithQuestionInspection
extends BaseInspection{
@SuppressWarnings({"PublicField"})
public boolean ignoreBooleanMethods = false;
@SuppressWarnings({"PublicField"})
public boolean ignoreInAnnotationInterface = true;
/** @noinspection PublicField*/
@NonNls public String questionString =
"is,can,has,should,could,will,shall,check,contains,equals,add," +
@@ -51,41 +60,97 @@ public class BooleanMethodNameMustStartWithQuestionInspection
parseString(questionString, questionList);
}
@Override
@NotNull
public String getDisplayName(){
return InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos){
return InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.problem.descriptor");
}
@Override
public void readSettings(Element element) throws InvalidDataException{
super.readSettings(element);
parseString(questionString, questionList);
}
@Override
public void writeSettings(Element element) throws WriteExternalException{
questionString = formatString(questionList);
super.writeSettings(element);
}
@Override
public JComponent createOptionsPanel(){
final Form form = new Form();
return form.getContentPanel();
final JPanel panel = new JPanel(new GridBagLayout());
final IGTable table =
new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
final JScrollPane scrollPane = new JScrollPane(table);
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
final JButton addButton = new JButton(new AddAction(table));
constraints.gridx = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(addButton, constraints);
final JButton removeButton = new JButton(new RemoveAction(table));
constraints.gridy = 1;
panel.add(removeButton, constraints);
final BlankFiller filler = new BlankFiller();
constraints.gridy = 2;
constraints.weighty = 1.0;
panel.add(filler, constraints);
final CheckBox checkBox1 =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.methods.with.boolean.return.type.option"),
this, "ignoreBooleanMethods");
constraints.gridy = 3;
constraints.gridx = 0;
constraints.gridwidth = 2;
constraints.weighty = 0.0;
panel.add(checkBox1, constraints);
final CheckBox checkBox2 =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.boolean.methods.in.an.interface.option"),
this, "ignoreInAnnotationInterface");
constraints.gridy = 4;
panel.add(checkBox2, constraints);
return panel;
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos){
return new RenameFix();
}
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
return true;
}
@Override
public BaseInspectionVisitor buildVisitor(){
return new BooleanMethodNameMustStartWithQuestionVisitor();
}
@@ -95,8 +160,20 @@ public class BooleanMethodNameMustStartWithQuestionInspection
@Override public void visitMethod(@NotNull PsiMethod method){
final PsiType returnType = method.getReturnType();
if(returnType == null || !returnType.equals(PsiType.BOOLEAN)){
if(returnType == null){
return;
} else if(!returnType.equals(PsiType.BOOLEAN)){
if (ignoreBooleanMethods ||
!returnType.equalsToText("java.lang.Boolean")) {
return;
}
}
if (ignoreInAnnotationInterface) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null &&
containingClass.isAnnotationType()) {
return;
}
}
final String name = method.getName();
for(String question : questionList){
@@ -110,28 +187,4 @@ public class BooleanMethodNameMustStartWithQuestionInspection
registerMethodError(method);
}
}
private class Form{
JPanel contentPanel;
JButton addButton;
JButton removeButton;
IGTable table;
Form(){
super();
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents(){
table = new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
}
public JComponent getContentPanel(){
return contentPanel;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* 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.
@@ -25,15 +25,17 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.RenameFix;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.AddAction;
import com.siyeh.ig.ui.IGTable;
import com.siyeh.ig.ui.ListWrappingTableModel;
import com.siyeh.ig.ui.RemoveAction;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
@@ -45,47 +47,99 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
"is,can,has,should,could,will,shall,check,contains,equals," +
"startsWith,endsWith";
@SuppressWarnings({"PublicField"})
public boolean ignoreBooleanMethods = false;
List<String> questionList = new ArrayList(32);
public NonBooleanMethodNameMayNotStartWithQuestionInspection(){
parseString(questionString, questionList);
}
@Override
@NotNull
public String getDisplayName(){
return InspectionGadgetsBundle.message(
"non.boolean.method.name.must.not.start.with.question.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos){
return InspectionGadgetsBundle.message(
"non.boolean.method.name.must.not.start.with.question.problem.descriptor");
}
@Override
public void readSettings(Element element) throws InvalidDataException{
super.readSettings(element);
parseString(questionString, questionList);
}
@Override
public void writeSettings(Element element) throws WriteExternalException{
questionString = formatString(questionList);
super.writeSettings(element);
}
@Override
public JComponent createOptionsPanel(){
final Form form = new Form();
return form.getContentPanel();
final JPanel panel = new JPanel(new GridBagLayout());
final IGTable table =
new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
final JScrollPane scrollPane = new JScrollPane(table);
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
final JButton addButton = new JButton(new AddAction(table));
constraints.gridx = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(addButton, constraints);
final JButton removeButton = new JButton(new RemoveAction(table));
constraints.gridy = 1;
panel.add(removeButton, constraints);
final BlankFiller filler = new BlankFiller();
constraints.gridy = 2;
constraints.weighty = 1.0;
panel.add(filler, constraints);
final CheckBox checkBox =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.methods.with.boolean.return.type.option"),
this, "ignoreBooleanMethods");
constraints.gridy = 3;
constraints.gridx = 0;
constraints.gridwidth = 2;
constraints.weighty = 0.0;
panel.add(checkBox, constraints);
return panel;
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos){
return new RenameFix();
}
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
return true;
}
@Override
public BaseInspectionVisitor buildVisitor(){
return new NonBooleanMethodNameMayNotStartWithQuestionVisitor();
}
@@ -99,6 +153,10 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
if(returnType == null || returnType.equals(PsiType.BOOLEAN)){
return;
}
if(ignoreBooleanMethods && returnType.equalsToText(
"java.lang.Boolean")){
return;
}
final String name = method.getName();
boolean startsWithQuestionWord = false;
for(String question : questionList){
@@ -121,28 +179,4 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
registerMethodError(method);
}
}
private class Form{
JPanel contentPanel;
JButton addButton;
JButton removeButton;
IGTable table;
Form(){
super();
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents(){
table = new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
}
public JComponent getContentPanel(){
return contentPanel;
}
}
}
@@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.naming.NonBooleanMethodNameMayNotStartWithQuestionInspection.Form">
<grid id="c36c6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="94" y="35" width="298" height="158"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="14807">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d8a2f" class="com.siyeh.ig.ui.IGTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="52926" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.add"/>
</properties>
</component>
<component id="f6174" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.remove"/>
</properties>
</component>
<vspacer id="5ac98">
<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>
</children>
</grid>
</form>
@@ -437,11 +437,11 @@ update.options.save.shelve.tooltip=Use IDEA Shelve (the files will be restored w
update.options.save.stash=Using S&tash
update.options.save.stash.tooltip=Use 'git stash' to save changes (the files will be restored when update finishes)
update.options.type.default=Branch &Default
update.options.type.default.tooltip=Use branch default update type for all updated vcs roots
update.options.type.merge=Force &Merge
update.options.type.merge.tooltip=Force merge update strategy
update.options.type.rebase=Force &Rebase
update.options.type.rebase.tooltip=Force rebase update strategy
update.options.type.default.tooltip=Use branch default update strategy for all updated git vcs roots
update.options.type.merge=&Merge
update.options.type.merge.tooltip=Use merge update strategy for all git vcs roots
update.options.type.rebase=&Rebase
update.options.type.rebase.tooltip=Use rebase update strategy for all git vcs roots
update.options.type=Update Type
update.rebase.no.change.cancel=Cancel Update
update.rebase.no.change.retry=Retry Continue
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/rt">
<sourceFolder url="file://$MODULE_DIR$/rt/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Groovy" level="project" />
</component>
</module>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="jetgroovy" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="execution-openapi" />
<orderEntry type="module" module-name="grape-rt" />
</component>
</module>
@@ -0,0 +1 @@
Add the dependency defined by @Grab annotation to the project
@@ -0,0 +1,40 @@
package org.jetbrains.plugins.groovy.grape;
import groovy.lang.GroovyShell;
import org.codehaus.groovy.control.CompilationFailedException;
import java.io.File;
import java.net.URL;
/**
* @author peter
*/
public class GrapeRunner {
public static final String URL_PREFIX = "URL:";
private GrapeRunner() {
}
public static void main(String[] args) {
final File file = new File(args[0]);
if (!file.exists()) {
return;
}
final GroovyShell shell = new GroovyShell();
try {
shell.parse(file);
}
catch (CompilationFailedException ignored) {
//should fail, we're not compiling, we're just resolving Grab dependencies
}
catch (Throwable e) {
e.printStackTrace();
}
for (URL url : shell.getClassLoader().getURLs()) {
System.out.println(URL_PREFIX + url);
}
}
}
@@ -0,0 +1,18 @@
<idea-plugin url="http://www.jetbrains.net/confluence/display/GRVY/Groovy+Home">
<id>org.intellij.groovy.grape</id>
<name>Groovy Grape support</name>
<description>Managing Grape-defined dependencies</description>
<version>0.1</version>
<idea-version since-build="95.28" until-build="96.1"/>
<vendor logo="/org/jetbrains/plugins/groovy/images/groovy_16x16.png" url="http://www.jetbrains.com">JetBrains Inc.</vendor>
<depends>org.intellij.groovy</depends>
<extensions defaultExtensionNs="com.intellij">
<intentionAction>
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
<categoryKey>intention.category.groovy</categoryKey>
<className>org.jetbrains.plugins.groovy.grape.GrabDependencies</className>
</intentionAction>
</extensions>
</idea-plugin>
@@ -0,0 +1,218 @@
package org.jetbrains.plugins.groovy.grape;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.execution.CantRunException;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.process.DefaultJavaProcessHandler;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.PathUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
import org.jetbrains.plugins.groovy.runner.DefaultGroovyScriptRunner;
import org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfiguration;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* @author peter
*/
public class GrabDependencies implements IntentionAction {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.grape.GrabDependencies");
@NotNull
public String getText() {
return "Grab the artifacts";
}
@NotNull
public String getFamilyName() {
return "Grab";
}
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
final GrAnnotation anno = PsiTreeUtil.findElementOfClassAtOffset(file, editor.getCaretModel().getOffset(), GrAnnotation.class, false);
if (anno == null) {
return false;
}
final String qname = anno.getQualifiedName();
if (qname == null || !(qname.startsWith("groovy.lang.Grab") || "groovy.lang.Grapes".equals(qname))) {
return false;
}
final Module module = ModuleUtil.findModuleForPsiElement(file);
if (module == null) {
return false;
}
return file.getOriginalFile().getVirtualFile() != null;
}
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final Module module = ModuleUtil.findModuleForPsiElement(file);
assert module != null;
final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
assert vfile != null;
final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
try {
//debug
//javaParameters.getVMParametersList().add("-Xdebug"); javaParameters.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");
final boolean tests = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(vfile);
DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, tests, "org.jetbrains.plugins.groovy.grape.GrapeRunner");
javaParameters.getProgramParametersList().add("--classpath");
javaParameters.getProgramParametersList().add(PathUtil.getJarPathForClass(GrapeRunner.class));
javaParameters.getProgramParametersList().add(FileUtil.toSystemDependentName(vfile.getPath()));
}
catch (CantRunException e) {
Messages.showErrorDialog(e.getMessage(), "Can't run Groovyc");
return;
}
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
assert sdk != null;
SdkType sdkType = sdk.getSdkType();
assert sdkType instanceof JavaSdkType;
final String exePath = ((JavaSdkType)sdkType).getVMExecutablePath(sdk);
try {
final GrapeProcessHandler handler = new GrapeProcessHandler(JdkUtil.setupJVMCommandLine(exePath, javaParameters, true), module);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab annotations") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
handler.startNotify();
handler.waitFor();
}
});
}
catch (ExecutionException e) {
LOG.error(e);
}
}
public boolean startInWriteAction() {
return false;
}
private static class GrapeProcessHandler extends DefaultJavaProcessHandler {
private final StringBuilder myStdOut = new StringBuilder();
private final StringBuilder myStdErr = new StringBuilder();
private final Module myModule;
public GrapeProcessHandler(GeneralCommandLine commandLine, Module module) throws ExecutionException {
super(commandLine);
myModule = module;
}
@Override
public void notifyTextAvailable(String text, Key outputType) {
text = StringUtil.convertLineSeparators(text);
if (LOG.isDebugEnabled()) {
LOG.debug(outputType + text);
}
if (outputType == ProcessOutputTypes.STDOUT) {
myStdOut.append(text);
}
else if (outputType == ProcessOutputTypes.STDERR) {
myStdErr.append(text);
}
}
private void addGrapeDependencies(List<VirtualFile> jars) {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
final LibraryTable.ModifiableModel tableModel = model.getModuleLibraryTable().getModifiableModel();
for (VirtualFile jar : jars) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jar);
if (jarRoot != null) {
final Library.ModifiableModel libModel = tableModel.createLibrary("Grab:" + jar.getName()).getModifiableModel();
libModel.addRoot(jarRoot, OrderRootType.CLASSES);
libModel.commit();
}
}
tableModel.commit();
model.commit();
}
@Override
protected void notifyProcessTerminated(int exitCode) {
super.notifyProcessTerminated(exitCode);
final List<VirtualFile> jars = new ArrayList<VirtualFile>();
for (String line : myStdOut.toString().split("\n")) {
if (line.startsWith(GrapeRunner.URL_PREFIX)) {
try {
final URL url = new URL(line.substring(GrapeRunner.URL_PREFIX.length()));
final File libFile = new File(url.toURI());
if (libFile.exists() && libFile.getName().endsWith(".jar")) {
final VirtualFile vfile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libFile);
ContainerUtil.addIfNotNull(vfile, jars);
}
}
catch (MalformedURLException e) {
LOG.error(e);
}
catch (URISyntaxException e) {
LOG.error(e);
}
}
}
new WriteAction() {
protected void run(Result result) throws Throwable {
final String title = jars.size() + " dependencies added";
final String descr = myStdOut.toString().replaceAll("\n", "<br>") + "<p>" + myStdErr.toString().replaceAll("\n", "<br>");
Notifications.Bus.notify(new Notification("Grape", title, descr, NotificationType.INFORMATION), NotificationDisplayType.BALLOON, myModule.getProject());
if (!jars.isEmpty()) {
addGrapeDependencies(jars);
}
}
}.execute();
}
}
}
@@ -33,6 +33,7 @@ import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.MultiMap;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
@@ -365,31 +366,28 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
@Override
public void visitListOrMap(GrListOrMap listOrMap) {
final Map<GrNamedArgument, List<GrNamedArgument>> map = DuplicatesUtil.factorDuplicates(listOrMap.getNamedArguments(), new TObjectHashingStrategy<GrNamedArgument>() {
public int computeHashCode(GrNamedArgument arg) {
final GrArgumentLabel label = arg.getLabel();
if (label == null) return 0;
MultiMap<String, GrNamedArgument> map = new MultiMap<String, GrNamedArgument>();
for (GrNamedArgument element : listOrMap.getNamedArguments()) {
final GrArgumentLabel label = element.getLabel();
if (label != null) {
final String name = label.getName();
if (name == null) return 0;
return name.hashCode();
}
public boolean equals(GrNamedArgument arg1, GrNamedArgument arg2) {
final GrArgumentLabel label1 = arg1.getLabel();
final GrArgumentLabel label2 = arg2.getLabel();
if (label1 == null || label2 == null) {
return label1 == null && label2 == null;
if (name != null) {
map.putValue(name, element);
}
final String name1 = label1.getName();
final String name2 = label2.getName();
if (name1 == null || name2 == null) {
return name1 == null && name2 == null;
}
return name1.equals(name2);
}
});
}
processDuplicates(map, myHolder);
for (String key : map.keySet()) {
final Collection<GrNamedArgument> arguments = map.get(key);
if (arguments.size() > 1) {
final List<GrNamedArgument> args = new ArrayList<GrNamedArgument>(arguments);
for (int i = 1; i < args.size(); i++) {
GrNamedArgument namedArgument = args.get(i);
myHolder.createWarningAnnotation(namedArgument.getLabel(), GroovyBundle.message("duplicate.element.in.the.map"));
}
}
}
}
@Override
@@ -734,15 +732,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
}
}
protected static void processDuplicates(Map<GrNamedArgument, List<GrNamedArgument>> map, AnnotationHolder holder) {
for (List<GrNamedArgument> args : map.values()) {
for (int i = 1; i < args.size(); i++) {
GrNamedArgument namedArgument = args.get(i);
holder.createWarningAnnotation(namedArgument, GroovyBundle.message("duplicate.element.in.the.map"));
}
}
}
private static void registerAbstractMethodFix(Annotation annotation, GrMethod method, boolean makeClassAbstract) {
if (method.getBlock() == null) {
annotation.registerFix(new AddMethodBodyFix(method));
@@ -66,6 +66,23 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner {
@Override
public void configureCommandLine(JavaParameters params, @Nullable Module module, boolean tests, VirtualFile script, GroovyScriptRunConfiguration configuration) throws CantRunException {
configureGenericGroovyRunner(params, module, tests, "groovy.ui.GroovyMain");
addClasspathFromRootModel(module, tests, params);
params.getVMParametersList().addParametersString(configuration.vmParams);
params.getProgramParametersList().add(FileUtil.toSystemDependentName(configuration.scriptPath));
params.getProgramParametersList().addParametersString(configuration.scriptParams);
addScriptEncodingSettings(params, script, module);
if (configuration.isDebugEnabled) {
params.getProgramParametersList().add("--debug");
}
}
public static void configureGenericGroovyRunner(JavaParameters params, Module module, boolean tests, String mainClass) throws CantRunException {
assert module != null;
final VirtualFile groovyJar = findGroovyJar(module);
if (groovyJar != null) {
@@ -80,25 +97,13 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner {
final String confPath = getConfPath(groovyHome);
params.getVMParametersList().add("-Dgroovy.starter.conf=" + confPath);
params.getVMParametersList().addParametersString(configuration.vmParams);
params.setMainClass("org.codehaus.groovy.tools.GroovyStarter");
params.getProgramParametersList().add("--conf");
params.getProgramParametersList().add(confPath);
addClasspathFromRootModel(module, tests, params);
params.getProgramParametersList().add("--main");
params.getProgramParametersList().add("groovy.ui.GroovyMain");
params.getProgramParametersList().add(FileUtil.toSystemDependentName(configuration.scriptPath));
params.getProgramParametersList().addParametersString(configuration.scriptParams);
addScriptEncodingSettings(params, script, module);
if (configuration.isDebugEnabled) {
params.getProgramParametersList().add("--debug");
}
params.getProgramParametersList().add(mainClass);
}
private static void addScriptEncodingSettings(final JavaParameters params, final VirtualFile scriptFile, Module module) {
@@ -172,20 +172,8 @@ public class GroovyScriptRunConfiguration extends ModuleBasedConfiguration<RunCo
final JavaCommandLineState state = new JavaCommandLineState(environment) {
protected JavaParameters createJavaParameters() throws ExecutionException {
JavaParameters params = new JavaParameters();
params.setCharset(null);
if (module != null) {
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
params.setJdk(sdk);
}
}
if (params.getJdk() == null) {
params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
}
JavaParameters params = createJavaParametersWithSdk(module);
params.setWorkingDirectory(getAbsoluteWorkDir());
scriptRunner.configureCommandLine(params, module, tests, script, GroovyScriptRunConfiguration.this);
return params;
@@ -197,6 +185,22 @@ public class GroovyScriptRunConfiguration extends ModuleBasedConfiguration<RunCo
}
public static JavaParameters createJavaParametersWithSdk(Module module) {
JavaParameters params = new JavaParameters();
params.setCharset(null);
if (module != null) {
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
params.setJdk(sdk);
}
}
if (params.getJdk() == null) {
params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
}
return params;
}
@Nullable
private VirtualFile getScriptFile() {
if (scriptPath == null) return null;
@@ -224,6 +224,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
public void testSuperConstructorInvocation() throws Exception {doTest();}
public void testDuplicateMapKeys() throws Exception {doTest();}
public void testIndexPropertyAccess() throws Exception {
doTest();
}
@@ -0,0 +1,2 @@
x = [ (person.firstNameKey):person.firstName, (person.lastNameKey):person.lastName ]
x = [2:1, <warning descr="Duplicate element in the map">2</warning>:2]
@@ -107,14 +107,13 @@ public class MavenModuleImporter {
private void configDependencies() {
for (MavenArtifact artifact : myMavenProject.getDependencies()) {
boolean isExportable = artifact.isExportable();
DependencyScope scope = selectScope(artifact.getScope());
MavenProject depProject = myMavenTree.findProject(artifact.getMavenId());
if (depProject != null) {
myRootModelAdapter.addModuleDependency(myMavenProjectToModuleName.get(depProject), isExportable, scope);
myRootModelAdapter.addModuleDependency(myMavenProjectToModuleName.get(depProject), scope);
}
else if (myMavenProject.isSupportedDependency(artifact)) {
myRootModelAdapter.addLibraryDependency(artifact, isExportable, scope, myModifiableModelsProvider, myMavenProject);
myRootModelAdapter.addLibraryDependency(artifact, scope, myModifiableModelsProvider, myMavenProject);
}
}
}
@@ -194,7 +194,7 @@ public class MavenRootModelAdapter {
return new Path(path);
}
public void addModuleDependency(String moduleName, boolean isExportable, DependencyScope scope) {
public void addModuleDependency(String moduleName, DependencyScope scope) {
Module m = findModuleByName(moduleName);
ModuleOrderEntry e;
@@ -205,7 +205,6 @@ public class MavenRootModelAdapter {
e = myRootModel.addInvalidModuleEntry(moduleName);
}
e.setExported(isExportable);
e.setScope(scope);
}
@@ -215,7 +214,6 @@ public class MavenRootModelAdapter {
}
public void addLibraryDependency(MavenArtifact artifact,
boolean isExportable,
DependencyScope scope,
MavenModifiableModelsProvider provider,
MavenProject project) {
@@ -234,7 +232,6 @@ public class MavenRootModelAdapter {
}
LibraryOrderEntry e = myRootModel.addLibraryEntry(library);
e.setExported(isExportable);
e.setScope(scope);
}
@@ -0,0 +1,29 @@
/*
* 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 org.jetbrains.idea.maven.project.actions;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
public class DownloadActionGroup extends DefaultActionGroup {
@Override
public void update(AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabled(MavenActionUtil.getProjectsManager(e.getDataContext()).isMavenizedProject());
}
}
@@ -26,5 +26,10 @@ public abstract class MavenProjectsManagerAction extends MavenAction {
perform(MavenActionUtil.getProjectsManager(e.getDataContext()));
}
@Override
protected boolean isAvailable(AnActionEvent e) {
return super.isAvailable(e) && MavenActionUtil.getProjectsManager(e.getDataContext()).isMavenizedProject();
}
protected abstract void perform(MavenProjectsManager manager);
}
@@ -15,9 +15,15 @@
*/
package org.jetbrains.idea.maven.project.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
public class ReimportAction extends MavenProjectsManagerAction {
@Override
protected boolean isAvailable(AnActionEvent e) {
return true;
}
@Override
protected void perform(MavenProjectsManager manager) {
manager.forceUpdateAllProjectsOrFindAllAvailablePomFiles();
@@ -29,8 +29,6 @@ public class MavenActionGroup extends DefaultActionGroup {
}
protected boolean isAvailable(AnActionEvent e) {
final DataContext context = e.getDataContext();
if (MavenActionUtil.getProject(context) == null) return false;
return !MavenActionUtil.getMavenProjects(context).isEmpty();
return !MavenActionUtil.getMavenProjects(e.getDataContext()).isEmpty();
}
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
@@ -33,7 +34,7 @@ public class MavenActionUtil {
private MavenActionUtil() {
}
@Nullable
@NotNull
public static Project getProject(DataContext context) {
return PlatformDataKeys.PROJECT.getData(context);
}
@@ -27,7 +27,7 @@ public abstract class MavenToggleAction extends ToggleAction implements DumbAwar
}
protected boolean isAvailable(AnActionEvent e) {
return MavenActionUtil.getProject(e.getDataContext()) != null;
return true;
}
public final boolean isSelected(AnActionEvent e) {
@@ -293,7 +293,8 @@
</action>
</group>
<group id="Maven.DownloadAllGroup" popup="true" icon="/images/download.png">
<group id="Maven.DownloadAllGroup" popup="true" class="org.jetbrains.idea.maven.project.actions.DownloadActionGroup"
icon="/images/download.png">
<reference id="Maven.DownloadAllSources"/>
<reference id="Maven.DownloadAllDocs"/>
<reference id="Maven.DownloadAllSourcesAndDocs"/>
@@ -199,7 +199,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
assertModuleDeps(moduleName, LibraryOrderEntry.class, expectedDeps);
}
protected void assertExportedModuleDeps(String moduleName, String... expectedDeps) {
protected void assertExportedDeps(String moduleName, String... expectedDeps) {
final List<String> actual = new ArrayList<String>();
getRootManager(moduleName).processOrder(new RootPolicy<Object>() {
@@ -15,11 +15,14 @@
*/
package org.jetbrains.idea.maven.compiler;
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerManagerImpl;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.impl.ModuleCompileScope;
import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.io.FileUtil;
@@ -824,6 +827,9 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
}
public void testDoNotFilterButCopyBigFiles() throws Exception {
assertFalse(CompilerConfiguration.getInstance(myProject).isResourceFile("file.xyz"));
assertEquals(FileTypeManager.getInstance().getFileTypeByFileName("file.xyz"), StdFileTypes.UNKNOWN);
createProjectSubFile("resources/file.xyz").setBinaryContent(new byte[1024 * 1024 * 20]);
importProject("<groupId>test</groupId>" +
@@ -21,7 +21,6 @@ import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.maven.MavenImportingTestCase;
@@ -527,30 +526,7 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
assertModuleModuleDepScope("m1", "m4", DependencyScope.TEST);
}
public void testOptionalLibraryDependencyIsNotExportable() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>group</groupId>" +
" <artifactId>lib1</artifactId>" +
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>group</groupId>" +
" <artifactId>lib2</artifactId>" +
" <version>1</version>" +
" <optional>true</optional>" +
" </dependency>" +
"</dependencies>");
assertModules("project");
assertExportedModuleDeps("project", "Maven: group:lib1:1");
}
public void testOptionalModuleDependencyIsNotExportable() throws Exception {
public void testDependenciesAreNotExported() throws Exception {
createProjectPom("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<packaging>pom</packaging>" +
@@ -572,10 +548,9 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>m3</artifactId>" +
" <groupId>lib</groupId>" +
" <artifactId>lib</artifactId>" +
" <version>1</version>" +
" <optional>true</optional>" +
" </dependency>" +
"</dependencies>");
@@ -583,55 +558,8 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
"<artifactId>m2</artifactId>" +
"<version>1</version>");
createModulePom("m3", "<groupId>test</groupId>" +
"<artifactId>m3</artifactId>" +
"<version>1</version>");
importProject();
assertExportedModuleDeps("m1", "m2");
}
public void testOnlyCompileAndRuntimeDependenciesAreExported() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>compile</artifactId>" +
" <scope>compile</scope>" +
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>runtime</artifactId>" +
" <scope>runtime</scope>" +
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>test</artifactId>" +
" <scope>test</scope>" +
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>provided</artifactId>" +
" <scope>provided</scope>" +
" <version>1</version>" +
" </dependency>" +
" <dependency>" +
" <groupId>test</groupId>" +
" <artifactId>system</artifactId>" +
" <scope>system</scope>" +
" <systemPath>${java.home}/lib/tools.jar</systemPath>" +
" <version>1</version>" +
" </dependency>" +
"</dependencies>");
assertExportedModuleDeps("project", "Maven: test:compile:1", "Maven: test:runtime:1");
assertExportedDeps("m1");
}
public void testTransitiveDependencies() throws Exception {