Unverified Commit 0067d3cd authored by Neil C Smith's avatar Neil C Smith Committed by GitHub
Browse files

Merge pull request #3121 from apache/delivery

Sync delivery to release125 for 12.5-beta2
parents c0f4399c 1bca4481
......@@ -209,7 +209,7 @@ public enum ServerDetails {
*/
GLASSFISH_SERVER_6(NbBundle.getMessage(ServerDetails.class, "STR_6_SERVER_NAME", new Object[]{}), // NOI18N
"deployer:gfv6ee9", // NOI18N
6,
600,
"https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/6.0.0/glassfish-6.0.0.zip", // NOI18N
"https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/6.0.0/glassfish-6.0.0.zip", // NOI18N
"http://www.eclipse.org/legal/epl-2.0" //NOI18N
......@@ -220,7 +220,7 @@ public enum ServerDetails {
*/
GLASSFISH_SERVER_6_1_0(NbBundle.getMessage(ServerDetails.class, "STR_610_SERVER_NAME", new Object[]{}), // NOI18N
"deployer:gfv610ee9", // NOI18N
6,
610,
"https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/6.1.0/glassfish-6.1.0.zip", // NOI18N
"https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/6.1.0/glassfish-6.1.0.zip", // NOI18N
"http://www.eclipse.org/legal/epl-2.0" //NOI18N
......
......@@ -121,11 +121,7 @@ public class ActionProviderImpl implements ActionProvider {
@Override
public String[] getSupportedActions() {
List<? extends GradleActionsProvider> providers = ActionToTaskUtils.actionProviders(project);
Set<String> actions = new HashSet<>();
for (GradleActionsProvider provider : providers) {
actions.addAll(provider.getSupportedActions());
}
Set<String> actions = new HashSet<>(ActionToTaskUtils.getAllSupportedActions(project));
// add a fixed 'prime build' action
actions.add(ActionProvider.COMMAND_PRIME);
actions.add(COMMAND_DL_SOURCES);
......@@ -184,7 +180,7 @@ public class ActionProviderImpl implements ActionProvider {
LOG.log(Level.FINEST, "Priming build action for {0} is: {1}", new Object[] { project, enabled });
return enabled;
}
return ActionToTaskUtils.isActionEnabled(command, project, context);
return ActionToTaskUtils.isActionEnabled(command, null, project, context);
}
@NbBundle.Messages({
......@@ -259,7 +255,7 @@ public class ActionProviderImpl implements ActionProvider {
LOG.log(Level.FINE, "Attempt to run a config-disabled action: {0}", action);
return false;
}
if (!ActionToTaskUtils.isActionEnabled(action, project, context)) {
if (!ActionToTaskUtils.isActionEnabled(action, mapping, project, context)) {
LOG.log(Level.FINE, "Attempt to run action that is not enabled: {0}", action);
return false;
}
......
......@@ -23,7 +23,9 @@ import org.netbeans.modules.gradle.spi.actions.ProjectActionMappingProvider;
import org.netbeans.modules.gradle.api.execute.ActionMapping;
import org.netbeans.modules.gradle.spi.actions.GradleActionsProvider;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gradle.api.execute.GradleExecConfiguration;
......@@ -47,10 +49,43 @@ public final class ActionToTaskUtils {
providers.addAll(Lookup.getDefault().lookupAll(GradleActionsProvider.class));
return providers;
}
public static boolean isActionEnabled(String action, Project project, Lookup lookup) {
ActionMapping mapping = getActiveMapping(action, project, lookup);
public static Set<String> getAllSupportedActions(@NonNull Project project) {
Set<String> actions = new HashSet<>();
for (GradleActionsProvider provider : actionProviders(project)) {
actions.addAll(provider.getSupportedActions());
}
ProjectActionMappingProvider projectProvider = project.getLookup().lookup(ProjectActionMappingProvider.class);
ConfigurableActionProvider contextProvider = project.getLookup().lookup(ConfigurableActionProvider.class);
ProjectConfigurationProvider<GradleExecConfiguration> pcp = project.getLookup().lookup(ProjectConfigurationProvider.class);
if (contextProvider == null || projectProvider == null) {
return actions;
}
if (pcp == null || contextProvider == null) {
actions.addAll(projectProvider.customizedActions());
} else {
for (GradleExecConfiguration gec : pcp.getConfigurations()) {
projectProvider = contextProvider.findActionProvider(gec.getId());
if (projectProvider != null) {
actions.addAll(projectProvider.customizedActions());
}
}
}
return actions;
}
public static boolean isCustomMapping(ActionMapping am) {
return am.getName().startsWith(ActionMapping.CUSTOM_PREFIX);
}
public static boolean isActionEnabled(String action, ActionMapping mapping, Project project, Lookup lookup) {
if (mapping == null) {
mapping = getActiveMapping(action, project, lookup);
}
if (!ActionMapping.isDisabled(mapping)) {
if (isCustomMapping(mapping)) {
return true;
}
List<? extends GradleActionsProvider> providers = actionProviders(project);
for (GradleActionsProvider provider : providers) {
if (provider.isActionEnabled(action, project, lookup)) {
......
......@@ -157,12 +157,7 @@ public class ConfigurableActionsProviderImpl implements ProjectActionMappingProv
this.project = project;
this.projectDirectory = project.getProjectDirectory();
FileChangeListener wl = WeakListeners.create(FileChangeListener.class, new FileChangeAdapter() {
@Override
public void fileDataCreated(FileEvent fe) {
actionFileChanged(fe.getFile(), null, false);
}
}, this.projectDirectory);
FileChangeListener wl = WeakListeners.create(FileChangeListener.class, fcl, this.projectDirectory);
projectDirectory.addFileChangeListener(wl);
LOG.log(Level.FINER, "Initializing ConfigurableAP for {0}", project);
......
......@@ -38,10 +38,12 @@ import org.junit.rules.TemporaryFolder;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ui.OpenProjects;
import org.netbeans.modules.gradle.api.execute.ActionMapping;
import org.netbeans.modules.gradle.api.execute.GradleCommandLine;
import org.netbeans.modules.gradle.api.execute.GradleExecConfiguration;
import org.netbeans.modules.gradle.api.execute.RunConfig;
import org.netbeans.modules.gradle.api.execute.RunUtilsTest;
import org.netbeans.modules.gradle.customizer.CustomActionMapping;
import org.netbeans.modules.gradle.execute.ConfigPersistenceUtilsTest;
import org.netbeans.modules.gradle.execute.GradleExecAccessor;
import org.netbeans.modules.gradle.execute.GradleExecutor;
......@@ -349,4 +351,52 @@ public class ConfigurableActionsProviderImplTest {
assertTrue("debug.single is supported for java.distribution / default", Arrays.asList(ap.getSupportedActions()).contains("debug.single"));
assertTrue("debug.single is enabled for java.distribution / default", ap.isActionEnabled("debug.single", Lookups.singleton(def)));
}
/**
* Checks that if a custom action is made/paersisted, it will be visible in
* action provider.
* @throws IOException
*/
@Test
public void testSaveCustomizedActionVisible() throws Exception {
createGradleProject2();
CustomActionRegistrationSupport supp = new CustomActionRegistrationSupport(project);
CustomActionMapping cam = new CustomActionMapping(ActionMapping.CUSTOM_PREFIX + "1");
cam.setArgs("build");
ActionProvider ap = project.getLookup().lookup(ActionProvider.class);
assertFalse(Arrays.asList(ap.getSupportedActions()).contains(cam.getName()));
supp.registerCustomAction(cam);
supp.save();
assertTrue(Arrays.asList(ap.getSupportedActions()).contains(cam.getName()));
}
/**
* Checks that custom created action is enabled.
*/
@Test
public void testCustomizedActionEnabled() throws Exception {
createGradleProject2();
CustomActionRegistrationSupport supp = new CustomActionRegistrationSupport(project);
CustomActionMapping cam = new CustomActionMapping(ActionMapping.CUSTOM_PREFIX + "1");
cam.setArgs("build");
ActionProvider ap = project.getLookup().lookup(ActionProvider.class);
assertFalse("Nonexistent ation must not be enabled", ap.isActionEnabled(cam.getName(), Lookup.EMPTY));
supp.registerCustomAction(cam);
supp.save();
assertTrue("Custom actions are always enabled", ap.isActionEnabled(cam.getName(), Lookup.EMPTY));
supp.unregisterCustomAction(cam.getName());
supp.save();
assertFalse("Deleted actions must not be enabled", ap.isActionEnabled(cam.getName(), Lookup.EMPTY));
}
}
......@@ -300,7 +300,7 @@ public class ASTUtils {
// how to get only methods from source?
// for now, just check line number, if < 0 it is not from source
// Second part of condition is for generated accessors
if ((!method.isSynthetic() && method.getCode() != null)
if ((!method.isSynthetic() && (method.isAbstract() || method.getCode() != null))
|| (method.isSynthetic() && possibleMethods.contains(method.getName()))) {
children.add(method);
}
......@@ -353,6 +353,46 @@ public class ASTUtils {
return offset;
}
/**
* Returns a simple name for a class. The result is not defined for local and
* anonymous classes and for closures.
* @param node the class
* @return class' simple name
*/
public static String getSimpleName(ClassNode node) {
if (node == null) {
return null;
}
if (node.getOuterClass() == null) {
return node.getNameWithoutPackage();
} else {
String s = node.getName().substring(node.getOuterClass().getName().length());
if (s.startsWith("$")) {
return s.substring(1);
} else {
return s;
}
}
}
/**
* Returns class' parent's name. For toplevel classes, returns the package name.
* For inner classes, it returns the outer class' name. The result is undefined for
* local, anonymous classes or closures.
* @param node the class node.
* @return parent name.
*/
public static String getClassParentName(ClassNode node) {
if (node == null) {
return null;
}
if (node.getOuterClass() == null) {
return node.getPackageName();
} else {
return node.getOuterClass().getName();
}
}
public static ASTNode getForeignNode(final IndexedElement o) {
......
......@@ -275,6 +275,7 @@ public class GroovyIndexer extends EmbeddingIndexer {
for (ASTElement child : children) {
switch (child.getKind()) {
case INTERFACE:
case CLASS:
analyzeClass((ASTClass) child);
break;
......@@ -299,6 +300,10 @@ public class GroovyIndexer extends EmbeddingIndexer {
case FIELD:
indexField((ASTField) child, document);
break;
case INTERFACE:
case CLASS:
analyzeClass((ASTClass) child);
break;
}
}
}
......
......@@ -73,6 +73,7 @@ public class StructureAnalyzer implements StructureScanner {
private Map<ASTClass, Set<FieldNode>> fields;
private Map<ASTClass, Set<PropertyNode>> properties;
private List<ASTMethod> methods;
private Map<String, ASTClass> classes = new HashMap<>();
private static final Logger LOG = Logger.getLogger(StructureAnalyzer.class.getName());
......@@ -170,7 +171,10 @@ public class StructureAnalyzer implements StructureScanner {
if (node instanceof ClassNode) {
ClassNode classNode = (ClassNode) node;
ASTClass co = new ASTClass(classNode, classNode.getName());
classes.put(co.getFqn(), co);
if (parent == null && classNode.getOuterClass() != null) {
parent = classes.get(classNode.getOuterClass().getName());
}
if (parent != null) {
parent.addChild(co);
} else {
......@@ -215,7 +219,9 @@ public class StructureAnalyzer implements StructureScanner {
@SuppressWarnings("unchecked")
List<ASTNode> list = ASTUtils.children(node);
// classes are collected from the whole source, but the toplevel classes come
// first/earlier than inners.
for (ASTNode child : list) {
path.descend(child);
scan(result, child, path, in, includes, parent);
......
......@@ -538,6 +538,12 @@ public abstract class CompletionItem extends DefaultCompletionProposal {
public ElementKind getKind() {
return ElementKind.METHOD;
}
@Override
public int getSortPrioOverride() {
// sort meta-methods after normal ones, but before keywords
return 550;
}
// accessed by CompletionAccessor
List<MethodParameter> getParameters() {
......
......@@ -21,6 +21,7 @@ package org.netbeans.modules.groovy.editor.api.elements.ast;
import org.codehaus.groovy.ast.ClassNode;
import org.netbeans.modules.csl.api.ElementKind;
import org.netbeans.modules.groovy.editor.api.ASTUtils;
import org.netbeans.modules.groovy.editor.api.elements.common.ClassElement;
public class ASTClass extends ASTElement implements ClassElement {
......@@ -29,14 +30,14 @@ public class ASTClass extends ASTElement implements ClassElement {
public ASTClass(ClassNode node, String fqn) {
super(node, node.getPackageName(), node.getNameWithoutPackage());
super(node, ASTUtils.getClassParentName(node), ASTUtils.getSimpleName(node));
if (fqn != null) {
this.fqn = fqn;
} else {
this.fqn = getName();
}
}
@Override
public String getFqn() {
return fqn;
......
......@@ -23,6 +23,7 @@ import java.util.Set;
import org.codehaus.groovy.ast.FieldNode;
import org.netbeans.modules.csl.api.ElementKind;
import org.netbeans.modules.csl.api.Modifier;
import org.netbeans.modules.groovy.editor.api.ASTUtils;
public final class ASTField extends ASTElement {
......@@ -33,7 +34,7 @@ public final class ASTField extends ASTElement {
public ASTField(FieldNode node, String in, boolean isProperty) {
super(node, in, node.getName());
this.isProperty = isProperty;
this.fieldType = node.getType().getNameWithoutPackage();
this.fieldType = ASTUtils.getSimpleName(node.getType());
}
@Override
......
......@@ -22,10 +22,12 @@ import groovy.lang.MetaMethod;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.ConstructorNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.netbeans.modules.csl.api.ElementKind;
import org.netbeans.modules.groovy.editor.api.ASTUtils;
import org.netbeans.modules.groovy.editor.api.elements.common.MethodElement;
public class ASTMethod extends ASTElement implements MethodElement {
......@@ -74,7 +76,7 @@ public class ASTMethod extends ASTElement implements MethodElement {
for (Parameter parameter : ((MethodNode) node).getParameters()) {
String paramName = parameter.getName();
String fqnType = parameter.getType().getName();
String type = parameter.getType().getNameWithoutPackage();
String type = ASTUtils.getSimpleName(parameter.getType());
parameters.add(new MethodParameter(fqnType, type, paramName));
}
......@@ -115,7 +117,7 @@ public class ASTMethod extends ASTElement implements MethodElement {
public String getName() {
if (name == null) {
if (node instanceof ConstructorNode) {
name = ((ConstructorNode) node).getDeclaringClass().getNameWithoutPackage();
name = ASTUtils.getSimpleName(((ConstructorNode) node).getDeclaringClass());
} else if (node instanceof MethodNode) {
name = ((MethodNode) node).getName();
}
......@@ -130,7 +132,7 @@ public class ASTMethod extends ASTElement implements MethodElement {
@Override
public String getReturnType() {
if (returnType == null) {
returnType = ((MethodNode) node).getReturnType().getNameWithoutPackage();
returnType = ASTUtils.getSimpleName(((MethodNode) node).getReturnType());
}
return returnType;
}
......
......@@ -19,8 +19,10 @@
package org.netbeans.modules.groovy.editor.completion.inference;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
......@@ -70,7 +72,7 @@ public final class MethodInference {
ClassNode callerType = findCallerType(methodCall.getObjectExpression(), path, baseDocument, offset);
if (callerType != null) {
return findReturnTypeFor(callerType, methodCall.getMethodAsString(), methodCall.getArguments(), path, false, baseDocument, offset);
return findReturnTypeFor(callerType.redirect(), methodCall.getMethodAsString(), methodCall.getArguments(), path, false, baseDocument, offset);
}
}
......@@ -93,7 +95,7 @@ public final class MethodInference {
if (expression instanceof StaticMethodCallExpression) {
StaticMethodCallExpression staticMethodCall = (StaticMethodCallExpression) expression;
return findReturnTypeFor(staticMethodCall.getOwnerType(), staticMethodCall.getMethod(), staticMethodCall.getArguments(), path, true, baseDocument, offset);
return findReturnTypeFor(staticMethodCall.getOwnerType().redirect(), staticMethodCall.getMethod(), staticMethodCall.getArguments(), path, true, baseDocument, offset);
}
return null;
}
......@@ -141,7 +143,7 @@ public final class MethodInference {
}
}
}
MethodNode possibleMethod = tryFindPossibleMethod(callerType, methodName, paramTypes, isStatic);
if (possibleMethod != null) {
return possibleMethod.getReturnType();
......@@ -154,7 +156,13 @@ public final class MethodInference {
MethodNode res = null;
ClassNode node = callerType;
do {
Queue<ClassNode> tq = new ArrayDeque<>();
tq.add(callerType.redirect());
while ((node = tq.poll()) != null) {
for (ClassNode in : node.getInterfaces()) {
// search also in interfaces
tq.add(in.redirect());
}
for (MethodNode method : node.getMethods(methodName)) {
if (isStatic && !method.isStatic()) {
continue;
......@@ -194,7 +202,10 @@ public final class MethodInference {
}
}
node = node.getSuperClass();
} while (node != null);
if (node != null) {
tq.add(node.redirect());
}
};
return res;
}
......
......@@ -20,6 +20,7 @@
package org.netbeans.modules.groovy.editor.completion.inference;
import groovy.lang.Range;
import java.util.Iterator;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
......@@ -38,6 +39,8 @@ import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.expr.RangeExpression;
import org.codehaus.groovy.ast.expr.StaticMethodCallExpression;
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.syntax.Types;
import org.netbeans.editor.BaseDocument;
......@@ -112,46 +115,86 @@ public class TypeInferenceVisitor extends TypeVisitor {
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
if (sameVariableName(leaf, expression.getLeftExpression())) {
guessedType = deriveExpressonType(expression.getRightExpression());
ClassNode fromExpression = deriveExpressonType(expression.getRightExpression());
if (fromExpression != null) {
guessedType = fromExpression;
}
}
}
private ASTNode leafStatement;
/**
* After each statement certify that the leaf / completion point was not
* passed.
*/
@Override
public void visitVariableExpression(VariableExpression expression) {
if (expression.isSuperExpression()) {
guessedType = expression.getType().getSuperClass();
protected void visitStatement(Statement statement) {
super.visitStatement(statement);
if (statement == leafStatement) {
leafReached = true;
}
}
@Override
public void visitBlockStatement(BlockStatement statement) {
ASTNode prev = null;
for (Iterator<ASTNode> it = path.iterator(); it.hasNext(); ) {
ASTNode n = it.next();
if (n == statement) {
leafStatement = prev;
break;
}
if (null != expression.getAccessedVariable()) {
Variable accessedVariable = expression.getAccessedVariable();
if (accessedVariable.hasInitialExpression()) {
Expression initialExpression = expression.getAccessedVariable().getInitialExpression();
if (initialExpression instanceof ConstantExpression
&& !initialExpression.getText().equals("null")) { // NOI18N
guessedType = ((ConstantExpression) initialExpression).getType();
} else if (initialExpression instanceof ConstructorCallExpression) {
guessedType = ClassHelper.make(((ConstructorCallExpression) initialExpression).getType().getName());
} else if (initialExpression instanceof MethodCallExpression) {
int newOffset = ASTUtils.getOffset(doc, initialExpression.getLineNumber(), initialExpression.getColumnNumber());
AstPath newPath = new AstPath(path.root(), newOffset, doc);
guessedType = MethodInference.findCallerType(initialExpression, newPath, doc, newOffset);
} else if (initialExpression instanceof ListExpression) {
guessedType = ((ListExpression) initialExpression).getType();
} else if (initialExpression instanceof MapExpression) {
guessedType = ((MapExpression) initialExpression).getType();
} else if (initialExpression instanceof RangeExpression) {
// this should work, but the type is Object - nut sure why
// guessedType = ((RangeExpression)initialExpression).getType();
guessedType = ClassHelper.makeWithoutCaching(Range.class, true);
}
} else if (accessedVariable instanceof Parameter) {
Parameter param = (Parameter) accessedVariable;
guessedType = param.getType();
}
} else if (!expression.getType().getName().equals("java.lang.Object")) {
guessedType = expression.getType();
prev = n;
}
super.visitBlockStatement(statement);
}
@Override
public void visitVariableExpression(VariableExpression expression) {
boolean guessed = true;
if (leaf instanceof VariableExpression && !sameVariableName(leaf, expression)) {
return;
}
if (expression.isSuperExpression()) {
guessedType = expression.getType().getSuperClass();
}
if (null != expression.getAccessedVariable()) {
Variable accessedVariable = expression.getAccessedVariable();
if (accessedVariable.hasInitialExpression()) {