Skip to content

Commit

Permalink
refresh project
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 6, 2023
1 parent ff32117 commit 126c301
Show file tree
Hide file tree
Showing 151 changed files with 613 additions and 672 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down Expand Up @@ -56,5 +56,4 @@ private boolean isResolvedClasspathChangeNotRawClasspath(IJavaElementDelta delta
return (delta.getFlags() & IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) != 0 &&
(delta.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) == 0;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.eclipse.dsl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -46,12 +47,7 @@ public static String[] getDisabledScripts() {
}

public static Set<String> getDisabledScriptsAsSet() {
String[] disabled = getDisabledScripts();
Set<String> set = new HashSet<>(disabled.length*2);
for (String dis : disabled) {
set.add(dis);
}
return set;
return new HashSet<>(Arrays.asList(getDisabledScripts()));
}

/**
Expand All @@ -71,24 +67,25 @@ private static String join(String[] filtered) {
sb.append(s);
sb.append(',');
}
sb.replace(sb.length()-1, sb.length(), "");
sb.replace(sb.length() - 1, sb.length(), "");
return sb.toString();
} else {
return "";
}
}

private static String[] filter(String[] disabled) {
// not working now
// IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// List<String> filtered = new ArrayList<String>(disabled.length);
// for (String string : disabled) {
// IResource r = root.getFile(new Path(string));
// if (r.getType() == IResource.FILE && r.isAccessible()) {
// filtered.add(string);
// }
// }
// return filtered.toArray(new String[filtered.size()]);
/* not working now
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
List<String> filtered = new ArrayList<String>(disabled.length);
for (String string : disabled) {
IResource r = root.getFile(new Path(string));
if (r.getType() == IResource.FILE && r.isAccessible()) {
filtered.add(string);
}
}
return filtered.toArray(new String[filtered.size()]);
*/
return disabled;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down Expand Up @@ -33,7 +33,7 @@ public class ResourceMarkerHandler implements IStaticCheckerHandler {

private IFile resource;

private int numFound = 0;
private int numFound;

@Override
public void setResource(IFile resource) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* 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
* https://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,
Expand Down Expand Up @@ -44,6 +44,55 @@
*/
public class ResourceTypeChecker {

private final IStaticCheckerHandler handler;
private final List<IResource> resources;

protected boolean onlyAssertions;
protected final char[][] includes;
protected final char[][] excludes;

public ResourceTypeChecker(IStaticCheckerHandler handler, String projectName, char[][] includes, char[][] excludes, boolean onlyAssertions) {
this(handler, createProject(projectName), includes, excludes, onlyAssertions);
}

public ResourceTypeChecker(IStaticCheckerHandler handler, List<IResource> resources, char[][] includes, char[][] excludes, boolean onlyAssertions) {
this.handler = handler;
this.resources = resources;
this.includes = includes;
this.excludes = excludes;
this.onlyAssertions = onlyAssertions;
}

private static List<IResource> createProject(String projectName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (!GroovyNature.hasGroovyNature(project)) {
throw new IllegalArgumentException("Invalid project: " + projectName);
}
return Collections.<IResource>singletonList(project);
}

/**
* Performs the tpe checking on the selected resources.
* @param monitor progress monitor, can be null
* @return true iff no type problems were found
* @throws CoreException
*/
public boolean doCheck(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Static type analysis", resources.size());
for (IResource resource : resources) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
CheckerVisitor visitor = new CheckerVisitor(monitor);
resource.accept(visitor);
monitor.worked(1);
}
return handler.finish(null);
}

class CheckerVisitor implements IResourceVisitor {
private IProgressMonitor monitor;

Expand Down Expand Up @@ -105,7 +154,7 @@ private Map<Integer, String> findComments(GroovyCompilationUnit unit) {
String candidate;
if (stok.hasMoreTokens() && (candidate = stok.nextToken()).startsWith("TYPE:")) {
// may or may not have a space after the colon
if (candidate.equals("TYPE:")) {
if ("TYPE:".equals(candidate)) {
if (stok.hasMoreTokens()) {
type = stok.nextToken();
}
Expand All @@ -121,53 +170,4 @@ private Map<Integer, String> findComments(GroovyCompilationUnit unit) {
return allComments;
}
}

private final IStaticCheckerHandler handler;
private final List<IResource> resources;

protected boolean onlyAssertions;
protected final char[][] includes;
protected final char[][] excludes;

public ResourceTypeChecker(IStaticCheckerHandler handler, String projectName, char[][] includes, char[][] excludes, boolean onlyAssertions) {
this(handler, createProject(projectName), includes, excludes, onlyAssertions);
}

public ResourceTypeChecker(IStaticCheckerHandler handler, List<IResource> resources, char[][] includes, char[][] excludes, boolean onlyAssertions) {
this.handler = handler;
this.resources = resources;
this.includes = includes;
this.excludes = excludes;
this.onlyAssertions = onlyAssertions;
}

private static List<IResource> createProject(String projectName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (!GroovyNature.hasGroovyNature(project)) {
throw new IllegalArgumentException("Invalid project: " + projectName);
}
return Collections.<IResource>singletonList(project);
}

/**
* Performs the tpe checking on the selected resources.
* @param monitor progress monitor, can be null
* @return true iff no type problems were found
* @throws CoreException
*/
public boolean doCheck(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Static type analysis", resources.size());
for (IResource resource : resources) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
CheckerVisitor visitor = new CheckerVisitor(monitor);
resource.accept(visitor);
monitor.worked(1);
}
return handler.finish(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,40 +142,40 @@ private void processCommandLine(String[] args) {

for (int i = 0; i < args.length; i += 1) {
String arg = args[i];
if (arg.equals("-h") || arg.equals("--help")) {
if ("-h".equals(arg) || "--help".equals(arg)) {
doHelp = true;
break;
} else if (arg.equals("--assertions_only")) {
} else if ("--assertions_only".equals(arg)) {
assertionsOnly = true;
} else if (arg.equals("--excludes")) {
} else if ("--excludes".equals(arg)) {
if (i == args.length - 1) {
System.err.println("Missing --excludes argument");
doHelp = true;
break;
}
excludes = args[++i];
} else if (arg.equals("--includes")) {
} else if ("--includes".equals(arg)) {
if (i == args.length - 1) {
System.err.println("Missing --includes argument");
doHelp = true;
break;
}
includes = args[++i];
} else if (arg.equals("--extra_dslds")) {
} else if ("--extra_dslds".equals(arg)) {
if (i == args.length - 1) {
System.err.println("Missing --extraDslds argument");
doHelp = true;
break;
}
extraDslds = args[++i].split("\\|");
} else if (arg.equals("--project_path")) {
} else if ("--project_path".equals(arg)) {
if (i == args.length - 1) {
System.err.println("Missing --project_path argument");
doHelp = true;
break;
}
projectFolderPath = args[++i];
} else if (arg.equals("--result_file")) {
} else if ("--result_file".equals(arg)) {
if (i == args.length - 1) {
System.err.println("Missing --result_file argument");
doHelp = true;
Expand Down Expand Up @@ -212,7 +212,8 @@ private void printUsage(boolean isInvalid) {
}

System.out.println("Usage:");
System.out.println("eclipse -application org.codehause.groovy.eclipse.staticCheck [--help] [-h] [--extra_dslds <FILES>] [--assertions_only] [--excludes <PATH>] [--includes <PATH>] [--project_path <PATH>] <PROJECT_NAME>");
System.out.println("eclipse -application org.codehause.groovy.eclipse.staticCheck" +
" [--help] [-h] [--extra_dslds <FILES>] [--assertions_only] [--excludes <PATH>] [--includes <PATH>] [--project_path <PATH>] <PROJECT_NAME>");
System.out.println("where:");
System.out.println("\t--help OR -h Print this message and exit.");
System.out.println("\t--extra_dslds list of extra dsld files to be included in this check. Use '|' as a file separator.");
Expand All @@ -223,7 +224,9 @@ private void printUsage(boolean isInvalid) {
System.out.println("\t--result_file File to send static checking results to. If not specified, then results sent to sysout.");
System.out.println("\t<PROJECT_NAME> Name of a project to type check. If not already in workspace, then must also use '--project_path'.");
System.out.println();
System.out.println("Ant style filters are allowed. Eg, src/org/codehaus/groovy/**/*.groovy means all files with groovy extensions in the org.codehaus.groovy package or below will be ex/included Filters can be concentenated using '|'.");
System.out.println("Ant style filters are allowed." +
" For example, src/org/codehaus/groovy/**/*.groovy means all files with groovy extensions in the org.codehaus.groovy tree will be ex/included." +
" Filters can be concentenated using '|'.");
}

private void removeExtraDslds() {
Expand Down
Loading

0 comments on commit 126c301

Please sign in to comment.