Skip to content

Commit

Permalink
Fixed or suppressed some more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 3, 2016
1 parent 359a306 commit f7b348c
Show file tree
Hide file tree
Showing 27 changed files with 328 additions and 1,024 deletions.
4 changes: 2 additions & 2 deletions base-test/org.eclipse.jdt.groovy.core.tests.compiler/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<relativePath>../pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
<groupId>org.codehaus.groovy.eclipse</groupId>
<artifactId>org.codehaus.groovy.eclipse.base-test.parent</artifactId>
<version>2.9.2-SNAPSHOT</version>
Expand All @@ -10,4 +10,4 @@
<artifactId>org.eclipse.jdt.groovy.core.tests.compiler</artifactId>
<version>3.3.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
import org.eclipse.jdt.internal.core.search.indexing.BinaryIndexer;

public abstract class AbstractRegressionTest extends AbstractCompilerTest implements StopableTestCase {
// javac comparison related types, fields and methods - see runJavac for
// details
// javac comparison related types, fields and methods - see runJavac for details
static class JavacCompiler {
String rootDirectoryPath;
String javacPathName;
Expand Down Expand Up @@ -121,6 +120,8 @@ static class JavacCompiler {
this.version = JavaCore.VERSION_1_6;
} else if (rawVersion.indexOf("1.7") != -1) {
this.version = JavaCore.VERSION_1_7;
} else if (rawVersion.indexOf("1.8") != -1) {
this.version = JavaCore.VERSION_1_8;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
Expand Down Expand Up @@ -821,6 +822,8 @@ protected void compileAndDeploy(String source, String directoryName, String clas
buffer.append("\" -1.6");
} else if (this.complianceLevel == ClassFileConstants.JDK1_7) {
buffer.append("\" -1.7");
} else if (this.complianceLevel == JDK1_8) {
buffer.append("\" -1.8");
}
buffer
.append(" -preserveAllLocals -nowarn -g -classpath \"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,19 +877,13 @@ public void visitImports(ModuleNode node) {
try {
if (type != null) {
visitClassReference(type);
// FIXADE this is a bit messy, shoud use existing infra to push and pop
completeExpressionStack.push(imp);
if (imp.getFieldNameExpr() != null) {
primaryTypeStack.push(type);
imp.getFieldNameExpr().visit(this);
dependentDeclarationStack.pop();
dependentTypeStack.pop();
}

// if (imp.getAliasExpr() != null) {
// primaryTypeStack.push(type);
// imp.getAliasExpr().visit(this);
// }
completeExpressionStack.pop();
}
} catch (VisitCompleted e) {
Expand Down Expand Up @@ -1001,9 +995,7 @@ public void visitBinaryExpression(BinaryExpression node) {

toVisitPrimary.visit(this);

ClassNode primaryExprType;

primaryExprType = primaryTypeStack.pop();
ClassNode primaryExprType = primaryTypeStack.pop();
if (isAssignment) {
assignmentStorer.storeAssignment(node, scopes.peek(), primaryExprType);
}
Expand All @@ -1013,24 +1005,24 @@ public void visitBinaryExpression(BinaryExpression node) {
completeExpressionStack.pop();
// type of the entire expression
ClassNode completeExprType = primaryExprType;

ClassNode dependentExprType = primaryTypeStack.pop();

if (!isAssignment) {
// TODO: Is it an illegal state to have either as null?
assert primaryExprType != null && dependentExprType != null;

if (!isAssignment && primaryExprType != null && dependentExprType != null) {
// type of RHS of binary expression
// find the type of the complete expression
String associatedMethod = findBinaryOperatorName(node.getOperation().getText());
if (isArithmeticOperationOnNumberOrStringOrList(node.getOperation().getText(), primaryExprType, dependentExprType)) {
// another special case.
// In 1.8 and later, Groovy will not go through the
// MOP for standard arithmetic operations on numbers
completeExprType = dependentExprType.equals(VariableScope.STRING_CLASS_NODE) ? VariableScope.STRING_CLASS_NODE
: primaryExprType;
completeExprType = dependentExprType.equals(VariableScope.STRING_CLASS_NODE) ? VariableScope.STRING_CLASS_NODE : primaryExprType;
} else if (associatedMethod != null) {
// there is an overloadable method associated with this operation
// convert to a constant expression and infer type
TypeLookupResult result = lookupExpressionType(new ConstantExpression(associatedMethod), primaryExprType, false,
scopes.peek());
TypeLookupResult result = lookupExpressionType(new ConstantExpression(associatedMethod), primaryExprType, false, scopes.peek());
completeExprType = result.type;
if (associatedMethod.equals("getAt") && result.declaringType.equals(VariableScope.DGM_CLASS_NODE)) {
// special case getAt coming from DGM.
Expand Down Expand Up @@ -1069,13 +1061,8 @@ public void visitBinaryExpression(BinaryExpression node) {
}

/**
* Make assumption that no one has overloaded the basic arithmetic operations on numbers These operations will bypass the mop in
* most situations anyway
*
* @param text
* @param primaryExprType
* @param dependentExprType
* @return
* Make assumption that no one has overloaded the basic arithmetic operations on numbers.
* These operations will bypass the mop in most situations anyway.
*/
private boolean isArithmeticOperationOnNumberOrStringOrList(String text, ClassNode lhs, ClassNode rhs) {
if (text.length() != 1) {
Expand Down Expand Up @@ -2029,8 +2016,10 @@ private void handleCompleteExpression(Expression node, ClassNode exprType, Class

private void postVisit(Expression node, ClassNode type, ClassNode declaringType, ASTNode declaration) {
if (isPrimaryExpression(node)) {
assert type != null;
primaryTypeStack.push(type);
} else if (isDependentExpression(node)) {
// TODO: null has been seen here for type; is that okay?
dependentTypeStack.push(type);
dependentDeclarationStack.push(new Tuple(declaringType, declaration));
}
Expand Down Expand Up @@ -2180,7 +2169,7 @@ private MethodNode findMethodNode(IMethod method) {
try {
if (method.isConstructor()) {
List<ConstructorNode> constructors = clazz.getDeclaredConstructors();
if (constructors.size() == 0) {
if (constructors == null || constructors.isEmpty()) {
return null;
}
String[] jdtParamTypes = method.getParameterTypes() == null ? NO_PARAMS : method.getParameterTypes();
Expand Down Expand Up @@ -2415,8 +2404,8 @@ private boolean isPrimaryExpression(Expression node) {
TernaryExpression prop = (TernaryExpression) complete;
return prop.getTrueExpression() == node;
} else if (complete instanceof ForStatement) {
// this check is used to store the type of the collection expression so that it can be assigned to the for loop
// variable
// this check is used to store the type of the collection expression
// so that it can be assigned to the for loop variable
ForStatement prop = (ForStatement) complete;
return prop.getCollectionExpression() == node;
} else if (complete instanceof ListExpression) {
Expand Down Expand Up @@ -2460,8 +2449,8 @@ private boolean isPrimaryExpression(Expression node) {
* <li>property/field (ie- right part) of an attribute expression
* </ul>
*
* Note that for statements and ternary expressions do not have any dependent expression even though they have primary
* expressions
* Note that for statements and ternary expressions do not have any dependent
* expression even though they have primary expressions.
*
* @param node expression node to check
* @return true iff the node is the primary expression in an expression pair.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class CodeSelectImportsTests extends BrowsingTestCase {
void testCodeSelectOnImportType2() {
String source = '''\
import java.lang.Thread.State
import java.util.regex.Pattern
Pattern p = ~/123/
'''.stripIndent()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src" output="bin"/>
<classpathentry kind="src" path="test plugin" output="bin"/>
<classpathentry kind="src" path="test plugin" output="bin">
<attributes>
<attribute name="ignore_optional_problems" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
</classpath>
2 changes: 1 addition & 1 deletion ide/org.codehaus.groovy.eclipse.ant/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src" output="bin"/>
<classpathentry kind="src" path="src-ant" output="bin"/>
<classpathentry kind="src" path="src-ant" output="bin-ant"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
</classpath>
1 change: 1 addition & 0 deletions ide/org.codehaus.groovy.eclipse.ant/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bin
/bin-ant
2 changes: 2 additions & 0 deletions ide/org.codehaus.groovy.eclipse.ant/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Bundle-SymbolicName: org.codehaus.groovy.eclipse.ant;singleton:=true
Bundle-Name: Groovy Ant support
Bundle-Vendor: Codehaus.org
Bundle-Version: 2.9.2.qualifier
Bundle-ClassPath: .,
groovyAntEclipse.jar
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ant.core,
org.apache.ant;bundle-version="1.7.0",
Expand Down
28 changes: 9 additions & 19 deletions ide/org.codehaus.groovy.eclipse.ant/build.properties
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
###############################################################################
# Copyright (c) 2007, 2009 Codehaus.org, SpringSource, and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Andrew Eisenberg - modified for Groovy Eclipse 2.0
###############################################################################
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
source.groovyAntEclipse.jar = src-ant/
output.groovyAntEclipse.jar = bin-ant/

bin.includes = .,\
groovyAntEclipse.jar,\
META-INF/,\
plugin.xml,\
about.html
jars.compile.order = .,\
groovyAntEclipse.jar
source.groovyAntEclipse.jar = src-ant/
output.groovyAntEclipse.jar = bin/
compilerArg=-nowarn
src.includes = about.html
jars.extra.classpath=platform:/plugin/org.eclipse.jdt.core/jdtCompilerAdapter.jar

compilerArg=-nowarn
jars.compile.order=.,groovyAntEclipse.jar
jars.extra.classpath=platform:/plugin/org.eclipse.jdt.core/jdtCompilerAdapter.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 Codehaus.org, SpringSource, and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
/*
* Copyright 2009-2016 the original author or authors.
*
* Contributors:
* Andrew Eisenberg - modified for Groovy Eclipse 2.0
*******************************************************************************/
* 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.codehaus.groovy.eclipse.ant;


import java.io.File;
import java.lang.reflect.Method;

Expand All @@ -24,44 +28,42 @@
import org.eclipse.jdt.core.JDTCompilerAdapter;

/**
*
* @author Andrew Eisenberg
* @created Jul 10, 2010
*/
public class GroovyCompilerAdapter extends JDTCompilerAdapter implements CompilerAdapter {

@Override
public void setJavac(Javac javac) {
super.setJavac(javac);
// now ensure that Groovy files are included
File[] groovyFiles = getGroovyFiles(javac);
if (groovyFiles.length > 0) {
// now log...
for (int i = 0; i < groovyFiles.length; i++) {
for (int i = 0, n = groovyFiles.length; i < n; i += 1) {
javac.log("Compiling " + groovyFiles.length + " groovy source file"
+ (groovyFiles.length == 1 ? "" : "s")
+ (destDir != null ? " to " + destDir : ""));
String filename = groovyFiles[i].getAbsolutePath();
javac.log(filename);
}

File[] newCompileList = new File[groovyFiles.length + compileList.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
System.arraycopy(groovyFiles, 0, newCompileList, compileList.length, groovyFiles.length);
compileList = newCompileList;
}
}

protected File[] getGroovyFiles(Javac javac) {
String[] list = javac.getSrcdir().list();
File destDir = javac.getDestdir();
File[] sourceFiles = new File[0];
File[] sourceFiles = new File[0];
for (int i = 0; i < list.length; i++) {
File srcDir = javac.getProject().resolveFile(list[i]);
if (!srcDir.exists()) {
throw new BuildException("srcdir \""
+ srcDir.getPath()
+ "\" does not exist!", javac.getLocation());
throw new BuildException(
"srcdir \"" + srcDir.getPath() + "\" does not exist!", javac.getLocation());
}

DirectoryScanner ds = getDirectoryScanner(srcDir, javac);
Expand All @@ -79,23 +81,16 @@ protected File[] getGroovyFiles(Javac javac) {
}
return sourceFiles;
}

/**
* @param srcDir
* @return
*/

private DirectoryScanner getDirectoryScanner(File srcDir, Javac javac) {
try {
Method getDirectoryScannerMethod = MatchingTask.class.getDeclaredMethod("getDirectoryScanner", File.class);
getDirectoryScannerMethod.setAccessible(true);
return (DirectoryScanner) getDirectoryScannerMethod.invoke(javac, srcDir);
} catch (Exception e) {
throw new BuildException("Problem finding directory scanner for srcdir \""
+ srcDir.getPath()
+ "\"", e);
throw new BuildException("Problem finding directory scanner for srcdir \"" + srcDir.getPath() + "\"", e);
}
}

}


Expand All @@ -105,25 +100,22 @@ public String[] mapFileName(String sourceFileName) {
if (sourceFileName != null) {
if (sourceFileName.endsWith(".groovy")) {
return new String[] {
extractVariablePart(sourceFileName, ".groovy".length())
+ ".class" };
extractVariablePart(sourceFileName, ".groovy".length()) + ".class"
};
}
}
return null;
}

private String extractVariablePart(String name, int postfixLength) {
return name.substring(0,
name.length() - postfixLength);
return name.substring(0, name.length() - postfixLength);
}


public void setFrom(String from) {
// noop
// no-op
}

public void setTo(String to) {
// noop
// no-op
}

}
Loading

0 comments on commit f7b348c

Please sign in to comment.