From a6c589517c5f5a3f8ca5fe791028027e92defee1 Mon Sep 17 00:00:00 2001 From: khartlage Date: Mon, 1 Mar 2004 20:39:53 +0000 Subject: [PATCH 1/1] Eclipse3M7 version --- net.sourceforge.phpeclipse.tests/.classpath | 36 +- .../core/tests/util/AbstractCompilerTest.java | 160 + .../sourceforge/phpdt/core/tests/util/Util.java | 525 ++ .../php/test/DualParseSyntaxErrorTest.java | 158 + .../phpeclipse/tests/parser/PHPParserTestCase.java | 5 +- .../src/test/PHPParserTestCase2.java | 256 - .../phpdt/internal/compiler/Compiler.java | 4 +- .../internal/compiler/DocumentElementParser.java | 2 +- .../internal/compiler/SourceElementParser.java | 2 +- .../internal/compiler/batch/CompilationUnit.java | 75 + .../phpdt/internal/compiler/parser/Parser.java | 7 +- .../phpdt/internal/compiler/parser/UnitParser.java | 25 +- .../internal/compiler/problem/DefaultProblem.java | 252 +- .../internal/compiler/problem/ProblemReporter.java | 5952 +++++++++----------- .../phpeditor/php/PHPPartitionScanner.java | 6 +- 15 files changed, 3852 insertions(+), 3613 deletions(-) create mode 100644 net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java create mode 100644 net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/Util.java create mode 100644 net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java delete mode 100644 net.sourceforge.phpeclipse.tests/src/test/PHPParserTestCase2.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/batch/CompilationUnit.java diff --git a/net.sourceforge.phpeclipse.tests/.classpath b/net.sourceforge.phpeclipse.tests/.classpath index 8fb0ce4..065ac06 100644 --- a/net.sourceforge.phpeclipse.tests/.classpath +++ b/net.sourceforge.phpeclipse.tests/.classpath @@ -1,35 +1,7 @@ - - - - - - - - - - - - - - - - - - + + + + diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java new file mode 100644 index 0000000..5ea14a5 --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.core.tests.util; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +//import net.sourceforge.phpdt.core.tests.junit.extension.TestCase; +//import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions; + +public class AbstractCompilerTest extends TestCase { + + public static final String COMPLIANCE_1_3 = "1.3"; + public static final String COMPLIANCE_1_4 = "1.4"; + public static final String COMPLIANCE_1_5 = "1.5"; + + public static final int F_1_3 = 0x1; + public static final int F_1_4 = 0x2; + public static final int F_1_5 = 0x4; + + private static int possibleComplianceLevels = -1; + + protected String complianceLevel; + + /* + * Returns the possible compliance levels this VM instance can run. + */ + public static int getPossibleComplianceLevels() { + if (possibleComplianceLevels == -1) { + String compliance = System.getProperty("compliance"); + if (compliance != null) { + if (COMPLIANCE_1_3.equals(compliance)) { + possibleComplianceLevels = F_1_3; + } else if (COMPLIANCE_1_4.equals(compliance)) { + possibleComplianceLevels = F_1_4; + } else if (COMPLIANCE_1_5.equals(compliance)) { + possibleComplianceLevels = F_1_5; + } else { + System.out.println("Invalid compliance specified (" + compliance + ")"); + System.out.println("Use one of " + COMPLIANCE_1_3 + ", " + COMPLIANCE_1_4 + ", " + COMPLIANCE_1_5); + System.out.println("Defaulting to all possible compliances"); + } + } + if (possibleComplianceLevels == -1) { + possibleComplianceLevels = F_1_3; + String specVersion = System.getProperty("java.specification.version"); + boolean canRun1_4 = !"1.0".equals(specVersion) && !"1.1".equals(specVersion) && !"1.2".equals(specVersion) && !"1.3".equals(specVersion); + if (canRun1_4) { + possibleComplianceLevels |= F_1_4; + } + boolean canRun1_5 = canRun1_4 && !"1.4".equals(specVersion); + if (canRun1_5) { + possibleComplianceLevels |= F_1_5; + } + } + } + return possibleComplianceLevels; + } + + /* + * Returns a test suite including the tests defined by the given classes for all possible complianceLevels + * and using the given setup class (CompilerTestSetup or a subclass) + */ + public static Test suite(String suiteName, Class setupClass, ArrayList testClasses) { + TestSuite all = new TestSuite(suiteName); + int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); + if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) { + all.addTest(suiteForComplianceLevel(COMPLIANCE_1_3, setupClass, testClasses)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) { + all.addTest(suiteForComplianceLevel(COMPLIANCE_1_4, setupClass, testClasses)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) { + all.addTest(suiteForComplianceLevel(COMPLIANCE_1_5, setupClass, testClasses)); + } + return all; + } + + /* + * Returns a test suite including the tests defined by the given classes for the given complianceLevel + * (see AbstractCompilerTest for valid values) and using the given setup class (CompilerTestSetup or a subclass) + */ + public static Test suiteForComplianceLevel(String complianceLevel, Class setupClass, ArrayList testClasses) { + TestSuite suite; + if (testClasses.size() == 1) { + suite = new TestSuite((Class)testClasses.get(0), complianceLevel); + } else { + suite = new TestSuite(complianceLevel); + for (int i = 0, length = testClasses.size(); i < length; i++) { + Class testClass = (Class)testClasses.get(i); + TestSuite innerSuite = new TestSuite(testClass); + suite.addTest(innerSuite); + } + } + + // call the setup constructor with the suite and compliance level + try { + Constructor constructor = setupClass.getConstructor(new Class[]{Test.class, String.class}); + Test setUp = (Test)constructor.newInstance(new Object[]{suite, complianceLevel}); + return setUp; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + + return null; + } + + public AbstractCompilerTest(String name) { + super(name); + } + +// protected Map getCompilerOptions() { +// Map options = new CompilerOptions().getMap(); +// if (COMPLIANCE_1_3.equals(this.complianceLevel)) { +// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3); +// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); +// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); +// } else if (COMPLIANCE_1_4.equals(this.complianceLevel)) { +// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4); +// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); +// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); +// } else if (COMPLIANCE_1_5.equals(this.complianceLevel)) { +// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); +// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); +// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); +// } +// return options; +// } + + public String getName() { + String name = super.getName(); + if (this.complianceLevel != null) { + name = this.complianceLevel + " - " + name; + } + return name; + } + +// public void initialize(CompilerTestSetup setUp) { +// this.complianceLevel = setUp.complianceLevel; +// } +} diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/Util.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/Util.java new file mode 100644 index 0000000..d7fb981 --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/Util.java @@ -0,0 +1,525 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.core.tests.util; + +import java.io.*; +import java.net.ServerSocket; +import java.util.Locale; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +//import net.sourceforge.phpdt.core.tests.compiler.regression.Requestor; +import net.sourceforge.phpdt.internal.compiler.Compiler; +import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy; +import net.sourceforge.phpdt.internal.compiler.IProblemFactory; +import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit; +//import net.sourceforge.phpdt.internal.compiler.batch.FileSystem; +import net.sourceforge.phpdt.internal.compiler.env.INameEnvironment; +import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; +public class Util { + public static String OUTPUT_DIRECTORY = "comptest"; + +public static CompilationUnit[] compilationUnits(String[] testFiles) { + int length = testFiles.length / 2; + CompilationUnit[] result = new CompilationUnit[length]; + int index = 0; + for (int i = 0; i < length; i++) { + result[i] = new CompilationUnit(testFiles[index + 1].toCharArray(), testFiles[index], null); + index += 2; + } + return result; +} +//public static void compile(String[] pathsAndContents, Map options, String outputPath) { +// IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); +// Requestor requestor = +// new Requestor( +// problemFactory, +// outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator, +// false); +// INameEnvironment nameEnvironment = new FileSystem(getJavaClassLibs(), new String[] {}, null); +// IErrorHandlingPolicy errorHandlingPolicy = +// new IErrorHandlingPolicy() { +// public boolean stopOnFirstError() { +// return false; +// } +// public boolean proceedOnErrors() { +// return true; +// } +// }; +// Compiler batchCompiler = +// new Compiler( +// nameEnvironment, +// errorHandlingPolicy, +// options, +// requestor, +// problemFactory); +// batchCompiler.compile(compilationUnits(pathsAndContents)); // compile all files together +// System.err.print(requestor.problemLog); // problem log empty if no problems +//} +public static String[] concatWithClassLibs(String classpath, boolean inFront) { + String[] classLibs = getJavaClassLibs(); + final int length = classLibs.length; + String[] defaultClassPaths = new String[length + 1]; + if (inFront) { + System.arraycopy(classLibs, 0, defaultClassPaths, 1, length); + defaultClassPaths[0] = classpath; + } else { + System.arraycopy(classLibs, 0, defaultClassPaths, 0, length); + defaultClassPaths[length] = classpath; + } + return defaultClassPaths; +} +public static String convertToIndependantLineDelimiter(String source) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = source.length(); i < length; i++) { + char car = source.charAt(i); + if (car == '\r') { + buffer.append('\n'); + if (i < length-1 && source.charAt(i+1) == '\n') { + i++; // skip \n after \r + } + } else { + buffer.append(car); + } + } + return buffer.toString(); +} +/** + * Copy the given source (a file or a directory that must exists) to the given destination (a directory that must exists). + */ +public static void copy(String sourcePath, String destPath) { + sourcePath = toNativePath(sourcePath); + destPath = toNativePath(destPath); + File source = new File(sourcePath); + if (!source.exists()) return; + File dest = new File(destPath); + if (!dest.exists()) return; + if (source.isDirectory()) { + String[] files = source.list(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + String file = files[i]; + File sourceFile = new File(source, file); + if (sourceFile.isDirectory()) { + File destSubDir = new File(dest, file); + destSubDir.mkdir(); + copy(sourceFile.getPath(), destSubDir.getPath()); + } else { + copy(sourceFile.getPath(), dest.getPath()); + } + } + } + } else { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + File destFile = new File(dest, source.getName()); + if (destFile.exists() && !destFile.delete()) { + throw new IOException(destFile + " is in use"); + } + out = new FileOutputStream(destFile); + int bufferLength = 1024; + byte[] buffer = new byte[bufferLength]; + int read = 0; + while (read != -1) { + read = in.read(buffer, 0, bufferLength); + if (read != -1) { + out.write(buffer, 0, read); + } + } + } catch (IOException e) { + throw new Error(e.toString()); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + if (out != null) { + try { + out.close(); + } catch (IOException e) { + } + } + } + } +} +//public static void createJar(String[] pathsAndContents, Map options, String jarPath) throws IOException { +// String classesPath = getOutputDirectory() + File.separator + "classes"; +// File classesDir = new File(classesPath); +// flushDirectoryContent(classesDir); +// compile(pathsAndContents, options, classesPath); +// zip(classesDir, jarPath); +//} +/** + * Generate a display string from the given String. + * @param indent number of tabs are added at the begining of each line. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.displayString("abc\ndef\tghi")] +*/ +public static String displayString(String inputString){ + return displayString(inputString, 0); +} +/** + * Generate a display string from the given String. + * It converts: + * + * This method doesn't convert \r\n to \n. + *

+ * Example of use: + * + *

  • + *
    + * input string = "abc\ndef\tghi",
    + * indent = 3
    + * result = "\"\t\t\tabc\\n" +
    + * 			"\t\t\tdef\tghi\""
    + * 
    + *
  • + *
  • + *
    + * input string = "abc\ndef\tghi\n",
    + * indent = 3
    + * result = "\"\t\t\tabc\\n" +
    + * 			"\t\t\tdef\tghi\\n\""
    + * 
    + *
  • + *
  • + *
    + * input string = "abc\r\ndef\tghi\r\n",
    + * indent = 3
    + * result = "\"\t\t\tabc\\r\\n" +
    + * 			"\t\t\tdef\tghi\\r\\n\""
    + * 
    + *
  • + * + *

    + * + * @param inputString the given input string + * @param indent number of tabs are added at the begining of each line. + * + * @return the displayed string +*/ +public static String displayString(String inputString, int indent) { + int length = inputString.length(); + StringBuffer buffer = new StringBuffer(length); + java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + while (tokenizer.hasMoreTokens()){ + + String token = tokenizer.nextToken(); + if (token.equals("\r")) { + buffer.append("\\r"); + if (tokenizer.hasMoreTokens()) { + token = tokenizer.nextToken(); + if (token.equals("\n")) { + buffer.append("\\n"); + if (tokenizer.hasMoreTokens()) { + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } + continue; + } else { + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } + } else { + continue; + } + } else if (token.equals("\n")) { + buffer.append("\\n"); + if (tokenizer.hasMoreTokens()) { + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } + continue; + } + + StringBuffer tokenBuffer = new StringBuffer(); + for (int i = 0; i < token.length(); i++){ + char c = token.charAt(i); + switch (c) { + case '\r' : + tokenBuffer.append("\\r"); + break; + case '\n' : + tokenBuffer.append("\\n"); + break; + case '\b' : + tokenBuffer.append("\\b"); + break; + case '\t' : + tokenBuffer.append("\t"); + break; + case '\f' : + tokenBuffer.append("\\f"); + break; + case '\"' : + tokenBuffer.append("\\\""); + break; + case '\'' : + tokenBuffer.append("\\'"); + break; + case '\\' : + tokenBuffer.append("\\\\"); + break; + default : + tokenBuffer.append(c); + } + } + buffer.append(tokenBuffer.toString()); + } + buffer.append("\""); + return buffer.toString(); +} +/** + * Reads the content of the given source file and converts it to a display string. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0)] +*/ +public static String fileContentToDisplayString(String sourceFilePath, int indent, boolean independantLineDelimiter) { + File sourceFile = new File(sourceFilePath); + if (!sourceFile.exists()) { + System.out.println("File " + sourceFilePath + " does not exists."); + return null; + } + if (!sourceFile.isFile()) { + System.out.println(sourceFilePath + " is not a file."); + return null; + } + StringBuffer sourceContentBuffer = new StringBuffer(); + FileInputStream input = null; + try { + input = new FileInputStream(sourceFile); + } catch (FileNotFoundException e) { + return null; + } + try { + int read; + do { + read = input.read(); + if (read != -1) { + sourceContentBuffer.append((char)read); + } + } while (read != -1); + input.close(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + try { + input.close(); + } catch (IOException e2) { + } + } + String sourceString = sourceContentBuffer.toString(); + if (independantLineDelimiter) { + sourceString = convertToIndependantLineDelimiter(sourceString); + } + return displayString(sourceString, indent); +} +/** + * Reads the content of the given source file, converts it to a display string. + * If the destination file path is not null, writes the result to this file. + * Otherwise writes it to the console. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0, null)] +*/ +public static void fileContentToDisplayString(String sourceFilePath, int indent, String destinationFilePath, boolean independantLineDelimiter) { + String displayString = fileContentToDisplayString(sourceFilePath, indent, independantLineDelimiter); + if (destinationFilePath == null) { + System.out.println(displayString); + return; + } + writeToFile(displayString, destinationFilePath); +} +/** + * Flush content of a given directory (leaving it empty), + * no-op if not a directory. + */ +public static void flushDirectoryContent(File dir) { + if (dir.isDirectory()) { + String[] files = dir.list(); + if (files == null) return; + for (int i = 0, max = files.length; i < max; i++) { + File current = new File(dir, files[i]); + if (current.isDirectory()) { + flushDirectoryContent(current); + } + current.delete(); + } + } +} +/** + * Search the user hard-drive for a Java class library. + * Returns null if none could be found. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJavaClassLib()] +*/ +public static String[] getJavaClassLibs() { + String jreDir = getJREDirectory(); + if (jreDir == null) { + return new String[] {}; + } else { + final String vmName = System.getProperty("java.vm.name"); + if ("J9".equals(vmName)) { + return new String[] { toNativePath(jreDir + "/lib/jclMax/classes.zip")}; + } else { + File file = new File(jreDir + "/lib/rt.jar"); + if (file.exists()) { + return new String[] { + toNativePath(jreDir + "/lib/rt.jar") + }; + } else { + return new String[] { + toNativePath(jreDir + "/lib/core.jar"), + toNativePath(jreDir + "/lib/security.jar"), + toNativePath(jreDir + "/lib/graphics.jar") + }; + } + } + } +} +public static String getJavaClassLibsAsString() { + String[] classLibs = getJavaClassLibs(); + StringBuffer buffer = new StringBuffer(); + for (int i = 0, max = classLibs.length; i < max; i++) { + buffer + .append(classLibs[i]) + .append(File.pathSeparatorChar); + + } + return buffer.toString(); +} +/** + * Returns the JRE directory this tests are running on. + * Returns null if none could be found. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJREDirectory()] +*/ +public static String getJREDirectory() { + return System.getProperty("java.home"); +} +/** + * Search the user hard-drive for a possible output directory. + * Returns null if none could be found. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] +*/ +public static String getOutputDirectory() { + String container = System.getProperty("user.home"); + if (container == null){ + return null; + } else { + return toNativePath(container) + File.separator + OUTPUT_DIRECTORY; + } +} +/** + * Returns the next available port number on the local host. + */ +public static int getFreePort() { + ServerSocket socket = null; + try { + socket = new ServerSocket(0); + return socket.getLocalPort(); + } catch (IOException e) { + // ignore + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException e) { + // ignore + } + } + } + return -1; +} +/** + * Makes the given path a path using native path separators as returned by File.getPath() + * and trimming any extra slash. + */ +public static String toNativePath(String path) { + String nativePath = path.replace('\\', File.separatorChar).replace('/', File.separatorChar); + return + nativePath.endsWith("/") || nativePath.endsWith("\\") ? + nativePath.substring(0, nativePath.length() - 1) : + nativePath; +} +public static void writeToFile(String contents, String destinationFilePath) { + File destFile = new File(destinationFilePath); + FileOutputStream output = null; + try { + output = new FileOutputStream(destFile); + PrintWriter writer = new PrintWriter(output); + writer.print(contents); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + return; + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e2) { + } + } + } +} +//public static void zip(File rootDir, String zipPath) throws IOException { +// ZipOutputStream zip = null; +// try { +// zip = new ZipOutputStream(new FileOutputStream(zipPath)); +// zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash +// } finally { +// if (zip != null) { +// zip.close(); +// } +// } +//} +//private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { +// String[] list = dir.list(); +// if (list != null) { +// for (int i = 0, length = list.length; i < length; i++) { +// String name = list[i]; +// File file = new File(dir, name); +// if (file.isDirectory()) { +// zip(file, zip, rootPathLength); +// } else { +// String path = file.getPath(); +// path = path.substring(rootPathLength); +// ZipEntry entry = new ZipEntry(path.replace('\\', '/')); +// zip.putNextEntry(entry); +// zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); +// zip.closeEntry(); +// } +// } +// } +//} +} + diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java new file mode 100644 index 0000000..949a9ad --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java @@ -0,0 +1,158 @@ +/* + * Created on 29.02.2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package net.sourceforge.phpeclipse.phpeditor.php.test; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Locale; + +import net.sourceforge.phpdt.core.compiler.IProblem; +import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest; +import net.sourceforge.phpdt.core.tests.util.Util; +import net.sourceforge.phpdt.internal.compiler.CompilationResult; +import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies; +import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit; +import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit; +import net.sourceforge.phpdt.internal.compiler.parser.UnitParser; +import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem; +import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; +import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter; +import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; +import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; + +/** + * @author khartlage + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +public class DualParseSyntaxErrorTest extends AbstractCompilerTest { + public static boolean optimizeStringLiterals = false; + + public DualParseSyntaxErrorTest(String testName){ + super(testName); + } + public void checkParse( + char[] source, + String expectedSyntaxErrorDiagnosis, + String testName) { + + UnitParser parser = + new UnitParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + //new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault()))); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true); +// if (computedUnit.types != null) { +// for (int i = computedUnit.types.size(); --i >= 0;){ +// ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit); +// } +// } + + StringBuffer buffer = new StringBuffer(100); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + IProblem[] problems = compilationResult.getAllProblems(); + int count = problems.length; + int problemCount = 0; + char[] unitSource = compilationResult.compilationUnit.getContents(); + for (int i = 0; i < count; i++) { + if (problems[i] != null) { + if (problemCount == 0) + buffer.append("----------\n"); + problemCount++; + buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING")); + buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\')); + try { + buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource)); + buffer.append("\n"); + buffer.append(problems[i].getMessage()); + buffer.append("\n"); + } catch (Exception e) { + StringWriter stringWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(stringWriter)); + buffer.append(stringWriter.getBuffer()); + } + buffer.append("----------\n"); + } + } + } + String computedSyntaxErrorDiagnosis = buffer.toString(); + if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) { + System.out.println(Util.displayString(computedSyntaxErrorDiagnosis)); + } + assertEquals( + "Invalid syntax error diagnosis" + testName, + expectedSyntaxErrorDiagnosis, + computedSyntaxErrorDiagnosis); + } + + public void test01() { + String s = + "class class { \n"+ + " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+ + " { \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 1)\n" + + " class class { \n" + + " ^^^^^\n" + + "Parse error \"Don\'t use keyword for class declaration [class].\"\n" + + "----------\n" + + "2. ERROR in (at line 1)\n" + + " class class { \n" + + " ^\n" + + "Parse error \"Class name expected after keyword \'class\'.\"\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); + } + + public void test02() { + String s = + "if(!$result = mysql_query($sql)) return(array());\n"; + + String expectedSyntaxErrorDiagnosis = + ""; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); + } + + public void test03() { + String s = + "class test { \n"+ + " murks; \n"+ + " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+ + " { \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + ""; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); + } +} diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java index 6091e18..1122579 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java @@ -27,6 +27,9 @@ public class PHPParserTestCase extends TestCase { * Test the PHP Parser with different PHP snippets */ public void testPHPParser() { + // checkPHP("if(!$result = mysql_query($sql)) return(array());"); + checkPHP("class test { function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n{ \n } \n }"); + // Bugs item #690938 checkPHP( "$ebus_sql['sel_url_list'] = <<$a;", true); - checkPHP("for ($this->i = 0;$this->i<2;$this->i++) {}", true); - checkPHP("for ($i = 2;$i<3;$i+= 3) {}", true); - checkPHP("function c($a,$b) {}", true); - checkPHP("$a = $$tata;", true); - checkPHP("$$tata=2;", true); - checkPHP("$tata;", true); - checkPHP("$tata = &new Tutu;", true); - checkPHP("$tata = $bobo;", true); - checkPHP("function test($tutu) {$id = $this->gogo($titi); echo $id;}", true); - checkPHP("function test() { $tata = $b; echo $b;}", true); - checkPHP("function test() { echo $b;}", true); - checkPHP("for(;;) {}", true); - //checkHTML(new File("class.adm_gestuser.php")); - checkHTML("", true); - checkHTML("", true); - checkHTML("" + - "\n dfgdfgfdfg" + - "\n" + - "\n" + - "" + - "dfgdfg" + - "\ndsfgdf", false); - checkHTML("" + - "\n dfgdfgfdfg" + - "\n" + - "\n" + - "", true); - checkHTML("sdfsdf ", true); - checkHTML("\n\n\n\n ", true); - checkHTML("", true); - checkHTML(" foo ", true); - checkHTML(" ", true); -//todo : fix this checkHTML("'; ?>",true); - checkHTML("", true); - checkHTML("", true); - checkHTML("", true); - checkHTML("", true); - checkHTML("", true); - checkHTML("", true); - - checkPHP("$a = array();", true); - checkPHP("'caca';", true); - checkPHP("if $cac a) echo 'coucou';", false); - // checkPHP("$oka dd = 'a'.$i;$val = $$add;", false); - checkPHP("($a==\"b\") || (c($this->x)==\"d\");", true); - checkPHP("(substr($this->file, 0, 2) == \"MM\");", true); - checkPHP("(substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";", true); - checkPHP("return (substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";", true); - checkPHP("$this->highlightfile->linkscripts{$category};", true); - checkPHP("$code = call_user_method($this->highlightfile->linkscripts{$category}, $this->highlightfile, $oldword, $this->output_module);", true); - checkPHP("$this->startmap[$startcurrtag]();", true); - checkPHP("new $this->startmap[$startcurrtag]();", true); - checkPHP("$this->highlightfile = new $this->startmap[$startcurrtag]();", true); - checkPHP("echo \"Test\", \"me\";", true); - checkPHP("print (\"Test me\");", true); -// checkPHP("$s = <<blockvariables[$block][$varname]);", true); - checkPHP("new IT_Error(\"The block '$block' was not found in the template.\", __FILE__, __LINE__);", true); - checkPHP("for ($i=156, $j=0; $i<512; $i++, $j++) $v_checksum += ord(substr($v_binary_data_last,$j,1));", true); - checkPHP("define('MAIL_MIME_CRLF', $crlf, true);", false); - checkPHP("static $last_run = 0;", true); - checkPHP("unset($headers['Subject']);", true); - checkPHP("switch($func) {\n case \"f0\":\n case \"f1\":\n f1();\n break; \n case \"tt\": \n default: \n f0(); \n break;\n }", true); - checkPHP("function validateAndParseResponse($code, &$arguments) { }", true); - checkPHP("$options = Console_Getopt::getopt($argv, \"h?v:e:p:d:\");", true); - checkPHP("$this->container = new $container_class($container_options);", true); - checkPHP("class Cmd extends PEAR { var $arrSetting = array(); }", true); - checkPHP("class Cmd extends PEAR { var $arrSetting = array(), $i=10; }", true); - checkPHP("if (isset($test)) { } elseif (isset($lang)) { }", true); - checkPHP("require_once(\"mainfile.php\"); ", true); - checkPHP("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n", true); - checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n", true); - checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) :\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n", true); - checkPHP("$tipath = \"images/topics/\";", true); - checkPHP("$reasons = array(\"1\", \"2\",\"test\");", true); - checkPHP("if ($home == 1) { message_box(); blocks(Center);}", true); - checkPHP("$bresult = sql_query(\"select * from \".$functionName.\"_banner WHERE type='0' AND active='1'\", $dbi);", true); - checkPHP("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }", true); - checkPHP("list ($catid) = sql_fetch_row($result, $dbi);", true); - checkPHP("if (!$name) { \n }", true); - checkPHP("mt_srand((double)microtime()*1000000);", true); - checkPHP("\"\\\"\";", true); - checkPHP("$v->read();", true); - checkPHP("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);", true); - checkPHP("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";", true); - checkPHP("if (!empty($pass) AND $pass==$passwd) { }", true); - checkPHP("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);", true); - checkPHP("if ($term{0}!=$firstChar) {}", true); - checkPHP( - "echo \"
    \"._NOADMINYET.\"


    \"\n" - + ".\"
    \"\n" - + ".\"\"._NICKNAME.\":\"\n" - + ";", true); - checkPHP("/* \n overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/) \n */;", true); - checkPHP("if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){ } ", true); - checkPHP("$arrAtchCookie[1] -= filesize(realpath($AtchTempDir).\"/\".$xattachlist)/ 1024; ", true); - checkPHP( - "if (!isset($message)){ \n" - + "$message = $myrow[post_text];\n" - + "$message = eregi_replace(\"\\[addsig]\", \"\\n-----------------\\n\" . $myrow[user_sig], $message); \n" - + "$message = str_replace(\"
    \", \"\\n\", $message); \n" - + "$message = str_replace(\"
    \", \"\\n\", $message); \n } ", true); - checkPHP("do {$array[] = array(\"$myrow[uid]\" => \"$myrow[uname]\"); } while($myrow = mysql_fetch_array($result));", true); - checkPHP("$ol = new Overlib();", true); - checkPHP("$risultato = mysql_query($sql) or\n die(mysql_error());", true); - } - - private void checkPHP(final String strEval, final boolean good) { - ParseException ex = null; - try { - System.out.println("strEval = " + strEval); - PHPParser.phpParserTester(strEval); - } catch (ParseException e) { - ex = e; - } - if (good) { - try { - Assert.isTrue(ex == null); - } catch (RuntimeException e) { - ex.printStackTrace(); - throw e; - } - } else { - Assert.isNotNull(ex); - } - } - - private void checkHTML(final String strEval, final boolean good) { - ParseException ex = null; - try { - System.out.println("strEval = " + strEval); - PHPParser.htmlParserTester(strEval); - } catch (ParseException e) { - ex = e; - } - if (good) { - try { - Assert.isTrue(ex == null); - } catch (RuntimeException e) { - ex.printStackTrace(); - throw e; - } - } else { - Assert.isNotNull(ex); - } - } - - private void checkHTML(final File strEval, final boolean good) { - ParseException ex = null; - try { - System.out.println("strEval = " + strEval.toString()); - PHPParser.htmlParserTester(strEval); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (ParseException e) { - ex = e; - } - if (good) { - try { - Assert.isTrue(ex == null); - } catch (RuntimeException e) { - ex.printStackTrace(); - throw e; - } - } else { - Assert.isNotNull(ex); - } - } - - private void testDirectory(final File file) { - if (file.isDirectory()) { - final File[] files = file.listFiles(); - for (int i = 0; i < files.length; i++) { - testDirectory(files[i]); - } - } else { - if (file.getName().toUpperCase().endsWith(".PHP")) { - checkHTML(file, true); - } - } - } - - /** - * The JUnit setup method. - */ - protected void setUp() { - Assert.isTrue(PHPeclipsePlugin.PHPPARSER == PHPeclipsePlugin.PHPPARSER_NEW); - Assert.isTrue(PHPParser.PARSER_DEBUG); - parser = (test.PHPParser) PHPParserManager.getParser(); - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java index 6583d9e..081c885 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java @@ -215,7 +215,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { // diet parsing for large collection of unit CompilationUnitDeclaration parsedUnit; if (totalUnits < parseThreshold) { - parsedUnit = parser.parse(sourceUnit, unitResult); + parsedUnit = parser.parse(sourceUnit, unitResult,false); } else { parsedUnit = parser.dietParse(sourceUnit, unitResult); } @@ -293,7 +293,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { try { // diet parsing for large collection of units if (totalUnits < parseThreshold) { - parsedUnit = parser.parse(sourceUnits[i], unitResult); + parsedUnit = parser.parse(sourceUnits[i], unitResult, false); } else { parsedUnit = parser.dietParse(sourceUnits[i], unitResult); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/DocumentElementParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/DocumentElementParser.java index f2cb849..079b182 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/DocumentElementParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/DocumentElementParser.java @@ -1009,7 +1009,7 @@ public CompilationUnitDeclaration endParse(int act) { public void initialize() { //positionning the parser for a new compilation unit //avoiding stack reallocation and all that.... - super.initialize(); + super.initialize(false); intArrayPtr = -1; } /** diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java index b3c72a0..b689763 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java @@ -1084,7 +1084,7 @@ public void parseCompilationUnit( // diet = true; reportReferenceInfo = needReferenceInfo; CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, 10); //this.options.maxProblemsPerUnit); - CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult); + CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult, false); if (scanner.recordLineSeparator) { requestor.acceptLineSeparatorPositions(scanner.getLineEnds()); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/batch/CompilationUnit.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/batch/CompilationUnit.java new file mode 100644 index 0000000..0971b28 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/batch/CompilationUnit.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; + +import net.sourceforge.phpdt.core.compiler.CharOperation; +import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit; +import net.sourceforge.phpdt.internal.compiler.util.Util; + +public class CompilationUnit implements ICompilationUnit { + public char[] contents; + public char[] fileName; + public char[] mainTypeName; + String encoding; + +public CompilationUnit(char[] contents, String fileName, String encoding) { + this.contents = contents; + if (File.separator.equals("/")) { //$NON-NLS-1$ + if (fileName.indexOf("\\") != -1) { //$NON-NLS-1$ + fileName = fileName.replace('\\', File.separatorChar); + } + } else { + // the file separator is \ + if (fileName.indexOf('/') != -1) { + fileName = fileName.replace('/', File.separatorChar); + } + } + this.fileName = fileName.toCharArray(); + + int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$ + if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$ + start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$ + + int end = fileName.lastIndexOf("."); //$NON-NLS-1$ + if (end == -1) + end = fileName.length(); + + this.mainTypeName = fileName.substring(start, end).toCharArray(); + this.encoding = encoding; +} +public char[] getContents() { + if (this.contents != null) + return this.contents; // answer the cached source + + // otherwise retrieve it + try { + return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding); + } catch (IOException e) { + // assume no content then + } + return CharOperation.NO_CHAR; +} +public char[] getFileName() { + return this.fileName; +} +public char[] getMainTypeName() { + return this.mainTypeName; +} +public char[][] getPackageName() { + return null; +} +public String toString() { + return "CompilationUnit[" + new String(this.fileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$ +} +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 8d65f5b..609a33c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -172,6 +172,7 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par this.initializeScanner(); } + public void setFileToParse(IFile fileToParse) { this.currentPHPString = 0; PHPParserSuperclass.fileToParse = fileToParse; @@ -732,7 +733,7 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par scanner.setPHPMode(false); } - protected void initialize() { + protected void initialize(boolean phpMode) { compilationUnit = null; referenceContext = null; this.str = ""; @@ -741,8 +742,8 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par // this.rowCount = 1; // this.columnCount = 0; this.phpEnd = false; - this.phpMode = false; - scanner.setPHPMode(false); + this.phpMode = phpMode; + scanner.setPHPMode(phpMode); } /** * Parses a string with php tags diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java index 2da0761..d420454 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java @@ -77,8 +77,8 @@ public class UnitParser extends Parser { firstToken = TokenNameMINUS_MINUS; scanner.recordLineSeparator = false; } - public void initialize() { - super.initialize(); + public void initialize(boolean phpMode) { + super.initialize(phpMode); //positionning the parser for a new compilation unit //avoiding stack reallocation and all that.... // astPtr = -1; @@ -132,13 +132,13 @@ public class UnitParser extends Parser { // A P I - public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult) { + public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult, boolean phpMode) { // parses a compilation unit and manages error handling (even bugs....) CompilationUnitDeclaration unit; try { /* automaton initialization */ - initialize(); + initialize(phpMode); goForCompilationUnit(); /* scanner initialization */ @@ -253,7 +253,7 @@ public class UnitParser extends Parser { //convert bugs into parse error - initialize(); + initialize(false); goForConstructorBody(); nestedMethod[nestedType]++; @@ -273,7 +273,7 @@ public class UnitParser extends Parser { } if (lastAct == ERROR_ACTION) { - initialize(); + initialize(false); return; } @@ -317,7 +317,7 @@ public class UnitParser extends Parser { //convert bugs into parse error - initialize(); + initialize(false); goForExpression(); nestedMethod[nestedType]++; @@ -356,7 +356,7 @@ public class UnitParser extends Parser { //convert bugs into parse error - initialize(); + initialize(false); goForInitializer(); nestedMethod[nestedType]++; @@ -401,7 +401,7 @@ public class UnitParser extends Parser { // if ((md.modifiers & AccSemicolonBody) != 0) // return; - initialize(); + initialize(false); goForMethodBody(); nestedMethod[nestedType]++; @@ -445,7 +445,7 @@ public class UnitParser extends Parser { CompilationUnitDeclaration unit; try { /* automaton initialization */ - initialize(); + initialize(false); goForCompilationUnit(); /* scanner initialization */ @@ -469,12 +469,15 @@ public class UnitParser extends Parser { } public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult) { + return dietParse(sourceUnit, compilationResult, true); + } + public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, boolean phpMode) { CompilationUnitDeclaration parsedUnit; boolean old = diet; try { diet = true; - parsedUnit = parse(sourceUnit, compilationResult); + parsedUnit = parse(sourceUnit, compilationResult, phpMode); } finally { diet = old; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/DefaultProblem.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/DefaultProblem.java index 1e7169e..db6db84 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/DefaultProblem.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/DefaultProblem.java @@ -9,32 +9,19 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.phpdt.internal.compiler.problem; - import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.internal.compiler.util.Util; - import org.eclipse.ui.texteditor.ITextEditor; - - public class DefaultProblem implements ProblemSeverities, IProblem { - private char[] fileName; private int id; private int startPosition, endPosition, line; private int severity; private String[] arguments; private String message; - - public DefaultProblem( - char[] originatingFileName, - String message, - int id, - String[] stringArguments, - int severity, - int startPosition, - int endPosition, - int line) { - + public DefaultProblem(char[] originatingFileName, String message, int id, + String[] stringArguments, int severity, int startPosition, + int endPosition, int line) { this.fileName = originatingFileName; this.message = message; this.id = id; @@ -44,201 +31,244 @@ public class DefaultProblem implements ProblemSeverities, IProblem { this.endPosition = endPosition; this.line = line; } - - public String errorReportSource(ITextEditor textEditor){ //ICompilationUnit compilationUnit) { - //extra from the source the innacurate token + public String errorReportSource(char[] unitSource) { + //extra from the source the innacurate token //and "highlight" it using some underneath ^^^^^ //put some context around too. - //this code assumes that the font used in the console is fixed size - //sanity ..... if ((startPosition > endPosition) - || ((startPosition <= 0) && (endPosition <= 0))) + || ((startPosition < 0) && (endPosition < 0))) return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$ - + StringBuffer errorBuffer = new StringBuffer(" "); //$NON-NLS-1$ + errorBuffer.append(Util.bind("problem.atLine", String.valueOf(line))); //$NON-NLS-1$ + errorBuffer.append("\n\t"); //$NON-NLS-1$ + char c; final char SPACE = '\u0020'; final char MARK = '^'; final char TAB = '\t'; -// char[] source = compilationUnit.getContents(); - char[] source = textEditor.getDocumentProvider().getDocument(null).get().toCharArray(); //the next code tries to underline the token..... //it assumes (for a good display) that token source does not - //contain any \r \n. This is false on statements ! + //contain any \r \n. This is false on statements ! //(the code still works but the display is not optimal !) - - //compute the how-much-char we are displaying around the inaccurate token - int begin = startPosition >= source.length ? source.length - 1 : startPosition; - int relativeStart = 0; - int end = endPosition >= source.length ? source.length - 1 : endPosition; - int relativeEnd = 0; - label : for (relativeStart = 0;; relativeStart++) { - if (begin == 0) - break label; - if ((source[begin - 1] == '\n') || (source[begin - 1] == '\r')) - break label; - begin--; + // expand to line limits + int length = unitSource.length, begin, end; + for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) { + if ((c = unitSource[begin - 1]) == '\n' || c == '\r') + break; } - label : for (relativeEnd = 0;; relativeEnd++) { - if ((end + 1) >= source.length) - break label; - if ((source[end + 1] == '\r') || (source[end + 1] == '\n')) { - break label; - } - end++; + for (end = endPosition >= length ? length - 1 : endPosition; end + 1 < length; end++) { + if ((c = unitSource[end + 1]) == '\r' || c == '\n') + break; } - //extract the message form the source - char[] extract = new char[end - begin + 1]; - System.arraycopy(source, begin, extract, 0, extract.length); - char c; - //remove all SPACE and TAB that begin the error message... - int trimLeftIndex = 0; - while (((c = extract[trimLeftIndex++]) == TAB) || (c == SPACE)) { - }; - System.arraycopy( - extract, - trimLeftIndex - 1, - extract = new char[extract.length - trimLeftIndex + 1], - 0, - extract.length); - relativeStart -= trimLeftIndex; - //buffer spaces and tabs in order to reach the error position - int pos = 0; - char[] underneath = new char[extract.length]; // can't be bigger - for (int i = 0; i <= relativeStart; i++) { - if (extract[i] == TAB) { - underneath[pos++] = TAB; - } else { - underneath[pos++] = SPACE; - } + // trim left and right spaces/tabs + while ((c = unitSource[begin]) == ' ' || c == '\t') + begin++; + //while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO + // (philippe) should also trim right, but all tests are to be updated + // copy source + errorBuffer.append(unitSource, begin, end - begin + 1); + errorBuffer.append("\n\t"); //$NON-NLS-1$ + // compute underline + for (int i = begin; i < startPosition; i++) { + errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE); + } + for (int i = startPosition; i <= (endPosition >= length + ? length - 1 + : endPosition); i++) { + errorBuffer.append(MARK); } - //mark the error position - for (int i = startPosition; - i <= (endPosition >= source.length ? source.length - 1 : endPosition); - i++) - underneath[pos++] = MARK; - //resize underneathto remove 'null' chars - System.arraycopy(underneath, 0, underneath = new char[pos], 0, pos); - - return " " + Util.bind("problem.atLine", String.valueOf(line)) //$NON-NLS-2$ //$NON-NLS-1$ - + "\n\t" + new String(extract) + "\n\t" + new String(underneath); //$NON-NLS-2$ //$NON-NLS-1$ + return errorBuffer.toString(); } - + // public String errorReportSource(ITextEditor textEditor){ + // //ICompilationUnit compilationUnit) { + // //extra from the source the innacurate token + // //and "highlight" it using some underneath ^^^^^ + // //put some context around too. + // + // //this code assumes that the font used in the console is fixed size + // + // //sanity ..... + // if ((startPosition > endPosition) + // || ((startPosition <= 0) && (endPosition <= 0))) + // return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$ + // + // final char SPACE = '\u0020'; + // final char MARK = '^'; + // final char TAB = '\t'; + //// char[] source = compilationUnit.getContents(); + // char[] source = + // textEditor.getDocumentProvider().getDocument(null).get().toCharArray(); + // //the next code tries to underline the token..... + // //it assumes (for a good display) that token source does not + // //contain any \r \n. This is false on statements ! + // //(the code still works but the display is not optimal !) + // + // //compute the how-much-char we are displaying around the inaccurate + // token + // int begin = startPosition >= source.length ? source.length - 1 : + // startPosition; + // int relativeStart = 0; + // int end = endPosition >= source.length ? source.length - 1 : + // endPosition; + // int relativeEnd = 0; + // label : for (relativeStart = 0;; relativeStart++) { + // if (begin == 0) + // break label; + // if ((source[begin - 1] == '\n') || (source[begin - 1] == '\r')) + // break label; + // begin--; + // } + // label : for (relativeEnd = 0;; relativeEnd++) { + // if ((end + 1) >= source.length) + // break label; + // if ((source[end + 1] == '\r') || (source[end + 1] == '\n')) { + // break label; + // } + // end++; + // } + // //extract the message form the source + // char[] extract = new char[end - begin + 1]; + // System.arraycopy(source, begin, extract, 0, extract.length); + // char c; + // //remove all SPACE and TAB that begin the error message... + // int trimLeftIndex = 0; + // while (((c = extract[trimLeftIndex++]) == TAB) || (c == SPACE)) { + // }; + // System.arraycopy( + // extract, + // trimLeftIndex - 1, + // extract = new char[extract.length - trimLeftIndex + 1], + // 0, + // extract.length); + // relativeStart -= trimLeftIndex; + // //buffer spaces and tabs in order to reach the error position + // int pos = 0; + // char[] underneath = new char[extract.length]; // can't be bigger + // for (int i = 0; i <= relativeStart; i++) { + // if (extract[i] == TAB) { + // underneath[pos++] = TAB; + // } else { + // underneath[pos++] = SPACE; + // } + // } + // //mark the error position + // for (int i = startPosition; + // i <= (endPosition >= source.length ? source.length - 1 : endPosition); + // i++) + // underneath[pos++] = MARK; + // //resize underneathto remove 'null' chars + // System.arraycopy(underneath, 0, underneath = new char[pos], 0, pos); + // + // return " " + Util.bind("problem.atLine", String.valueOf(line)) + // //$NON-NLS-2$ //$NON-NLS-1$ + // + "\n\t" + new String(extract) + "\n\t" + new String(underneath); + // //$NON-NLS-2$ //$NON-NLS-1$ + // } /** * Answer back the original arguments recorded into the problem. + * * @return java.lang.String[] */ public String[] getArguments() { - return arguments; } - /** * Answer the type of problem. + * * @see org.eclipse.jdt.core.compiler.IProblem#getID() * @return int */ public int getID() { - return id; } - /** - * Answer a localized, human-readable message string which describes the problem. + * Answer a localized, human-readable message string which describes the + * problem. + * * @return java.lang.String */ public String getMessage() { - return message; } - /** * Answer the file name in which the problem was found. + * * @return char[] */ public char[] getOriginatingFileName() { - return fileName; } - /** * Answer the end position of the problem (inclusive), or -1 if unknown. + * * @return int */ public int getSourceEnd() { - return endPosition; } - /** * Answer the line number in source where the problem begins. + * * @return int */ public int getSourceLineNumber() { - return line; } - /** * Answer the start position of the problem (inclusive), or -1 if unknown. + * * @return int */ public int getSourceStart() { - return startPosition; } - /* * Helper method: checks the severity to see if the Error bit is set. * @return boolean */ public boolean isError() { - return (severity & ProblemSeverities.Error) != 0; } - /* * Helper method: checks the severity to see if the Error bit is not set. * @return boolean */ public boolean isWarning() { - return (severity & ProblemSeverities.Error) == 0; } - /** * Set the end position of the problem (inclusive), or -1 if unknown. - * + * * Used for shifting problem positions. - * @param sourceEnd the new value of the sourceEnd of the receiver + * + * @param sourceEnd + * the new value of the sourceEnd of the receiver */ public void setSourceEnd(int sourceEnd) { - endPosition = sourceEnd; } - /** * Set the line number in source where the problem begins. - * @param lineNumber the new value of the line number of the receiver + * + * @param lineNumber + * the new value of the line number of the receiver */ public void setSourceLineNumber(int lineNumber) { - line = lineNumber; } - /** * Set the start position of the problem (inclusive), or -1 if unknown. - * + * * Used for shifting problem positions. - * @param sourceStart the new value of the source start position of the receiver + * + * @param sourceStart + * the new value of the source start position of the receiver */ public void setSourceStart(int sourceStart) { - startPosition = sourceStart; } - public String toString() { - String s = "Pb(" + (id & IgnoreCategoriesMask) + ") "; //$NON-NLS-1$ //$NON-NLS-2$ if (message != null) { s += message; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java index 5bdab62..7e72de4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java @@ -9,7 +9,6 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.phpdt.internal.compiler.problem; - import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.core.compiler.InvalidInputException; @@ -76,3255 +75,2822 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference; import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression; - public class ProblemReporter extends ProblemHandler implements ProblemReasons { - public ReferenceContext referenceContext; -public ProblemReporter(IErrorHandlingPolicy policy, IProblemFactory problemFactory) { -//CompilerOptions options, IProblemFactory problemFactory) { - super(policy, problemFactory);//options, problemFactory); -} -public void abortDueToInternalError(String errorMessage) { - String[] arguments = new String[] {errorMessage}; - this.handle( - IProblem.Unclassified, - arguments, - arguments, - Error | Abort, - 0, - 0); -} -public void abortDueToInternalError(String errorMessage, AstNode location) { - String[] arguments = new String[] {errorMessage}; - this.handle( - IProblem.Unclassified, - arguments, - arguments, - Error | Abort, - location.sourceStart, - location.sourceEnd); -} -public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) { - - this.handle( - // %1 must be abstract since it cannot override the inherited package-private abstract method %2 - IProblem.AbstractMethodCannotBeOverridden, - new String[] { - new String(type.sourceName()), - new String( - CharOperation.concat( - concreteMethod.declaringClass.readableName(), - concreteMethod.readableName(), - '.'))}, - new String[] { - new String(type.sourceName()), - new String( - CharOperation.concat( - concreteMethod.declaringClass.shortReadableName(), - concreteMethod.shortReadableName(), - '.'))}, - type.sourceStart(), - type.sourceEnd()); -} -public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) { - - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.AbstractMethodInAbstractClass, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) { - this.handle( + public ProblemReporter(IErrorHandlingPolicy policy, + IProblemFactory problemFactory) { + //CompilerOptions options, IProblemFactory problemFactory) { + super(policy, problemFactory);//options, problemFactory); + } + public void abortDueToInternalError(String errorMessage) { + String[] arguments = new String[]{errorMessage}; + this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, + 0, 0); + } + public void abortDueToInternalError(String errorMessage, AstNode location) { + String[] arguments = new String[]{errorMessage}; + this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, + location.sourceStart, location.sourceEnd); + } + public void abstractMethodCannotBeOverridden(SourceTypeBinding type, + MethodBinding concreteMethod) { + this.handle( + // %1 must be abstract since it cannot override the inherited + // package-private abstract method %2 + IProblem.AbstractMethodCannotBeOverridden, new String[]{ + new String(type.sourceName()), + new String(CharOperation.concat( + concreteMethod.declaringClass.readableName(), + concreteMethod.readableName(), '.'))}, + new String[]{ + new String(type.sourceName()), + new String(CharOperation.concat( + concreteMethod.declaringClass + .shortReadableName(), concreteMethod + .shortReadableName(), '.'))}, type + .sourceStart(), type.sourceEnd()); + } + public void abstractMethodInAbstractClass(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.AbstractMethodInAbstractClass, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void abstractMethodMustBeImplemented(SourceTypeBinding type, + MethodBinding abstractMethod) { + this.handle( // Must implement the inherited abstract method %1 - // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods. - IProblem.AbstractMethodMustBeImplemented, - new String[] { - new String( - CharOperation.concat( - abstractMethod.declaringClass.readableName(), - abstractMethod.readableName(), - '.'))}, - new String[] { - new String( - CharOperation.concat( - abstractMethod.declaringClass.shortReadableName(), - abstractMethod.shortReadableName(), - '.'))}, - type.sourceStart(), - type.sourceEnd()); -} -public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) { - this.handle( - IProblem.BodyForAbstractMethod, - NoArgument, - NoArgument, - method.sourceStart, - method.sourceEnd, - method, - method.compilationResult()); -} -public void alreadyDefinedLabel(char[] labelName, AstNode location) { - String[] arguments = new String[] {new String(labelName)}; - this.handle( - IProblem.DuplicateLabel, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) { - this.handle( - IProblem.AnonymousClassCannotExtendFinalClass, - new String[] {new String(type.readableName())}, - new String[] {new String(type.shortReadableName())}, - expression.sourceStart, - expression.sourceEnd); -} -public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) { - String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)}; - this.handle( - IProblem.ArgumentTypeCannotBeVoid, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) { - String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)}; - this.handle( - IProblem.ArgumentTypeCannotBeVoidArray, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.ArgumentTypeNotFound; - break; - case NotVisible : // 2 - id = IProblem.ArgumentTypeNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.ArgumentTypeAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.ArgumentTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + // 8.4.3 - Every non-abstract subclass of an abstract type, A, + // must provide a concrete implementation of all of A's + // methods. + IProblem.AbstractMethodMustBeImplemented, + new String[]{new String(CharOperation.concat( + abstractMethod.declaringClass.readableName(), + abstractMethod.readableName(), '.'))}, + new String[]{new String(CharOperation.concat( + abstractMethod.declaringClass.shortReadableName(), + abstractMethod.shortReadableName(), '.'))}, type + .sourceStart(), type.sourceEnd()); } - this.handle( - id, - new String[] {new String(methodDecl.selector), arg.name(), new String(expectedType.readableName())}, - new String[] {new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName())}, - arg.type.sourceStart, - arg.type.sourceEnd); -} -public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) { - this.handle( - IProblem.ArrayConstantsOnlyInArrayInitializers, - NoArgument, - NoArgument, - sourceStart, - sourceEnd); -} -public void assignmentHasNoEffect(Assignment assignment, char[] name){ - String[] arguments = new String[] { new String(name) }; - this.handle( - IProblem.AssignmentHasNoEffect, - arguments, - arguments, - assignment.sourceStart, - assignment.sourceEnd); -} -public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) { - this.handle( - IProblem.VoidMethodReturnsValue, - new String[] {new String(expectedType.readableName())}, - new String[] {new String(expectedType.shortReadableName())}, - returnStatement.sourceStart, - returnStatement.sourceEnd); -} -public void attemptToReturnVoidValue(ReturnStatement returnStatement) { - this.handle( - IProblem.MethodReturnsVoid, - NoArgument, - NoArgument, - returnStatement.sourceStart, - returnStatement.sourceEnd); -} -//public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) { -// String[] arguments = new String[] {new String(location.selector), parametersAsString(location.binding)}; -// if (location.isConstructor()) { -// this.handle( -// IProblem.BytecodeExceeds64KLimitForConstructor, -// arguments, -// arguments, -// Error | Abort, -// location.sourceStart, -// location.sourceEnd); -// } else { -// this.handle( -// IProblem.BytecodeExceeds64KLimit, -// arguments, -// arguments, -// Error | Abort, -// location.sourceStart, -// location.sourceEnd); -// } -//} -public void bytecodeExceeds64KLimit(TypeDeclaration location) { - this.handle( - IProblem.BytecodeExceeds64KLimitForClinit, - NoArgument, - NoArgument, - Error | Abort, - location.sourceStart, - location.sourceEnd); -} -public void cannotAllocateVoidArray(Expression expression) { - this.handle( - IProblem.CannotAllocateVoidArray, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void cannotAssignToFinalField(FieldBinding field, AstNode location) { - this.handle( - IProblem.FinalFieldAssignment, - new String[] { - (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$ - new String(field.readableName())}, - new String[] { - (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$ - new String(field.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void cannotAssignToFinalLocal(LocalVariableBinding local, AstNode location) { - String[] arguments = new String[] { new String(local.readableName())}; - this.handle( - IProblem.NonBlankFinalLocalAssignment, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, AstNode location) { - String[] arguments = new String[] {new String(local.readableName())}; - this.handle( - IProblem.FinalOuterLocalAssignment, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) { - String[] arguments = new String[] {new String(interfaceName)}; - this.handle( - IProblem.CannotDefineInterfaceInLocalType, - arguments, - arguments, - sourceStart, - sourceEnd); -} -public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) { - this.handle( - IProblem.CannotDefineDimensionExpressionsWithInit, - NoArgument, - NoArgument, - expresssion.sourceStart, - expresssion.sourceEnd); -} -public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) { - this.handle( - IProblem.DirectInvocationOfAbstractMethod, - new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)}, - new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)}, - messageSend.sourceStart, - messageSend.sourceEnd); -} -public void cannotImportPackage(ImportReference importRef) { - String[] arguments = new String[] {CharOperation.toString(importRef.tokens)}; - this.handle( - IProblem.CannotImportPackage, - arguments, - arguments, - importRef.sourceStart, - importRef.sourceEnd); -} -public void cannotInstantiate(TypeReference typeRef, TypeBinding type) { - this.handle( - IProblem.InvalidClassInstantiation, - new String[] {new String(type.readableName())}, - new String[] {new String(type.shortReadableName())}, - typeRef.sourceStart, - typeRef.sourceEnd); -} -public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, AstNode location) { - String[] arguments =new String[]{ new String(local.readableName())}; - this.handle( - IProblem.OuterLocalMustBeFinal, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void cannotReturnInInitializer(AstNode location) { - this.handle( - IProblem.CannotReturnInInitializer, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void cannotThrowNull(ThrowStatement statement) { - this.handle( - IProblem.CannotThrowNull, - NoArgument, - NoArgument, - statement.sourceStart, - statement.sourceEnd); -} -public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) { - this.handle( - IProblem.CannotThrowType, - new String[] {new String(expectedType.readableName())}, - new String[] {new String(expectedType.shortReadableName())}, - exceptionType.sourceStart, - exceptionType.sourceEnd); -} -public void cannotUseSuperInJavaLangObject(AstNode reference) { - this.handle( - IProblem.ObjectHasNoSuperclass, - NoArgument, - NoArgument, - reference.sourceStart, - reference.sourceEnd); -} -public void cannotUseSuperInCodeSnippet(int start, int end) { - this.handle( - IProblem.CannotUseSuperInCodeSnippet, - NoArgument, - NoArgument, - Error | Abort, - start, - end); -} -public void caseExpressionMustBeConstant(Expression expression) { - this.handle( - IProblem.NonConstantExpression, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) { - String name = new String(type.sourceName()); - String expectedFullName = new String(expectedType.readableName()); - String expectedShortName = new String(expectedType.shortReadableName()); - if (expectedShortName.equals(name)) expectedShortName = expectedFullName; - this.handle( - IProblem.ClassExtendFinalClass, - new String[] {expectedFullName, name}, - new String[] {expectedShortName, name}, - superclass.sourceStart, - superclass.sourceEnd); -} -public void codeSnippetMissingClass(String missing, int start, int end) { - String[] arguments = new String[]{missing}; - this.handle( - IProblem.CodeSnippetMissingClass, - arguments, - arguments, - Error | Abort, - start, - end); -} -public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) { - String[] arguments = new String[]{ className, missingMethod, argumentTypes }; - this.handle( - IProblem.CodeSnippetMissingMethod, - arguments, - arguments, - Error | Abort, - start, - end); -} -/* - * Given the current configuration, answers which category the problem - * falls into: - * Error | Warning | Ignore - */ -//public int computeSeverity(int problemId){ -// -// // severity can have been preset on the problem -//// if ((problem.severity & Fatal) != 0){ -//// return Error; -//// } -// -// // if not then check whether it is a configurable problem -// int errorThreshold = options.errorThreshold; -// int warningThreshold = options.warningThreshold; -// -// switch(problemId){ -// -// case IProblem.UnreachableCatch : -// case IProblem.CodeCannotBeReached : -// if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.MaskedCatch : -// if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){ -// return Warning; -// } -// return Ignore; -// -///* -// case Never Used : -// if ((errorThreshold & ParsingOptionalError) != 0){ -// return Error; -// } -// if ((warningThreshold & ParsingOptionalError) != 0){ -// return Warning; -// } -// return Ignore; -//*/ -// case IProblem.ImportNotFound : -// case IProblem.ImportNotVisible : -// case IProblem.ImportAmbiguous : -// case IProblem.ImportInternalNameProvided : -// case IProblem.ImportInheritedNameHidesEnclosingName : -// case IProblem.DuplicateImport : -// case IProblem.ConflictingImport : -// case IProblem.CannotImportPackage : -// if ((errorThreshold & CompilerOptions.ImportProblem) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.ImportProblem) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.UnusedImport : -// // if import problem are disabled, then ignore -// if ((errorThreshold & CompilerOptions.ImportProblem) == 0 -// && (warningThreshold & CompilerOptions.ImportProblem) == 0){ -// return Ignore; -// } -// if ((errorThreshold & CompilerOptions.UnusedImport) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UnusedImport) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.MethodButWithConstructorName : -// if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.OverridingNonVisibleMethod : -// if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod : -// case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod : -// if ((errorThreshold & CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.OverridingDeprecatedMethod : -// case IProblem.UsingDeprecatedType : -// case IProblem.UsingDeprecatedMethod : -// case IProblem.UsingDeprecatedConstructor : -// case IProblem.UsingDeprecatedField : -// if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.LocalVariableIsNeverUsed : -// if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.ArgumentIsNeverUsed : -// if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.NoImplicitStringConversionForCharArrayExpression : -// if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.NeedToEmulateFieldReadAccess : -// case IProblem.NeedToEmulateFieldWriteAccess : -// case IProblem.NeedToEmulateMethodAccess : -// case IProblem.NeedToEmulateConstructorAccess : -// if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){ -// return Warning; -// } -// return Ignore; -// case IProblem.NonExternalizedStringLiteral : -// if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){ -// return Warning; -// } -// return Ignore; -// case IProblem.UseAssertAsAnIdentifier : -// if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ -// return Warning; -// } -// return Ignore; -// case IProblem.NonStaticAccessToStaticMethod : -// case IProblem.NonStaticAccessToStaticField : -// if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){ -// return Warning; -// } -// return Ignore; -// case IProblem.AssignmentHasNoEffect: -// if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){ -// return Warning; -// } -// return Ignore; -// case IProblem.UnusedPrivateConstructor: -// case IProblem.UnusedPrivateMethod: -// case IProblem.UnusedPrivateField: -// case IProblem.UnusedPrivateType: -// if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){ -// return Error; -// } -// if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){ -// return Warning; -// } -// return Ignore; -// -// case IProblem.Task : -// return Warning; -// default: -// return Error; -// } -//} -//public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) { -// this.handle( -// IProblem.IncompatibleTypesInConditionalOperator, -// new String[] {new String(trueType.readableName()), new String(falseType.readableName())}, -// new String[] {new String(trueType.sourceName()), new String(falseType.sourceName())}, -// expression.sourceStart, -// expression.sourceEnd); -//} -public void conflictingImport(ImportReference importRef) { - String[] arguments = new String[] {CharOperation.toString(importRef.tokens)}; - this.handle( - IProblem.ConflictingImport, - arguments, - arguments, - importRef.sourceStart, - importRef.sourceEnd); -} -public void constantOutOfFormat(NumberLiteral lit) { - // the literal is not in a correct format - // this code is called on IntLiteral and LongLiteral - // example 000811 ...the 8 is uncorrect. - - if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) { - char[] source = lit.source(); - try { - final String Radix; - final int radix; - if ((source[1] == 'x') || (source[1] == 'X')) { - radix = 16; - Radix = "Hexa"; //$NON-NLS-1$ - } else { - radix = 8; - Radix = "Octal"; //$NON-NLS-1$ - } - //look for the first digit that is incorrect - int place = -1; - label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) { - if (Character.digit(source[i], radix) == -1) { - place = i; - break label; + public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) { + this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, + method.sourceStart, method.sourceEnd, method, method + .compilationResult()); + } + public void alreadyDefinedLabel(char[] labelName, AstNode location) { + String[] arguments = new String[]{new String(labelName)}; + this.handle(IProblem.DuplicateLabel, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void anonymousClassCannotExtendFinalClass(Expression expression, + TypeBinding type) { + this.handle(IProblem.AnonymousClassCannotExtendFinalClass, + new String[]{new String(type.readableName())}, + new String[]{new String(type.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void argumentTypeCannotBeVoid(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(arg.name)}; + this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(arg.name)}; + this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void argumentTypeProblem(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg, + TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ArgumentTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ArgumentTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ArgumentTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ArgumentTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), + arg.name(), new String(expectedType.readableName())}, + new String[]{new String(methodDecl.selector), arg.name(), + new String(expectedType.shortReadableName())}, + arg.type.sourceStart, arg.type.sourceEnd); + } + public void arrayConstantsOnlyInArrayInitializers(int sourceStart, + int sourceEnd) { + this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, + NoArgument, sourceStart, sourceEnd); + } + public void assignmentHasNoEffect(Assignment assignment, char[] name) { + String[] arguments = new String[]{new String(name)}; + this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, + assignment.sourceStart, assignment.sourceEnd); + } + public void attemptToReturnNonVoidExpression( + ReturnStatement returnStatement, TypeBinding expectedType) { + this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String( + expectedType.readableName())}, new String[]{new String( + expectedType.shortReadableName())}, + returnStatement.sourceStart, returnStatement.sourceEnd); + } + public void attemptToReturnVoidValue(ReturnStatement returnStatement) { + this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, + returnStatement.sourceStart, returnStatement.sourceEnd); + } + //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) + // { + // String[] arguments = new String[] {new String(location.selector), + // parametersAsString(location.binding)}; + // if (location.isConstructor()) { + // this.handle( + // IProblem.BytecodeExceeds64KLimitForConstructor, + // arguments, + // arguments, + // Error | Abort, + // location.sourceStart, + // location.sourceEnd); + // } else { + // this.handle( + // IProblem.BytecodeExceeds64KLimit, + // arguments, + // arguments, + // Error | Abort, + // location.sourceStart, + // location.sourceEnd); + // } + //} + public void bytecodeExceeds64KLimit(TypeDeclaration location) { + this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, + NoArgument, Error | Abort, location.sourceStart, + location.sourceEnd); + } + public void cannotAllocateVoidArray(Expression expression) { + this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void cannotAssignToFinalField(FieldBinding field, AstNode location) { + this.handle(IProblem.FinalFieldAssignment, new String[]{ + (field.declaringClass == null ? "array" : new String( + field.declaringClass.readableName())), //$NON-NLS-1$ + new String(field.readableName())}, new String[]{ + (field.declaringClass == null ? "array" : new String( + field.declaringClass.shortReadableName())), //$NON-NLS-1$ + new String(field.shortReadableName())}, location.sourceStart, + location.sourceEnd); + } + public void cannotAssignToFinalLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, + arguments, location.sourceStart, location.sourceEnd); + } + public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void cannotDeclareLocalInterface(char[] interfaceName, + int sourceStart, int sourceEnd) { + String[] arguments = new String[]{new String(interfaceName)}; + this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, + arguments, sourceStart, sourceEnd); + } + public void cannotDefineDimensionsAndInitializer( + ArrayAllocationExpression expresssion) { + this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, + NoArgument, NoArgument, expresssion.sourceStart, + expresssion.sourceEnd); + } + public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, + MethodBinding method) { + this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + messageSend.sourceStart, messageSend.sourceEnd); + } + public void cannotImportPackage(ImportReference importRef) { + String[] arguments = new String[]{CharOperation + .toString(importRef.tokens)}; + this.handle(IProblem.CannotImportPackage, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void cannotInstantiate(TypeReference typeRef, TypeBinding type) { + this.handle(IProblem.InvalidClassInstantiation, + new String[]{new String(type.readableName())}, + new String[]{new String(type.shortReadableName())}, + typeRef.sourceStart, typeRef.sourceEnd); + } + public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void cannotReturnInInitializer(AstNode location) { + this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void cannotThrowNull(ThrowStatement statement) { + this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void cannotThrowType(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, TypeReference exceptionType, + TypeBinding expectedType) { + this.handle(IProblem.CannotThrowType, new String[]{new String( + expectedType.readableName())}, new String[]{new String( + expectedType.shortReadableName())}, exceptionType.sourceStart, + exceptionType.sourceEnd); + } + public void cannotUseSuperInJavaLangObject(AstNode reference) { + this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, + reference.sourceStart, reference.sourceEnd); + } + public void cannotUseSuperInCodeSnippet(int start, int end) { + this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, + NoArgument, Error | Abort, start, end); + } + public void caseExpressionMustBeConstant(Expression expression) { + this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void classExtendFinalClass(SourceTypeBinding type, + TypeReference superclass, TypeBinding expectedType) { + String name = new String(type.sourceName()); + String expectedFullName = new String(expectedType.readableName()); + String expectedShortName = new String(expectedType.shortReadableName()); + if (expectedShortName.equals(name)) + expectedShortName = expectedFullName; + this.handle(IProblem.ClassExtendFinalClass, new String[]{ + expectedFullName, name}, new String[]{expectedShortName, name}, + superclass.sourceStart, superclass.sourceEnd); + } + public void codeSnippetMissingClass(String missing, int start, int end) { + String[] arguments = new String[]{missing}; + this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, + Error | Abort, start, end); + } + public void codeSnippetMissingMethod(String className, + String missingMethod, String argumentTypes, int start, int end) { + String[] arguments = new String[]{className, missingMethod, + argumentTypes}; + this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, + Error | Abort, start, end); + } + /* + * Given the current configuration, answers which category the problem + * falls into: Error | Warning | Ignore + */ + //public int computeSeverity(int problemId){ + // + // // severity can have been preset on the problem + //// if ((problem.severity & Fatal) != 0){ + //// return Error; + //// } + // + // // if not then check whether it is a configurable problem + // int errorThreshold = options.errorThreshold; + // int warningThreshold = options.warningThreshold; + // + // switch(problemId){ + // + // case IProblem.UnreachableCatch : + // case IProblem.CodeCannotBeReached : + // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.MaskedCatch : + // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){ + // return Warning; + // } + // return Ignore; + // + ///* + // case Never Used : + // if ((errorThreshold & ParsingOptionalError) != 0){ + // return Error; + // } + // if ((warningThreshold & ParsingOptionalError) != 0){ + // return Warning; + // } + // return Ignore; + //*/ + // case IProblem.ImportNotFound : + // case IProblem.ImportNotVisible : + // case IProblem.ImportAmbiguous : + // case IProblem.ImportInternalNameProvided : + // case IProblem.ImportInheritedNameHidesEnclosingName : + // case IProblem.DuplicateImport : + // case IProblem.ConflictingImport : + // case IProblem.CannotImportPackage : + // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.UnusedImport : + // // if import problem are disabled, then ignore + // if ((errorThreshold & CompilerOptions.ImportProblem) == 0 + // && (warningThreshold & CompilerOptions.ImportProblem) == 0){ + // return Ignore; + // } + // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.MethodButWithConstructorName : + // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != + // 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.OverridingNonVisibleMethod : + // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != + // 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) + // != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod : + // case + // IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod + // : + // if ((errorThreshold & + // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ + // return Error; + // } + // if ((warningThreshold & + // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.OverridingDeprecatedMethod : + // case IProblem.UsingDeprecatedType : + // case IProblem.UsingDeprecatedMethod : + // case IProblem.UsingDeprecatedConstructor : + // case IProblem.UsingDeprecatedField : + // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.LocalVariableIsNeverUsed : + // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.ArgumentIsNeverUsed : + // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.NoImplicitStringConversionForCharArrayExpression : + // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != + // 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.NeedToEmulateFieldReadAccess : + // case IProblem.NeedToEmulateFieldWriteAccess : + // case IProblem.NeedToEmulateMethodAccess : + // case IProblem.NeedToEmulateConstructorAccess : + // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.NonExternalizedStringLiteral : + // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.UseAssertAsAnIdentifier : + // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.NonStaticAccessToStaticMethod : + // case IProblem.NonStaticAccessToStaticField : + // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.AssignmentHasNoEffect: + // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.UnusedPrivateConstructor: + // case IProblem.UnusedPrivateMethod: + // case IProblem.UnusedPrivateField: + // case IProblem.UnusedPrivateType: + // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.Task : + // return Warning; + // default: + // return Error; + // } + //} + //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression + // expression, TypeBinding trueType, TypeBinding falseType) { + // this.handle( + // IProblem.IncompatibleTypesInConditionalOperator, + // new String[] {new String(trueType.readableName()), new + // String(falseType.readableName())}, + // new String[] {new String(trueType.sourceName()), new + // String(falseType.sourceName())}, + // expression.sourceStart, + // expression.sourceEnd); + //} + public void conflictingImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation + .toString(importRef.tokens)}; + this.handle(IProblem.ConflictingImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void constantOutOfFormat(NumberLiteral lit) { + // the literal is not in a correct format + // this code is called on IntLiteral and LongLiteral + // example 000811 ...the 8 is uncorrect. + if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) { + char[] source = lit.source(); + try { + final String Radix; + final int radix; + if ((source[1] == 'x') || (source[1] == 'X')) { + radix = 16; + Radix = "Hexa"; //$NON-NLS-1$ + } else { + radix = 8; + Radix = "Octal"; //$NON-NLS-1$ } + //look for the first digit that is incorrect + int place = -1; + label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) { + if (Character.digit(source[i], radix) == -1) { + place = i; + break label; + } + } + String[] arguments = new String[]{Radix + " " + + new String(source) + " (digit " + + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + this.handle(IProblem.NumericValueOutOfRange, arguments, + arguments, lit.sourceStart, lit.sourceEnd); + return; + } catch (IndexOutOfBoundsException ex) { } - String[] arguments = new String[] {Radix + " " + new String(source) + " (digit " + new String(new char[] {source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - this.handle( - IProblem.NumericValueOutOfRange, - arguments, - arguments, - lit.sourceStart, - lit.sourceEnd); - return; - } catch (IndexOutOfBoundsException ex) {} - - // just in case .... use a predefined error.. - // we should never come here...(except if the code changes !) - this.constantOutOfRange(lit); + // just in case .... use a predefined error.. + // we should never come here...(except if the code changes !) + this.constantOutOfRange(lit); + } } -} -public void constantOutOfRange(Literal lit) { - // lit is some how out of range of it declared type - // example 9999999999999999999999999999999999999999999999999999999999999999999 - String[] arguments = new String[] {new String(lit.source())}; - this.handle( - IProblem.NumericValueOutOfRange, - arguments, - arguments, - lit.sourceStart, - lit.sourceEnd); -} -public void deprecatedField(FieldBinding field, AstNode location) { - this.handle( - IProblem.UsingDeprecatedField, - new String[] {new String(field.declaringClass.readableName()), new String(field.name)}, - new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)}, - location.sourceStart, - location.sourceEnd); -} -public void deprecatedMethod(MethodBinding method, AstNode location) { - if (method.isConstructor()) - this.handle( - IProblem.UsingDeprecatedConstructor, - new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)}, - new String[] {new String(method.declaringClass.shortReadableName()), parametersAsShortString(method)}, - location.sourceStart, - location.sourceEnd); - else - this.handle( - IProblem.UsingDeprecatedMethod, - new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)}, - new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)}, - location.sourceStart, - location.sourceEnd); -} -public void deprecatedType(TypeBinding type, AstNode location) { - if (location == null) return; // 1G828DN - no type ref for synthetic arguments - this.handle( - IProblem.UsingDeprecatedType, - new String[] {new String(type.readableName())}, - new String[] {new String(type.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void duplicateCase(Case statement, Constant constant) { - String[] arguments = new String[] {String.valueOf(constant.intValue())}; - this.handle( - IProblem.DuplicateCase, - arguments, - arguments, - statement.sourceStart, - statement.sourceEnd); -} -public void duplicateDefaultCase(DefaultCase statement) { - this.handle( - IProblem.DuplicateDefaultCase, - NoArgument, - NoArgument, - statement.sourceStart, - statement.sourceEnd); -} -public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) { - this.handle( - IProblem.DuplicateField, - new String[] {new String(type.sourceName()), fieldDecl.name()}, - new String[] {new String(type.shortReadableName()), fieldDecl.name()}, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void duplicateImport(ImportReference importRef) { - String[] arguments = new String[] {CharOperation.toString(importRef.tokens)}; - this.handle( - IProblem.DuplicateImport, - arguments, - arguments, - importRef.sourceStart, - importRef.sourceEnd); -} -public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) { - String[] arguments = new String[]{ new String(field.readableName())}; - this.handle( - IProblem.DuplicateBlankFinalFieldInitialization, - arguments, - arguments, - reference.sourceStart, - reference.sourceEnd); -} -public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, AstNode location) { - String[] arguments = new String[] { new String(local.readableName())}; - this.handle( - IProblem.DuplicateFinalLocalInitialization, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(methodDecl.selector), new String(type.sourceName())}; - this.handle( - IProblem.DuplicateMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) { -/* to highlight modifiers use: - this.handle( - new Problem( - DuplicateModifierForField, - new String[] {fieldDecl.name()}, - fieldDecl.modifiers.sourceStart, - fieldDecl.modifiers.sourceEnd)); -*/ - String[] arguments = new String[] {fieldDecl.name()}; - this.handle( - IProblem.DuplicateModifierForField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - this.handle( - IProblem.DuplicateModifierForMethod, - new String[] {new String(type.sourceName()), new String(methodDecl.selector)}, - new String[] {new String(type.shortReadableName()), new String(methodDecl.selector)}, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void duplicateModifierForType(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.DuplicateModifierForType, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) { - String[] arguments = new String[] {localDecl.name()}; - this.handle( - complainForArgument - ? IProblem.DuplicateModifierForArgument - : IProblem.DuplicateModifierForVariable, - arguments, - arguments, - localDecl.sourceStart, - localDecl.sourceEnd); -} -public void duplicateNestedType(TypeDeclaration typeDecl) { - String[] arguments = new String[] {new String(typeDecl.name)}; - this.handle( - IProblem.DuplicateNestedType, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) { - this.handle( - IProblem.DuplicateSuperInterface, - new String[] { - new String(superType.readableName()), - new String(type.sourceName())}, - new String[] { - new String(superType.shortReadableName()), - new String(type.sourceName())}, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { - String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)}; - this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit - this.handle( - IProblem.DuplicateTypes, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd, - compUnitDecl.compilationResult); -} -public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) { - StringBuffer buffer = new StringBuffer(); - StringBuffer shortBuffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0){ - buffer.append(", "); //$NON-NLS-1$ - shortBuffer.append(", "); //$NON-NLS-1$ + public void constantOutOfRange(Literal lit) { + // lit is some how out of range of it declared type + // example + // 9999999999999999999999999999999999999999999999999999999999999999999 + String[] arguments = new String[]{new String(lit.source())}; + this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, + lit.sourceStart, lit.sourceEnd); + } + public void deprecatedField(FieldBinding field, AstNode location) { + this.handle(IProblem.UsingDeprecatedField, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, + location.sourceEnd); + } + public void deprecatedMethod(MethodBinding method, AstNode location) { + if (method.isConstructor()) + this.handle(IProblem.UsingDeprecatedConstructor, new String[]{ + new String(method.declaringClass.readableName()), + parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + parametersAsShortString(method)}, location.sourceStart, + location.sourceEnd); + else + this.handle(IProblem.UsingDeprecatedMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass + .shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + location.sourceStart, location.sourceEnd); + } + public void deprecatedType(TypeBinding type, AstNode location) { + if (location == null) + return; // 1G828DN - no type ref for synthetic arguments + this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type + .readableName())}, new String[]{new String(type + .shortReadableName())}, location.sourceStart, + location.sourceEnd); + } + public void duplicateCase(Case statement, Constant constant) { + String[] arguments = new String[]{String.valueOf(constant.intValue())}; + this.handle(IProblem.DuplicateCase, arguments, arguments, + statement.sourceStart, statement.sourceEnd); + } + public void duplicateDefaultCase(DefaultCase statement) { + this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void duplicateFieldInType(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + this.handle(IProblem.DuplicateField, new String[]{ + new String(type.sourceName()), fieldDecl.name()}, new String[]{ + new String(type.shortReadableName()), fieldDecl.name()}, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void duplicateImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation + .toString(importRef.tokens)}; + this.handle(IProblem.DuplicateImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void duplicateInitializationOfBlankFinalField(FieldBinding field, + Reference reference) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, + arguments, reference.sourceStart, reference.sourceEnd); + } + public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, + arguments, location.sourceStart, location.sourceEnd); + } + public void duplicateMethodInType(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(type.sourceName())}; + this.handle(IProblem.DuplicateMethod, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void duplicateModifierForField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + /* + * to highlight modifiers use: this.handle( new Problem( + * DuplicateModifierForField, new String[] {fieldDecl.name()}, + * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd)); + */ + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.DuplicateModifierForField, arguments, arguments, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void duplicateModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + this.handle(IProblem.DuplicateModifierForMethod, + new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}, new String[]{ + new String(type.shortReadableName()), + new String(methodDecl.selector)}, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void duplicateModifierForType(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.DuplicateModifierForType, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void duplicateModifierForVariable(LocalDeclaration localDecl, + boolean complainForArgument) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(complainForArgument + ? IProblem.DuplicateModifierForArgument + : IProblem.DuplicateModifierForVariable, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void duplicateNestedType(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.DuplicateNestedType, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void duplicateSuperinterface(SourceTypeBinding type, + TypeDeclaration typeDecl, ReferenceBinding superType) { + this.handle(IProblem.DuplicateSuperInterface, new String[]{ + new String(superType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(superType.shortReadableName()), + new String(type.sourceName())}, typeDecl.sourceStart, + typeDecl.sourceEnd); + } + public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, + TypeDeclaration typeDecl) { + String[] arguments = new String[]{ + new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + this.handle(IProblem.DuplicateTypes, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, + TypeBinding[] params) { + StringBuffer buffer = new StringBuffer(); + StringBuffer shortBuffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) { + buffer.append(", "); //$NON-NLS-1$ + shortBuffer.append(", "); //$NON-NLS-1$ + } + buffer.append(new String(params[i].readableName())); + shortBuffer.append(new String(params[i].shortReadableName())); } - buffer.append(new String(params[i].readableName())); - shortBuffer.append(new String(params[i].shortReadableName())); - } - - this.handle( - recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType, - new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()}, - new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()}, - messageSend.sourceStart, - messageSend.sourceEnd); -} -public void errorThisSuperInStatic(AstNode reference) { - String[] arguments = new String[] {reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$ - this.handle( - IProblem.ThisInStaticContext, - arguments, - arguments, - reference.sourceStart, - reference.sourceEnd); -} -public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.ExceptionTypeNotFound; - break; - case NotVisible : // 2 - id = IProblem.ExceptionTypeNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.ExceptionTypeAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.ExceptionTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + this.handle(recType.isArrayType() + ? IProblem.NoMessageSendOnArrayType + : IProblem.NoMessageSendOnBaseType, new String[]{ + new String(recType.readableName()), + new String(messageSend.selector), buffer.toString()}, + new String[]{new String(recType.shortReadableName()), + new String(messageSend.selector), + shortBuffer.toString()}, messageSend.sourceStart, + messageSend.sourceEnd); } - this.handle( - id, - new String[] {new String(methodDecl.selector), new String(expectedType.readableName())}, - new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())}, - exceptionType.sourceStart, - exceptionType.sourceEnd); -} -public void expressionShouldBeAVariable(Expression expression) { - this.handle( - IProblem.ExpressionShouldBeAVariable, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) { - this.handle( - IProblem.ThisSuperDuringConstructorInvocation, - NoArgument, - NoArgument, - reference.sourceStart, - reference.sourceEnd); -} -public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.FieldTypeNotFound; - break; - case NotVisible : // 2 - id = IProblem.FieldTypeNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.FieldTypeAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.FieldTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.FieldTypeInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + public void errorThisSuperInStatic(AstNode reference) { + String[] arguments = new String[]{reference.isSuper() + ? "super" + : "this"}; //$NON-NLS-2$ //$NON-NLS-1$ + this.handle(IProblem.ThisInStaticContext, arguments, arguments, + reference.sourceStart, reference.sourceEnd); } - this.handle( - id, - new String[] {fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName())}, - new String[] {fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName())}, - fieldDecl.type.sourceStart, - fieldDecl.type.sourceEnd); -} -public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) { - this.handle( - // Cannot override the final method from %1 - // 8.4.3.3 - Final methods cannot be overridden or hidden. - IProblem.FinalMethodCannotBeOverridden, - new String[] {new String(inheritedMethod.declaringClass.readableName())}, - new String[] {new String(inheritedMethod.declaringClass.shortReadableName())}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); -} -public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) { - this.handle( - IProblem.ReferenceToForwardField, - NoArgument, - NoArgument, - reference.sourceStart, - reference.sourceEnd); -} -// use this private API when the compilation unit result can be found through the -// reference context. Otherwise, use the other API taking a problem and a compilation result -// as arguments - -private void handle( - int problemId, - String[] problemArguments, - String[] messageArguments, - int problemStartPosition, - int problemEndPosition){ - - this.handle( - problemId, - problemArguments, - messageArguments, - problemStartPosition, - problemEndPosition, - referenceContext, - referenceContext == null ? null : referenceContext.compilationResult()); - referenceContext = null; -} -// use this private API when the compilation unit result can be found through the -// reference context. Otherwise, use the other API taking a problem and a compilation result -// as arguments - -private void handle( - int problemId, - String[] problemArguments, - String[] messageArguments, - int severity, - int problemStartPosition, - int problemEndPosition){ - - this.handle( - problemId, - problemArguments, - messageArguments, - severity, - problemStartPosition, - problemEndPosition, - referenceContext, - referenceContext == null ? null : referenceContext.compilationResult()); - referenceContext = null; -} -// use this private API when the compilation unit result cannot be found through the -// reference context. - -private void handle( - int problemId, - String[] problemArguments, - String[] messageArguments, - int problemStartPosition, - int problemEndPosition, - CompilationResult unitResult){ - - this.handle( - problemId, - problemArguments, - messageArguments, - problemStartPosition, - problemEndPosition, - referenceContext, - unitResult); - referenceContext = null; -} -public void hidingEnclosingType(TypeDeclaration typeDecl) { - String[] arguments = new String[] {new String(typeDecl.name)}; - this.handle( - IProblem.HidingEnclosingType, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) { - int start = 0; - int end = 0; - String typeName = ""; //$NON-NLS-1$ - String shortTypeName = ""; //$NON-NLS-1$ - - if (reference == null) { // can only happen when java.lang.Object is busted - start = sourceType.sourceStart(); - end = sourceType.sourceEnd(); - typeName = new String(superType.readableName()); - shortTypeName = new String(superType.sourceName()); - } else { - start = reference.sourceStart; - end = reference.sourceEnd; - char[][] qName = reference.getTypeName(); - typeName = CharOperation.toString(qName); - shortTypeName = new String(qName[qName.length-1]); - } - - if (sourceType == superType) - this.handle( - IProblem.HierarchyCircularitySelfReference, - new String[] {new String(sourceType.sourceName()), typeName}, - new String[] {new String(sourceType.sourceName()), shortTypeName}, - start, - end); - else - this.handle( - IProblem.HierarchyCircularity, - new String[] {new String(sourceType.sourceName()), typeName}, - new String[] {new String(sourceType.sourceName()), shortTypeName}, - start, - end); -} -public void hierarchyHasProblems(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.HierarchyHasProblems, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.IllegalAbstractModifierCombinationForMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierCombinationFinalAbstractForClass, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {fieldDecl.name()}; - - this.handle( - IProblem.IllegalModifierCombinationFinalVolatileForField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} - -public void illegalModifierForClass(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierForClass, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {fieldDecl.name()}; - this.handle( - IProblem.IllegalModifierForField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void illegalModifierForInterface(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierForInterface, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {fieldDecl.name()}; - this.handle( - IProblem.IllegalModifierForInterfaceField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.IllegalModifierForInterfaceMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void illegalModifierForLocalClass(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierForLocalClass, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierForMemberClass(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierForMemberClass, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierForMemberInterface(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalModifierForMemberInterface, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.IllegalModifierForMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) { - String[] arguments = new String[] {localDecl.name()}; - this.handle( - complainAsArgument - ? IProblem.IllegalModifierForArgument - : IProblem.IllegalModifierForVariable, - arguments, - arguments, - localDecl.sourceStart, - localDecl.sourceEnd); -} -public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, AstNode location) { - this.handle( - IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance, - new String[] {new String(enclosingType.readableName())}, - new String[] {new String(enclosingType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void illegalStaticModifierForMemberType(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalStaticModifierForMemberType, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {new String(fieldDecl.name())}; - this.handle( - IProblem.IllegalVisibilityModifierCombinationForField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalVisibilityModifierCombinationForMemberType, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.IllegalVisibilityModifierCombinationForMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) { - String[] arguments = new String[] {new String(type.sourceName())}; - this.handle( - IProblem.IllegalVisibilityModifierForInterfaceMemberType, - arguments, - arguments, - type.sourceStart(), - type.sourceEnd()); -} -public void illegalVoidExpression(AstNode location) { - this.handle( - IProblem.InvalidVoidExpression, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void importProblem(ImportReference importRef, Binding expectedImport) { - int problemId = expectedImport.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.ImportNotFound; - break; - case NotVisible : // 2 - id = IProblem.ImportNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.ImportAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.ImportInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.ImportInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + public void exceptionTypeProblem(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, TypeReference exceptionType, + TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ExceptionTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ExceptionTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ExceptionTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ExceptionTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), + new String(expectedType.readableName())}, new String[]{ + new String(methodDecl.selector), + new String(expectedType.shortReadableName())}, + exceptionType.sourceStart, exceptionType.sourceEnd); } - String argument; - if(expectedImport instanceof ProblemReferenceBinding) { - argument = CharOperation.toString(((ProblemReferenceBinding)expectedImport).compoundName); - } else { - argument = CharOperation.toString(importRef.tokens); + public void expressionShouldBeAVariable(Expression expression) { + this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, + NoArgument, expression.sourceStart, expression.sourceEnd); } - String[] arguments = new String[]{argument}; - this.handle(id, arguments, arguments, importRef.sourceStart, importRef.sourceEnd); -} -public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType) { - if (type == currentMethod.declaringClass) { + public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) { + this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, + NoArgument, reference.sourceStart, reference.sourceEnd); + } + public void fieldTypeProblem(SourceTypeBinding type, + FieldDeclaration fieldDecl, TypeBinding expectedType) { + int problemId = expectedType.problemId(); int id; - if (currentMethod.declaringClass.isInterface() - && !inheritedMethod.isPublic()){ // interface inheriting Object protected method - id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod; - } else { - id = IProblem.IncompatibleExceptionInThrowsClause; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.FieldTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.FieldTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.FieldTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.FieldTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.FieldTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; } + this.handle(id, new String[]{fieldDecl.name(), + new String(type.sourceName()), + new String(expectedType.readableName())}, new String[]{ + fieldDecl.name(), new String(type.sourceName()), + new String(expectedType.shortReadableName())}, + fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd); + } + public void finalMethodCannotBeOverridden(MethodBinding currentMethod, + MethodBinding inheritedMethod) { this.handle( - // Exception %1 is not compatible with throws clause in %2 - // 9.4.4 - The type of exception in the throws clause is incompatible. - id, - new String[] { - new String(exceptionType.sourceName()), - new String( - CharOperation.concat( - inheritedMethod.declaringClass.readableName(), - inheritedMethod.readableName(), - '.'))}, - new String[] { - new String(exceptionType.sourceName()), - new String( - CharOperation.concat( - inheritedMethod.declaringClass.shortReadableName(), - inheritedMethod.shortReadableName(), - '.'))}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); - } else - this.handle( - // Exception %1 in throws clause of %2 is not compatible with %3 - // 9.4.4 - The type of exception in the throws clause is incompatible. - IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, - new String[] { - new String(exceptionType.sourceName()), - new String( - CharOperation.concat( - currentMethod.declaringClass.sourceName(), - currentMethod.readableName(), - '.')), - new String( - CharOperation.concat( - inheritedMethod.declaringClass.readableName(), - inheritedMethod.readableName(), - '.'))}, - new String[] { - new String(exceptionType.sourceName()), - new String( - CharOperation.concat( - currentMethod.declaringClass.sourceName(), - currentMethod.shortReadableName(), - '.')), - new String( - CharOperation.concat( - inheritedMethod.declaringClass.shortReadableName(), - inheritedMethod.shortReadableName(), - '.'))}, - type.sourceStart(), - type.sourceEnd()); -} -public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) { - StringBuffer methodSignature = new StringBuffer(); - methodSignature - .append(inheritedMethod.declaringClass.readableName()) - .append('.') - .append(inheritedMethod.readableName()); - - StringBuffer shortSignature = new StringBuffer(); - shortSignature - .append(inheritedMethod.declaringClass.shortReadableName()) - .append('.') - .append(inheritedMethod.shortReadableName()); - - int id; - if (currentMethod.declaringClass.isInterface() - && !inheritedMethod.isPublic()){ // interface inheriting Object protected method - id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod; - } else { - id = IProblem.IncompatibleReturnType; - } - this.handle( - id, - new String[] {methodSignature.toString()}, - new String[] {shortSignature.toString()}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); -} -public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) { - this.handle( - IProblem.IllegalDimension, - NoArgument, - NoArgument, - expression.dimensions[index + 1].sourceStart, - expression.dimensions[index + 1].sourceEnd); -} -public void incorrectSwitchType(Expression expression, TypeBinding testType) { - this.handle( - IProblem.IncorrectSwitchType, - new String[] {new String(testType.readableName())}, - new String[] {new String(testType.shortReadableName())}, - expression.sourceStart, - expression.sourceEnd); -} -public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) { - StringBuffer concreteSignature = new StringBuffer(); - concreteSignature - .append(concreteMethod.declaringClass.readableName()) - .append('.') - .append(concreteMethod.readableName()); - StringBuffer shortSignature = new StringBuffer(); - shortSignature - .append(concreteMethod.declaringClass.shortReadableName()) - .append('.') - .append(concreteMethod.shortReadableName()); - this.handle( - // The inherited method %1 cannot hide the public abstract method in %2 - IProblem.InheritedMethodReducesVisibility, - new String[] { - new String(concreteSignature.toString()), - new String(abstractMethods[0].declaringClass.readableName())}, - new String[] { - new String(shortSignature.toString()), - new String(abstractMethods[0].declaringClass.shortReadableName())}, - type.sourceStart(), - type.sourceEnd()); -} -public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) { - StringBuffer methodSignatures = new StringBuffer(); - StringBuffer shortSignatures = new StringBuffer(); - for (int i = length; --i >= 0;) { - methodSignatures - .append(inheritedMethods[i].declaringClass.readableName()) - .append('.') - .append(inheritedMethods[i].readableName()); - shortSignatures - .append(inheritedMethods[i].declaringClass.shortReadableName()) - .append('.') - .append(inheritedMethods[i].shortReadableName()); - if (i != 0){ - methodSignatures.append(", "); //$NON-NLS-1$ - shortSignatures.append(", "); //$NON-NLS-1$ + // Cannot override the final method from %1 + // 8.4.3.3 - Final methods cannot be overridden or hidden. + IProblem.FinalMethodCannotBeOverridden, + new String[]{new String(inheritedMethod.declaringClass + .readableName())}, new String[]{new String( + inheritedMethod.declaringClass.shortReadableName())}, + currentMethod.sourceStart(), currentMethod.sourceEnd()); + } + public void forwardReference(Reference reference, int indexInQualification, + TypeBinding type) { + this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, + reference.sourceStart, reference.sourceEnd); + } + // use this private API when the compilation unit result can be found + // through the + // reference context. Otherwise, use the other API taking a problem and a + // compilation result + // as arguments + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int problemStartPosition, + int problemEndPosition) { + this.handle(problemId, problemArguments, messageArguments, + problemStartPosition, problemEndPosition, referenceContext, + referenceContext == null ? null : referenceContext + .compilationResult()); + referenceContext = null; + } + // use this private API when the compilation unit result can be found + // through the + // reference context. Otherwise, use the other API taking a problem and a + // compilation result + // as arguments + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int severity, int problemStartPosition, + int problemEndPosition) { + this.handle(problemId, problemArguments, messageArguments, severity, + problemStartPosition, problemEndPosition, referenceContext, + referenceContext == null ? null : referenceContext + .compilationResult()); + referenceContext = null; + } + // use this private API when the compilation unit result cannot be found + // through the + // reference context. + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int problemStartPosition, + int problemEndPosition, CompilationResult unitResult) { + this.handle(problemId, problemArguments, messageArguments, + problemStartPosition, problemEndPosition, referenceContext, + unitResult); + referenceContext = null; + } + public void hidingEnclosingType(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.HidingEnclosingType, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void hierarchyCircularity(SourceTypeBinding sourceType, + ReferenceBinding superType, TypeReference reference) { + int start = 0; + int end = 0; + String typeName = ""; //$NON-NLS-1$ + String shortTypeName = ""; //$NON-NLS-1$ + if (reference == null) { // can only happen when java.lang.Object is + // busted + start = sourceType.sourceStart(); + end = sourceType.sourceEnd(); + typeName = new String(superType.readableName()); + shortTypeName = new String(superType.sourceName()); + } else { + start = reference.sourceStart; + end = reference.sourceEnd; + char[][] qName = reference.getTypeName(); + typeName = CharOperation.toString(qName); + shortTypeName = new String(qName[qName.length - 1]); } + if (sourceType == superType) + this + .handle(IProblem.HierarchyCircularitySelfReference, + new String[]{new String(sourceType.sourceName()), + typeName}, new String[]{ + new String(sourceType.sourceName()), + shortTypeName}, start, end); + else + this.handle(IProblem.HierarchyCircularity, new String[]{ + new String(sourceType.sourceName()), typeName}, + new String[]{new String(sourceType.sourceName()), + shortTypeName}, start, end); } - - this.handle( - // Return type is incompatible with %1 - // 9.4.2 - The return type from the method is incompatible with the declaration. - IProblem.IncompatibleReturnType, - new String[] {methodSignatures.toString()}, - new String[] {shortSignatures.toString()}, - type.sourceStart(), - type.sourceEnd()); -} -public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) { - this.handle( - IProblem.InitializerMustCompleteNormally, - NoArgument, - NoArgument, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, AstNode location) { - this.handle( - IProblem.CannotDefineStaticInitializerInLocalType, - new String[] {new String(innerType.readableName())}, - new String[] {new String(innerType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) { - this.handle( - IProblem.InterfaceCannotHaveConstructors, - NoArgument, - NoArgument, - constructor.sourceStart, - constructor.sourceEnd, - constructor, - constructor.compilationResult()); -} -public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {new String(type.sourceName())}; - - this.handle( - IProblem.InterfaceCannotHaveInitializers, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void invalidBreak(AstNode location) { - this.handle( - IProblem.InvalidBreak, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void invalidConstructor(Statement statement, MethodBinding targetConstructor) { - - boolean insideDefaultConstructor = - (referenceContext instanceof ConstructorDeclaration) - && ((ConstructorDeclaration)referenceContext).isDefaultConstructor(); - boolean insideImplicitConstructorCall = - (statement instanceof ExplicitConstructorCall) - && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper); - - int flag = IProblem.UndefinedConstructor; //default... - switch (targetConstructor.problemId()) { - case NotFound : - if (insideDefaultConstructor){ - flag = IProblem.UndefinedConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall){ - flag = IProblem.UndefinedConstructorInImplicitConstructorCall; - } else { - flag = IProblem.UndefinedConstructor; - } - break; - case NotVisible : - if (insideDefaultConstructor){ - flag = IProblem.NotVisibleConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall){ - flag = IProblem.NotVisibleConstructorInImplicitConstructorCall; + public void hierarchyHasProblems(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type + .sourceStart(), type.sourceEnd()); + } + public void illegalAbstractModifierCombinationForMethod( + ReferenceBinding type, AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, + arguments, arguments, methodDecl.sourceStart, + methodDecl.sourceEnd); + } + public void illegalModifierCombinationFinalAbstractForClass( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierCombinationFinalVolatileForField( + ReferenceBinding type, FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, + arguments, arguments, fieldDecl.sourceStart, + fieldDecl.sourceEnd); + } + public void illegalModifierForClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForClass, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierForField, arguments, arguments, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalModifierForInterface(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForInterfaceField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierForInterfaceField, arguments, + arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalModifierForInterfaceMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalModifierForLocalClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForLocalClass, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMemberClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForMemberClass, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMemberInterface(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForMemberInterface, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalModifierForVariable(LocalDeclaration localDecl, + boolean complainAsArgument) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(complainAsArgument + ? IProblem.IllegalModifierForArgument + : IProblem.IllegalModifierForVariable, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void illegalPrimitiveOrArrayTypeForEnclosingInstance( + TypeBinding enclosingType, AstNode location) { + this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance, + new String[]{new String(enclosingType.readableName())}, + new String[]{new String(enclosingType.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void illegalStaticModifierForMemberType(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVisibilityModifierCombinationForField( + ReferenceBinding type, FieldDeclaration fieldDecl) { + String[] arguments = new String[]{new String(fieldDecl.name())}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForField, + arguments, arguments, fieldDecl.sourceStart, + fieldDecl.sourceEnd); + } + public void illegalVisibilityModifierCombinationForMemberType( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVisibilityModifierCombinationForMethod( + ReferenceBinding type, AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, + arguments, arguments, methodDecl.sourceStart, + methodDecl.sourceEnd); + } + public void illegalVisibilityModifierForInterfaceMemberType( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVoidExpression(AstNode location) { + this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void importProblem(ImportReference importRef, Binding expectedImport) { + int problemId = expectedImport.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ImportNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ImportNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ImportAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ImportInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ImportInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + String argument; + if (expectedImport instanceof ProblemReferenceBinding) { + argument = CharOperation + .toString(((ProblemReferenceBinding) expectedImport).compoundName); + } else { + argument = CharOperation.toString(importRef.tokens); + } + String[] arguments = new String[]{argument}; + this.handle(id, arguments, arguments, importRef.sourceStart, + importRef.sourceEnd); + } + public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, + MethodBinding currentMethod, MethodBinding inheritedMethod, + ReferenceBinding exceptionType) { + if (type == currentMethod.declaringClass) { + int id; + if (currentMethod.declaringClass.isInterface() + && !inheritedMethod.isPublic()) { // interface inheriting + // Object protected + // method + id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod; } else { - flag = IProblem.NotVisibleConstructor; + id = IProblem.IncompatibleExceptionInThrowsClause; } - break; - case Ambiguous : - if (insideDefaultConstructor){ - flag = IProblem.AmbiguousConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall){ - flag = IProblem.AmbiguousConstructorInImplicitConstructorCall; - } else { - flag = IProblem.AmbiguousConstructor; + this + .handle( + // Exception %1 is not compatible with throws + // clause in %2 + // 9.4.4 - The type of exception in the throws + // clause is incompatible. + id, + new String[]{ + new String(exceptionType.sourceName()), + new String( + CharOperation + .concat( + inheritedMethod.declaringClass + .readableName(), + inheritedMethod + .readableName(), + '.'))}, + new String[]{ + new String(exceptionType.sourceName()), + new String( + CharOperation + .concat( + inheritedMethod.declaringClass + .shortReadableName(), + inheritedMethod + .shortReadableName(), + '.'))}, + currentMethod.sourceStart(), currentMethod + .sourceEnd()); + } else + this + .handle( + // Exception %1 in throws clause of %2 is not + // compatible with %3 + // 9.4.4 - The type of exception in the throws + // clause is incompatible. + IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, + new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat( + currentMethod.declaringClass + .sourceName(), + currentMethod.readableName(), '.')), + new String( + CharOperation + .concat( + inheritedMethod.declaringClass + .readableName(), + inheritedMethod + .readableName(), + '.'))}, + new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat( + currentMethod.declaringClass + .sourceName(), + currentMethod.shortReadableName(), + '.')), + new String( + CharOperation + .concat( + inheritedMethod.declaringClass + .shortReadableName(), + inheritedMethod + .shortReadableName(), + '.'))}, type + .sourceStart(), type.sourceEnd()); + } + public void incompatibleReturnType(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + StringBuffer methodSignature = new StringBuffer(); + methodSignature.append(inheritedMethod.declaringClass.readableName()) + .append('.').append(inheritedMethod.readableName()); + StringBuffer shortSignature = new StringBuffer(); + shortSignature.append( + inheritedMethod.declaringClass.shortReadableName()).append('.') + .append(inheritedMethod.shortReadableName()); + int id; + if (currentMethod.declaringClass.isInterface() + && !inheritedMethod.isPublic()) { // interface inheriting + // Object protected method + id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod; + } else { + id = IProblem.IncompatibleReturnType; + } + this.handle(id, new String[]{methodSignature.toString()}, + new String[]{shortSignature.toString()}, currentMethod + .sourceStart(), currentMethod.sourceEnd()); + } + public void incorrectLocationForEmptyDimension( + ArrayAllocationExpression expression, int index) { + this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, + expression.dimensions[index + 1].sourceStart, + expression.dimensions[index + 1].sourceEnd); + } + public void incorrectSwitchType(Expression expression, TypeBinding testType) { + this.handle(IProblem.IncorrectSwitchType, new String[]{new String( + testType.readableName())}, new String[]{new String(testType + .shortReadableName())}, expression.sourceStart, + expression.sourceEnd); + } + public void inheritedMethodReducesVisibility(SourceTypeBinding type, + MethodBinding concreteMethod, MethodBinding[] abstractMethods) { + StringBuffer concreteSignature = new StringBuffer(); + concreteSignature.append(concreteMethod.declaringClass.readableName()) + .append('.').append(concreteMethod.readableName()); + StringBuffer shortSignature = new StringBuffer(); + shortSignature + .append(concreteMethod.declaringClass.shortReadableName()) + .append('.').append(concreteMethod.shortReadableName()); + this.handle( + // The inherited method %1 cannot hide the public abstract method in %2 + IProblem.InheritedMethodReducesVisibility, new String[]{ + new String(concreteSignature.toString()), + new String(abstractMethods[0].declaringClass + .readableName())}, new String[]{ + new String(shortSignature.toString()), + new String(abstractMethods[0].declaringClass + .shortReadableName())}, type.sourceStart(), + type.sourceEnd()); + } + public void inheritedMethodsHaveIncompatibleReturnTypes( + SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) { + StringBuffer methodSignatures = new StringBuffer(); + StringBuffer shortSignatures = new StringBuffer(); + for (int i = length; --i >= 0;) { + methodSignatures.append( + inheritedMethods[i].declaringClass.readableName()).append( + '.').append(inheritedMethods[i].readableName()); + shortSignatures.append( + inheritedMethods[i].declaringClass.shortReadableName()) + .append('.') + .append(inheritedMethods[i].shortReadableName()); + if (i != 0) { + methodSignatures.append(", "); //$NON-NLS-1$ + shortSignatures.append(", "); //$NON-NLS-1$ } - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - - - this.handle( - flag, - new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)}, - new String[] {new String(targetConstructor.declaringClass.shortReadableName()), parametersAsShortString(targetConstructor)}, - statement.sourceStart, - statement.sourceEnd); -} -public void invalidContinue(AstNode location) { - this.handle( - IProblem.InvalidContinue, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) { - - if (enclosingType.isAnonymousType()) enclosingType = enclosingType.superclass(); - int flag = IProblem.UndefinedType; // default - switch (type.problemId()) { - case NotFound : // 1 - flag = IProblem.UndefinedType; - break; - case NotVisible : // 2 - flag = IProblem.NotVisibleType; - break; - case Ambiguous : // 3 - flag = IProblem.AmbiguousType; - break; - case InternalNameProvided : - flag = IProblem.InternalTypeNameProvided; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - - this.handle( - flag, - new String[] {new String(enclosingType.readableName()) + "." + new String(type.readableName())}, //$NON-NLS-1$ - new String[] {new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName())}, //$NON-NLS-1$ - expression.sourceStart, - expression.sourceEnd); -} -public void invalidExpressionAsStatement(Expression expression){ - this.handle( - IProblem.InvalidExpressionAsStatement, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void invalidField(FieldReference fieldRef, TypeBinding searchedType) { - int severity = Error; - int flag = IProblem.UndefinedField; - FieldBinding field = fieldRef.binding; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; -/* also need to check that the searchedType is the receiver type - if (searchedType.isHierarchyInconsistent()) - severity = SecondaryError; -*/ - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle( - IProblem.NotVisibleType, - new String[] {new String(searchedType.leafComponentType().readableName())}, - new String[] {new String(searchedType.leafComponentType().shortReadableName())}, - fieldRef.receiver.sourceStart, - fieldRef.receiver.sourceEnd); - return; - - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - - String[] arguments = new String[] {new String(field.readableName())}; - this.handle( - flag, - arguments, - arguments, - severity, - fieldRef.sourceStart, - fieldRef.sourceEnd); -} -public void invalidField(NameReference nameRef, FieldBinding field) { - int flag = IProblem.UndefinedField; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle( - IProblem.NotVisibleType, - new String[] {new String(field.declaringClass.leafComponentType().readableName())}, - new String[] {new String(field.declaringClass.leafComponentType().shortReadableName())}, - nameRef.sourceStart, - nameRef.sourceEnd); - return; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - String[] arguments = new String[] {new String(field.readableName())}; - this.handle( - flag, - arguments, - arguments, - nameRef.sourceStart, - nameRef.sourceEnd); -} -public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) { - //the resolution of the index-th field of qname failed - //qname.otherBindings[index] is the binding that has produced the error - - //The different targetted errors should be : - //UndefinedField - //NotVisibleField - //AmbiguousField - - if (searchedType.isBaseType()) { + } this.handle( - IProblem.NoFieldOnBaseType, - new String[] { - new String(searchedType.readableName()), - CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), - new String(nameRef.tokens[index])}, - new String[] { - new String(searchedType.sourceName()), - CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), - new String(nameRef.tokens[index])}, - nameRef.sourceStart, - nameRef.sourceEnd); - return; - } - - int flag = IProblem.UndefinedField; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; -/* also need to check that the searchedType is the receiver type - if (searchedType.isHierarchyInconsistent()) - severity = SecondaryError; -*/ - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle( - IProblem.NotVisibleType, - new String[] {new String(searchedType.leafComponentType().readableName())}, - new String[] {new String(searchedType.leafComponentType().shortReadableName())}, - nameRef.sourceStart, + // Return type is incompatible with %1 + // 9.4.2 - The return type from the method is incompatible with + // the declaration. + IProblem.IncompatibleReturnType, new String[]{methodSignatures + .toString()}, new String[]{shortSignatures.toString()}, + type.sourceStart(), type.sourceEnd()); + } + public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) { + this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, + NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void innerTypesCannotDeclareStaticInitializers( + ReferenceBinding innerType, AstNode location) { + this.handle(IProblem.CannotDefineStaticInitializerInLocalType, + new String[]{new String(innerType.readableName())}, + new String[]{new String(innerType.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void interfaceCannotHaveConstructors( + ConstructorDeclaration constructor) { + this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, + NoArgument, constructor.sourceStart, constructor.sourceEnd, + constructor, constructor.compilationResult()); + } + public void interfaceCannotHaveInitializers(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, + arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void invalidBreak(AstNode location) { + this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void invalidConstructor(Statement statement, + MethodBinding targetConstructor) { + boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) + && ((ConstructorDeclaration) referenceContext) + .isDefaultConstructor(); + boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall) + && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper); + int flag = IProblem.UndefinedConstructor; //default... + switch (targetConstructor.problemId()) { + case NotFound : + if (insideDefaultConstructor) { + flag = IProblem.UndefinedConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.UndefinedConstructorInImplicitConstructorCall; + } else { + flag = IProblem.UndefinedConstructor; + } + break; + case NotVisible : + if (insideDefaultConstructor) { + flag = IProblem.NotVisibleConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.NotVisibleConstructorInImplicitConstructorCall; + } else { + flag = IProblem.NotVisibleConstructor; + } + break; + case Ambiguous : + if (insideDefaultConstructor) { + flag = IProblem.AmbiguousConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.AmbiguousConstructorInImplicitConstructorCall; + } else { + flag = IProblem.AmbiguousConstructor; + } + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{ + new String(targetConstructor.declaringClass.readableName()), + parametersAsString(targetConstructor)}, + new String[]{ + new String(targetConstructor.declaringClass + .shortReadableName()), + parametersAsShortString(targetConstructor)}, + statement.sourceStart, statement.sourceEnd); + } + public void invalidContinue(AstNode location) { + this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void invalidEnclosingType(Expression expression, TypeBinding type, + ReferenceBinding enclosingType) { + if (enclosingType.isAnonymousType()) + enclosingType = enclosingType.superclass(); + int flag = IProblem.UndefinedType; // default + switch (type.problemId()) { + case NotFound : + // 1 + flag = IProblem.UndefinedType; + break; + case NotVisible : + // 2 + flag = IProblem.NotVisibleType; + break; + case Ambiguous : + // 3 + flag = IProblem.AmbiguousType; + break; + case InternalNameProvided : + flag = IProblem.InternalTypeNameProvided; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{new String(enclosingType.readableName()) + + "." + new String(type.readableName())}, //$NON-NLS-1$ + new String[]{new String(enclosingType.shortReadableName()) + + "." + new String(type.shortReadableName())}, //$NON-NLS-1$ + expression.sourceStart, expression.sourceEnd); + } + public void invalidExpressionAsStatement(Expression expression) { + this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, + NoArgument, expression.sourceStart, expression.sourceEnd); + } + public void invalidField(FieldReference fieldRef, TypeBinding searchedType) { + int severity = Error; + int flag = IProblem.UndefinedField; + FieldBinding field = fieldRef.binding; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + /* + * also need to check that the searchedType is the receiver + * type if (searchedType.isHierarchyInconsistent()) severity = + * SecondaryError; + */ + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + searchedType.leafComponentType().readableName())}, + new String[]{new String(searchedType + .leafComponentType().shortReadableName())}, + fieldRef.receiver.sourceStart, + fieldRef.receiver.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, + fieldRef.sourceEnd); + } + public void invalidField(NameReference nameRef, FieldBinding field) { + int flag = IProblem.UndefinedField; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, + new String[]{new String(field.declaringClass + .leafComponentType().readableName())}, + new String[]{new String(field.declaringClass + .leafComponentType().shortReadableName())}, + nameRef.sourceStart, nameRef.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd); + } + public void invalidField(QualifiedNameReference nameRef, + FieldBinding field, int index, TypeBinding searchedType) { + //the resolution of the index-th field of qname failed + //qname.otherBindings[index] is the binding that has produced the + // error + //The different targetted errors should be : + //UndefinedField + //NotVisibleField + //AmbiguousField + if (searchedType.isBaseType()) { + this.handle(IProblem.NoFieldOnBaseType, new String[]{ + new String(searchedType.readableName()), + CharOperation.toString(CharOperation.subarray( + nameRef.tokens, 0, index)), + new String(nameRef.tokens[index])}, new String[]{ + new String(searchedType.sourceName()), + CharOperation.toString(CharOperation.subarray( + nameRef.tokens, 0, index)), + new String(nameRef.tokens[index])}, nameRef.sourceStart, + nameRef.sourceEnd); return; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - String[] arguments = new String[] {CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1))}; - this.handle( - flag, - arguments, - arguments, - nameRef.sourceStart, - nameRef.sourceEnd); -} -public void invalidMethod(MessageSend messageSend, MethodBinding method) { - // CODE should be UPDATED according to error coding in the different method binding errors - // The different targetted errors should be : - // UndefinedMethod - // NotVisibleMethod - // AmbiguousMethod - // InheritedNameHidesEnclosingName - // InstanceMethodDuringConstructorInvocation - // StaticMethodRequested - - int flag = IProblem.UndefinedMethod; //default... - switch (method.problemId()) { - case NotFound : - flag = IProblem.UndefinedMethod; - break; - case NotVisible : - flag = IProblem.NotVisibleMethod; - break; - case Ambiguous : - flag = IProblem.AmbiguousMethod; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedMethodHidesEnclosingName; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceMethodDuringConstructorInvocation; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.StaticMethodRequested; - break; - case ReceiverTypeNotVisible : - this.handle( - IProblem.NotVisibleType, - new String[] {new String(method.declaringClass.leafComponentType().readableName())}, - new String[] {new String(method.declaringClass.leafComponentType().shortReadableName())}, - messageSend.receiver.sourceStart, - messageSend.receiver.sourceEnd); - return; - - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - - if (flag == IProblem.UndefinedMethod) { - ProblemMethodBinding problemMethod = (ProblemMethodBinding) method; - if (problemMethod.closestMatch != null) { + } + int flag = IProblem.UndefinedField; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + /* + * also need to check that the searchedType is the receiver + * type if (searchedType.isHierarchyInconsistent()) severity = + * SecondaryError; + */ + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + searchedType.leafComponentType().readableName())}, + new String[]{new String(searchedType + .leafComponentType().shortReadableName())}, + nameRef.sourceStart, nameRef.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{CharOperation.toString(CharOperation + .subarray(nameRef.tokens, 0, index + 1))}; + this.handle(flag, arguments, arguments, nameRef.sourceStart, + nameRef.sourceEnd); + } + public void invalidMethod(MessageSend messageSend, MethodBinding method) { + // CODE should be UPDATED according to error coding in the different + // method binding errors + // The different targetted errors should be : + // UndefinedMethod + // NotVisibleMethod + // AmbiguousMethod + // InheritedNameHidesEnclosingName + // InstanceMethodDuringConstructorInvocation + // StaticMethodRequested + int flag = IProblem.UndefinedMethod; //default... + switch (method.problemId()) { + case NotFound : + flag = IProblem.UndefinedMethod; + break; + case NotVisible : + flag = IProblem.NotVisibleMethod; + break; + case Ambiguous : + flag = IProblem.AmbiguousMethod; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedMethodHidesEnclosingName; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceMethodDuringConstructorInvocation; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.StaticMethodRequested; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + method.declaringClass.leafComponentType() + .readableName())}, new String[]{new String( + method.declaringClass.leafComponentType() + .shortReadableName())}, + messageSend.receiver.sourceStart, + messageSend.receiver.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + if (flag == IProblem.UndefinedMethod) { + ProblemMethodBinding problemMethod = (ProblemMethodBinding) method; + if (problemMethod.closestMatch != null) { String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch); String parameterTypeNames = parametersAsString(method); String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch); String parameterTypeShortNames = parametersAsShortString(method); - if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){ + if (closestParameterTypeShortNames + .equals(parameterTypeShortNames)) { closestParameterTypeShortNames = closestParameterTypeNames; parameterTypeShortNames = parameterTypeNames; } - this.handle( - IProblem.ParameterMismatch, - new String[] { - new String(problemMethod.closestMatch.declaringClass.readableName()), - new String(problemMethod.closestMatch.selector), - closestParameterTypeNames, - parameterTypeNames - }, - new String[] { - new String(problemMethod.closestMatch.declaringClass.shortReadableName()), - new String(problemMethod.closestMatch.selector), - closestParameterTypeShortNames, - parameterTypeShortNames - }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + this + .handle( + IProblem.ParameterMismatch, + new String[]{ + new String( + problemMethod.closestMatch.declaringClass + .readableName()), + new String( + problemMethod.closestMatch.selector), + closestParameterTypeNames, + parameterTypeNames}, + new String[]{ + new String( + problemMethod.closestMatch.declaringClass + .shortReadableName()), + new String( + problemMethod.closestMatch.selector), + closestParameterTypeShortNames, + parameterTypeShortNames}, + (int) (messageSend.nameSourcePosition >>> 32), + (int) messageSend.nameSourcePosition); return; + } } + this.handle(flag, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + (int) (messageSend.nameSourcePosition >>> 32), + (int) messageSend.nameSourcePosition); } - - this.handle( - flag, - new String[] { - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[] { - new String(method.declaringClass.shortReadableName()), - new String(method.selector), parametersAsShortString(method)}, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); -} -public void invalidNullToSynchronize(Expression expression) { - this.handle( - IProblem.InvalidNullToSynchronized, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.InvalidOperator, - new String[] { - expression.operatorToString(), - leftName + ", " + rightName}, //$NON-NLS-1$ - new String[] { - expression.operatorToString(), - leftShortName + ", " + rightShortName}, //$NON-NLS-1$ - expression.sourceStart, - expression.sourceEnd); -} -public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.InvalidOperator, - new String[] { - assign.operatorToString(), - leftName + ", " + rightName}, //$NON-NLS-1$ - new String[] { - assign.operatorToString(), - leftShortName + ", " + rightShortName}, //$NON-NLS-1$ - assign.sourceStart, - assign.sourceEnd); -} -public void invalidOperator(UnaryExpression expression, TypeBinding type) { - this.handle( - IProblem.InvalidOperator, - new String[] {expression.operatorToString(), new String(type.readableName())}, - new String[] {expression.operatorToString(), new String(type.shortReadableName())}, - expression.sourceStart, - expression.sourceEnd); -} -public void invalidParenthesizedExpression(AstNode reference) { - this.handle( - IProblem.InvalidParenthesizedExpression, - NoArgument, - NoArgument, - reference.sourceStart, - reference.sourceEnd); -} -public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.SuperclassNotFound; - break; - case NotVisible : // 2 - id = IProblem.SuperclassNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.SuperclassAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.SuperclassInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.SuperclassInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + public void invalidNullToSynchronize(Expression expression) { + this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); } - this.handle( - id, - new String[] {new String(expectedType.readableName()), new String(type.sourceName())}, - new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())}, - superclassRef.sourceStart, - superclassRef.sourceEnd); -} -public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.InterfaceNotFound; - break; - case NotVisible : // 2 - id = IProblem.InterfaceNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.InterfaceAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.InterfaceInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.InterfaceInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + public void invalidOperator(BinaryExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.InvalidOperator, new String[]{ + expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ + new String[]{expression.operatorToString(), + leftShortName + ", " + rightShortName}, //$NON-NLS-1$ + expression.sourceStart, expression.sourceEnd); } + public void invalidOperator(CompoundAssignment assign, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.InvalidOperator, new String[]{ + assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ + new String[]{assign.operatorToString(), + leftShortName + ", " + rightShortName}, //$NON-NLS-1$ + assign.sourceStart, assign.sourceEnd); + } + public void invalidOperator(UnaryExpression expression, TypeBinding type) { + this.handle(IProblem.InvalidOperator, + new String[]{expression.operatorToString(), + new String(type.readableName())}, new String[]{ + expression.operatorToString(), + new String(type.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void invalidParenthesizedExpression(AstNode reference) { + this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, + NoArgument, reference.sourceStart, reference.sourceEnd); + } + public void invalidSuperclass(SourceTypeBinding type, + TypeReference superclassRef, ReferenceBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.SuperclassNotFound; + break; + case NotVisible : + // 2 + id = IProblem.SuperclassNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.SuperclassAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.SuperclassInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.SuperclassInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(expectedType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(expectedType.shortReadableName()), + new String(type.sourceName())}, superclassRef.sourceStart, + superclassRef.sourceEnd); + } + public void invalidSuperinterface(SourceTypeBinding type, + TypeReference superinterfaceRef, ReferenceBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.InterfaceNotFound; + break; + case NotVisible : + // 2 + id = IProblem.InterfaceNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.InterfaceAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.InterfaceInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.InterfaceInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(expectedType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(expectedType.shortReadableName()), + new String(type.sourceName())}, superinterfaceRef.sourceStart, + superinterfaceRef.sourceEnd); + } + public void invalidType(AstNode location, TypeBinding type) { + int flag = IProblem.UndefinedType; // default + switch (type.problemId()) { + case NotFound : + flag = IProblem.UndefinedType; + break; + case NotVisible : + flag = IProblem.NotVisibleType; + break; + case Ambiguous : + flag = IProblem.AmbiguousType; + break; + case InternalNameProvided : + flag = IProblem.InternalTypeNameProvided; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedTypeHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{new String(type.readableName())}, + new String[]{new String(type.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void invalidTypeReference(Expression expression) { + this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void invalidTypeToSynchronize(Expression expression, TypeBinding type) { + this.handle(IProblem.InvalidTypeToSynchronized, + new String[]{new String(type.readableName())}, + new String[]{new String(type.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void invalidUnaryExpression(Expression expression) { + this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void isClassPathCorrect(char[][] wellKnownTypeName, + CompilationUnitDeclaration compUnitDecl) { + referenceContext = compUnitDecl; + String[] arguments = new String[]{CharOperation + .toString(wellKnownTypeName)}; + this.handle(IProblem.IsClassPathCorrect, arguments, arguments, + AbortCompilation | Error, compUnitDecl == null + ? 0 + : compUnitDecl.sourceStart, compUnitDecl == null + ? 1 + : compUnitDecl.sourceEnd); + } + public void maskedExceptionHandler(ReferenceBinding exceptionType, + AstNode location) { + this.handle(IProblem.MaskedCatch, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) { + this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void methodNeedingNoBody(MethodDeclaration methodDecl) { this.handle( - id, - new String[] {new String(expectedType.readableName()), new String(type.sourceName())}, - new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())}, - superinterfaceRef.sourceStart, - superinterfaceRef.sourceEnd); -} -public void invalidType(AstNode location, TypeBinding type) { - int flag = IProblem.UndefinedType; // default - switch (type.problemId()) { - case NotFound : - flag = IProblem.UndefinedType; - break; - case NotVisible : - flag = IProblem.NotVisibleType; - break; - case Ambiguous : - flag = IProblem.AmbiguousType; - break; - case InternalNameProvided : - flag = IProblem.InternalTypeNameProvided; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedTypeHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - break; - } - - this.handle( - flag, - new String[] {new String(type.readableName())}, - new String[] {new String(type.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void invalidTypeReference(Expression expression) { - this.handle( - IProblem.InvalidTypeExpression, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void invalidTypeToSynchronize(Expression expression, TypeBinding type) { - this.handle( - IProblem.InvalidTypeToSynchronized, - new String[] {new String(type.readableName())}, - new String[] {new String(type.shortReadableName())}, - expression.sourceStart, - expression.sourceEnd); -} -public void invalidUnaryExpression(Expression expression) { - this.handle( - IProblem.InvalidUnaryExpression, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) { - referenceContext = compUnitDecl; - String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)}; - this.handle( - IProblem.IsClassPathCorrect, - arguments, - arguments, - AbortCompilation | Error, - compUnitDecl == null ? 0 : compUnitDecl.sourceStart, - compUnitDecl == null ? 1 : compUnitDecl.sourceEnd); -} -public void maskedExceptionHandler(ReferenceBinding exceptionType, AstNode location) { - this.handle( - IProblem.MaskedCatch, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) { - this.handle( - IProblem.MethodRequiresBody, - NoArgument, - NoArgument, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void methodNeedingNoBody(MethodDeclaration methodDecl) { - this.handle( -// ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod, - IProblem.BodyForAbstractMethod, - NoArgument, - NoArgument, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void methodWithConstructorName(MethodDeclaration methodDecl) { - this.handle( - IProblem.MethodButWithConstructorName, - NoArgument, - NoArgument, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -//public void missingEnclosingInstanceSpecification(ReferenceBinding enclosingType, AstNode location) { -// boolean insideConstructorCall = -// (location instanceof ExplicitConstructorCall) -// && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper); -// -// this.handle( -// insideConstructorCall -// ? IProblem.MissingEnclosingInstanceForConstructorCall -// : IProblem.MissingEnclosingInstance, -// new String[] {new String(enclosingType.readableName())}, -// new String[] {new String(enclosingType.shortReadableName())}, -// location.sourceStart, -// location.sourceEnd); -//} -public void missingReturnType(AbstractMethodDeclaration methodDecl) { - this.handle( - IProblem.MissingReturnType, - NoArgument, - NoArgument, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void missingSemiColon(Expression expression){ - this.handle( - IProblem.MissingSemiColon, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) { - this.handle( - IProblem.MustDefineEitherDimensionExpressionsOrInitializer, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[] {new String(compUnitDecl.getFileName())}; - this.handle( - IProblem.MustSpecifyPackage, - arguments, - arguments, - compUnitDecl.sourceStart, - compUnitDecl.sourceStart + 1); -} -public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) { - this.handle( - IProblem.StaticMethodRequested, - new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)}, - new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)}, - messageSend.sourceStart, - messageSend.sourceEnd); -} - -public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.NativeMethodsCannotBeStrictfp, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void needImplementation() { - this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$ -} -public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) { - this.handle( - IProblem.NeedToEmulateFieldReadAccess, - new String[] {new String(field.declaringClass.readableName()), new String(field.name)}, - new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)}, - location.sourceStart, - location.sourceEnd); -} -public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) { - this.handle( - IProblem.NeedToEmulateFieldWriteAccess, - new String[] {new String(field.declaringClass.readableName()), new String(field.name)}, - new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)}, - location.sourceStart, - location.sourceEnd); -} -public void needToEmulateMethodAccess( - MethodBinding method, - AstNode location) { - - if (method.isConstructor()) - this.handle( - IProblem.NeedToEmulateConstructorAccess, - new String[] { - new String(method.declaringClass.readableName()), - parametersAsString(method) - }, - new String[] { - new String(method.declaringClass.shortReadableName()), - parametersAsShortString(method) - }, - location.sourceStart, - location.sourceEnd); - else - this.handle( - IProblem.NeedToEmulateMethodAccess, - new String[] { - new String(method.declaringClass.readableName()), - new String(method.selector), - parametersAsString(method) - }, - new String[] { - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method) - }, - location.sourceStart, - location.sourceEnd); -} -public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) { - String[] arguments = new String[] {new String(typeDecl.name)}; - this.handle( - IProblem.CannotDefineInterfaceInLocalType, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, AstNode location) { - String[] arguments = new String[]{ new String(local.name) }; - this.handle( - local instanceof SyntheticArgumentBinding - ? IProblem.TooManySyntheticArgumentSlots - : IProblem.TooManyArgumentSlots, - arguments, - arguments, - Abort | Error, - location.sourceStart, - location.sourceEnd); -} -public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, AstNode location) { - String[] arguments = new String[]{ new String(local.name) }; - this.handle( - IProblem.TooManyLocalVariableSlots, - arguments, - arguments, - Abort | Error, - location.sourceStart, - location.sourceEnd); -} -public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location, boolean isConstructorCall) { - - int id; - - if (isConstructorCall) { - //28 = No enclosing instance of type {0} is available due to some intermediate constructor invocation - id = IProblem.EnclosingInstanceInConstructorCall; - } else if ((location instanceof ExplicitConstructorCall) + // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? + // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod, + IProblem.BodyForAbstractMethod, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void methodWithConstructorName(MethodDeclaration methodDecl) { + this.handle(IProblem.MethodButWithConstructorName, NoArgument, + NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd); + } + //public void missingEnclosingInstanceSpecification(ReferenceBinding + // enclosingType, AstNode location) { + // boolean insideConstructorCall = + // (location instanceof ExplicitConstructorCall) + // && (((ExplicitConstructorCall) location).accessMode == + // ExplicitConstructorCall.ImplicitSuper); + // + // this.handle( + // insideConstructorCall + // ? IProblem.MissingEnclosingInstanceForConstructorCall + // : IProblem.MissingEnclosingInstance, + // new String[] {new String(enclosingType.readableName())}, + // new String[] {new String(enclosingType.shortReadableName())}, + // location.sourceStart, + // location.sourceEnd); + //} + public void missingReturnType(AbstractMethodDeclaration methodDecl) { + this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void missingSemiColon(Expression expression) { + this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void mustDefineDimensionsOrInitializer( + ArrayAllocationExpression expression) { + this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, + NoArgument, NoArgument, expression.sourceStart, + expression.sourceEnd); + } + public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{new String(compUnitDecl.getFileName())}; + this.handle(IProblem.MustSpecifyPackage, arguments, arguments, + compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1); + } + public void mustUseAStaticMethod(MessageSend messageSend, + MethodBinding method) { + this.handle(IProblem.StaticMethodRequested, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + messageSend.sourceStart, messageSend.sourceEnd); + } + public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void needImplementation() { + this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$ + } + public void needToEmulateFieldReadAccess(FieldBinding field, + AstNode location) { + this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, + location.sourceEnd); + } + public void needToEmulateFieldWriteAccess(FieldBinding field, + AstNode location) { + this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, + location.sourceEnd); + } + public void needToEmulateMethodAccess(MethodBinding method, AstNode location) { + if (method.isConstructor()) + this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{ + new String(method.declaringClass.readableName()), + parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + parametersAsShortString(method)}, location.sourceStart, + location.sourceEnd); + else + this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass + .shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + location.sourceStart, location.sourceEnd); + } + public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, + arguments, typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.name)}; + this.handle(local instanceof SyntheticArgumentBinding + ? IProblem.TooManySyntheticArgumentSlots + : IProblem.TooManyArgumentSlots, arguments, arguments, Abort + | Error, location.sourceStart, location.sourceEnd); + } + public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.name)}; + this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, + Abort | Error, location.sourceStart, location.sourceEnd); + } + public void noSuchEnclosingInstance(TypeBinding targetType, + AstNode location, boolean isConstructorCall) { + int id; + if (isConstructorCall) { + //28 = No enclosing instance of type {0} is available due to some + // intermediate constructor invocation + id = IProblem.EnclosingInstanceInConstructorCall; + } else if ((location instanceof ExplicitConstructorCall) && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) { - //20 = No enclosing instance of type {0} is accessible to invoke the super constructor. Must define a constructor and explicitly qualify its super constructor invocation with an instance of {0} (e.g. x.super() where x is an instance of {0}). - id = IProblem.MissingEnclosingInstanceForConstructorCall; - } else if (location instanceof AllocationExpression - && (((AllocationExpression) location).binding.declaringClass.isMemberType() - || (((AllocationExpression) location).binding.declaringClass.isAnonymousType() - && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) { - //21 = No enclosing instance of type {0} is accessible. Must qualify the allocation with an enclosing instance of type {0} (e.g. x.new A() where x is an instance of {0}). - id = IProblem.MissingEnclosingInstance; - } else { // default - //22 = No enclosing instance of the type {0} is accessible in scope - id = IProblem.IncorrectEnclosingInstanceReference; - } - - this.handle( - id, - new String[] { new String(targetType.readableName())}, - new String[] { new String(targetType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.IncompatibleTypesInEqualityOperator, - new String[] {leftName, rightName }, - new String[] {leftShortName, rightShortName }, - expression.sourceStart, - expression.sourceEnd); -} -public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.IncompatibleTypesInConditionalOperator, - new String[] {leftName, rightName }, - new String[] {leftShortName, rightShortName }, - expression.sourceStart, - expression.sourceEnd); -} -public void objectCannotHaveSuperTypes(SourceTypeBinding type) { - this.handle( - IProblem.ObjectCannotHaveSuperTypes, - NoArgument, - NoArgument, - type.sourceStart(), - type.sourceEnd()); -} -public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.TypeMismatch, - new String[] {leftName, rightName }, - new String[] {leftShortName, rightShortName }, - assignment.sourceStart, - assignment.sourceEnd); -} -public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) { - this.handle( - IProblem.OverridingDeprecatedMethod, - new String[] { - new String( - CharOperation.concat( - localMethod.declaringClass.readableName(), - localMethod.readableName(), - '.')), - new String(inheritedMethod.declaringClass.readableName())}, - new String[] { - new String( - CharOperation.concat( - localMethod.declaringClass.shortReadableName(), - localMethod.shortReadableName(), - '.')), - new String(inheritedMethod.declaringClass.shortReadableName())}, - localMethod.sourceStart(), - localMethod.sourceEnd()); -} -public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) { - this.handle( - IProblem.OverridingNonVisibleMethod, - new String[] { - new String( - CharOperation.concat( - localMethod.declaringClass.readableName(), - localMethod.readableName(), - '.')), - new String(inheritedMethod.declaringClass.readableName())}, - new String[] { - new String( - CharOperation.concat( - localMethod.declaringClass.shortReadableName(), - localMethod.shortReadableName(), - '.')), - new String(inheritedMethod.declaringClass.shortReadableName())}, - localMethod.sourceStart(), - localMethod.sourceEnd()); -} -public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[] {CharOperation.toString(compUnitDecl.currentPackage.tokens)}; - this.handle( - IProblem.PackageCollidesWithType, - arguments, - arguments, - compUnitDecl.currentPackage.sourceStart, - compUnitDecl.currentPackage.sourceEnd); -} -public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[] {CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName())}; - this.handle( - IProblem.PackageIsNotExpectedPackage, - arguments, - arguments, - compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart, - compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd); -} -private String parametersAsString(MethodBinding method) { - TypeBinding[] params = method.parameters; - StringBuffer buffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(new String(params[i].readableName())); - } - return buffer.toString(); -} -private String parametersAsShortString(MethodBinding method) { - TypeBinding[] params = method.parameters; - StringBuffer buffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(new String(params[i].shortReadableName())); - } - return buffer.toString(); -} -public void parseError( - int startPosition, - int endPosition, - char[] currentTokenSource, - String errorTokenName, - String[] possibleTokens) { - - if (possibleTokens.length == 0) { //no suggestion available - if (isKeyword(currentTokenSource)) { - String[] arguments = new String[] {new String(currentTokenSource)}; - this.handle( - IProblem.ParsingErrorOnKeywordNoSuggestion, - arguments, - arguments, - // this is the current -invalid- token position - startPosition, - endPosition); - return; - } else { - String[] arguments = new String[] {errorTokenName}; - this.handle( - IProblem.ParsingErrorNoSuggestion, - arguments, - arguments, - // this is the current -invalid- token position - startPosition, - endPosition); - return; + //20 = No enclosing instance of type {0} is accessible to invoke + // the super constructor. Must define a constructor and explicitly + // qualify its super constructor invocation with an instance of {0} + // (e.g. x.super() where x is an instance of {0}). + id = IProblem.MissingEnclosingInstanceForConstructorCall; + } else if (location instanceof AllocationExpression + && (((AllocationExpression) location).binding.declaringClass + .isMemberType() || (((AllocationExpression) location).binding.declaringClass + .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass + .superclass().isMemberType()))) { + //21 = No enclosing instance of type {0} is accessible. Must + // qualify the allocation with an enclosing instance of type {0} + // (e.g. x.new A() where x is an instance of {0}). + id = IProblem.MissingEnclosingInstance; + } else { // default + //22 = No enclosing instance of the type {0} is accessible in + // scope + id = IProblem.IncorrectEnclosingInstanceReference; } + this.handle(id, new String[]{new String(targetType.readableName())}, + new String[]{new String(targetType.shortReadableName())}, + location.sourceStart, location.sourceEnd); } - - //build a list of probable right tokens - StringBuffer list = new StringBuffer(20); - for (int i = 0, max = possibleTokens.length; i < max; i++) { - if (i > 0) - list.append(", "); //$NON-NLS-1$ - list.append('"'); - list.append(possibleTokens[i]); - list.append('"'); - } - - if (isKeyword(currentTokenSource)) { - String[] arguments = new String[] {new String(currentTokenSource), list.toString()}; - this.handle( - IProblem.ParsingErrorOnKeyword, - arguments, - arguments, + public void notCompatibleTypesError(EqualExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{ + leftName, rightName}, new String[]{leftShortName, + rightShortName}, expression.sourceStart, expression.sourceEnd); + } + public void notCompatibleTypesError(InstanceOfExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.IncompatibleTypesInConditionalOperator, + new String[]{leftName, rightName}, new String[]{leftShortName, + rightShortName}, expression.sourceStart, + expression.sourceEnd); + } + public void objectCannotHaveSuperTypes(SourceTypeBinding type) { + this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, + NoArgument, type.sourceStart(), type.sourceEnd()); + } + public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName}, + new String[]{leftShortName, rightShortName}, + assignment.sourceStart, assignment.sourceEnd); + } + public void overridesDeprecatedMethod(MethodBinding localMethod, + MethodBinding inheritedMethod) { + this.handle(IProblem.OverridingDeprecatedMethod, new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .readableName(), localMethod.readableName(), '.')), + new String(inheritedMethod.declaringClass.readableName())}, + new String[]{ + new String(CharOperation.concat( + localMethod.declaringClass.shortReadableName(), + localMethod.shortReadableName(), '.')), + new String(inheritedMethod.declaringClass + .shortReadableName())}, localMethod + .sourceStart(), localMethod.sourceEnd()); + } + public void overridesPackageDefaultMethod(MethodBinding localMethod, + MethodBinding inheritedMethod) { + this.handle(IProblem.OverridingNonVisibleMethod, new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .readableName(), localMethod.readableName(), '.')), + new String(inheritedMethod.declaringClass.readableName())}, + new String[]{ + new String(CharOperation.concat( + localMethod.declaringClass.shortReadableName(), + localMethod.shortReadableName(), '.')), + new String(inheritedMethod.declaringClass + .shortReadableName())}, localMethod + .sourceStart(), localMethod.sourceEnd()); + } + public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{CharOperation + .toString(compUnitDecl.currentPackage.tokens)}; + this.handle(IProblem.PackageCollidesWithType, arguments, arguments, + compUnitDecl.currentPackage.sourceStart, + compUnitDecl.currentPackage.sourceEnd); + } + public void packageIsNotExpectedPackage( + CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{CharOperation + .toString(compUnitDecl.compilationResult.compilationUnit + .getPackageName())}; + this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, + compUnitDecl.currentPackage == null + ? 0 + : compUnitDecl.currentPackage.sourceStart, + compUnitDecl.currentPackage == null + ? 0 + : compUnitDecl.currentPackage.sourceEnd); + } + private String parametersAsString(MethodBinding method) { + TypeBinding[] params = method.parameters; + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(new String(params[i].readableName())); + } + return buffer.toString(); + } + private String parametersAsShortString(MethodBinding method) { + TypeBinding[] params = method.parameters; + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(new String(params[i].shortReadableName())); + } + return buffer.toString(); + } + public void parseError(int startPosition, int endPosition, + char[] currentTokenSource, String errorTokenName, + String[] possibleTokens) { + if (possibleTokens.length == 0) { //no suggestion available + if (isKeyword(currentTokenSource)) { + String[] arguments = new String[]{new String(currentTokenSource)}; + this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, + arguments, arguments, + // this is the current -invalid- token position + startPosition, endPosition); + return; + } else { + String[] arguments = new String[]{errorTokenName}; + this.handle(IProblem.ParsingErrorNoSuggestion, arguments, + arguments, + // this is the current -invalid- token position + startPosition, endPosition); + return; + } + } + //build a list of probable right tokens + StringBuffer list = new StringBuffer(20); + for (int i = 0, max = possibleTokens.length; i < max; i++) { + if (i > 0) + list.append(", "); //$NON-NLS-1$ + list.append('"'); + list.append(possibleTokens[i]); + list.append('"'); + } + if (isKeyword(currentTokenSource)) { + String[] arguments = new String[]{new String(currentTokenSource), + list.toString()}; + this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments, // this is the current -invalid- token position - startPosition, - endPosition); - return; - } - //extract the literal when it's a literal - if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$ + startPosition, endPosition); + return; + } + //extract the literal when it's a literal + if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$ errorTokenName = new String(currentTokenSource); - } - - String[] arguments = new String[] {errorTokenName, list.toString()}; - this.handle( - IProblem.ParsingError, - arguments, - arguments, + } + String[] arguments = new String[]{errorTokenName, list.toString()}; + this.handle(IProblem.ParsingError, arguments, arguments, // this is the current -invalid- token position - startPosition, - endPosition); -} -public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { - this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit - String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)}; - this.handle( - IProblem.PublicClassMustMatchFileName, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd, - compUnitDecl.compilationResult); -} -public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) { - - this.handle( - IProblem.RecursiveConstructorInvocation, - new String[] { - new String(constructorCall.binding.declaringClass.readableName()), - parametersAsString(constructorCall.binding) - }, - new String[] { - new String(constructorCall.binding.declaringClass.shortReadableName()), - parametersAsShortString(constructorCall.binding) - }, - constructorCall.sourceStart, - constructorCall.sourceEnd); -} - -public void redefineArgument(Argument arg) { - String[] arguments = new String[] {new String(arg.name)}; - this.handle( - IProblem.RedefinedArgument, - arguments, - arguments, - arg.sourceStart, - arg.sourceEnd); -} -public void redefineLocal(LocalDeclaration localDecl) { - String[] arguments = new String[] {new String(localDecl.name)}; - this.handle( - IProblem.RedefinedLocal, - arguments, - arguments, - localDecl.sourceStart, - localDecl.sourceEnd); -} -public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) { - this.handle( - IProblem.ArrayReferenceRequired, - new String[] {new String(arrayType.readableName())}, - new String[] {new String(arrayType.shortReadableName())}, - arrayRef.sourceStart, - arrayRef.sourceEnd); -} -public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(methodDecl.selector)}; - this.handle( - IProblem.ReturnTypeCannotBeVoidArray, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : // 1 - id = IProblem.ReturnTypeNotFound; - break; - case NotVisible : // 2 - id = IProblem.ReturnTypeNotVisible; - break; - case Ambiguous : // 3 - id = IProblem.ReturnTypeAmbiguous; - break; - case InternalNameProvided : // 4 - id = IProblem.ReturnTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : // 5 - id = IProblem.ReturnTypeInheritedNameHidesEnclosingName; - break; - case NoError : // 0 - default : - needImplementation(); // want to fail to see why we were here... - return; + startPosition, endPosition); } - this.handle( - id, - new String[] {new String(methodDecl.selector), new String(expectedType.readableName())}, - new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())}, - methodDecl.returnType.sourceStart, - methodDecl.returnType.sourceEnd); -} -public void scannerError(Parser parser, String errorTokenName) { - Scanner scanner = parser.scanner; - - int flag = IProblem.ParsingErrorNoSuggestion; - int startPos = scanner.startPosition; - - //special treatment for recognized errors.... - if (errorTokenName.equals(Scanner.END_OF_SOURCE)) - flag = IProblem.EndOfSource; - else - if (errorTokenName.equals(Scanner.INVALID_HEXA)) + public void publicClassMustMatchFileName( + CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + String[] arguments = new String[]{ + new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.handle(IProblem.PublicClassMustMatchFileName, arguments, + arguments, typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void recursiveConstructorInvocation( + ExplicitConstructorCall constructorCall) { + this.handle(IProblem.RecursiveConstructorInvocation, new String[]{ + new String(constructorCall.binding.declaringClass + .readableName()), + parametersAsString(constructorCall.binding)}, new String[]{ + new String(constructorCall.binding.declaringClass + .shortReadableName()), + parametersAsShortString(constructorCall.binding)}, + constructorCall.sourceStart, constructorCall.sourceEnd); + } + public void redefineArgument(Argument arg) { + String[] arguments = new String[]{new String(arg.name)}; + this.handle(IProblem.RedefinedArgument, arguments, arguments, + arg.sourceStart, arg.sourceEnd); + } + public void redefineLocal(LocalDeclaration localDecl) { + String[] arguments = new String[]{new String(localDecl.name)}; + this.handle(IProblem.RedefinedLocal, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void referenceMustBeArrayTypeAt(TypeBinding arrayType, + ArrayReference arrayRef) { + this.handle(IProblem.ArrayReferenceRequired, new String[]{new String( + arrayType.readableName())}, new String[]{new String(arrayType + .shortReadableName())}, arrayRef.sourceStart, + arrayRef.sourceEnd); + } + public void returnTypeCannotBeVoidArray(SourceTypeBinding type, + MethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(methodDecl.selector)}; + this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void returnTypeProblem(SourceTypeBinding type, + MethodDeclaration methodDecl, TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ReturnTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ReturnTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ReturnTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ReturnTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ReturnTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), + new String(expectedType.readableName())}, new String[]{ + new String(methodDecl.selector), + new String(expectedType.shortReadableName())}, + methodDecl.returnType.sourceStart, + methodDecl.returnType.sourceEnd); + } + public void scannerError(Parser parser, String errorTokenName) { + Scanner scanner = parser.scanner; + int flag = IProblem.ParsingErrorNoSuggestion; + int startPos = scanner.startPosition; + //special treatment for recognized errors.... + if (errorTokenName.equals(Scanner.END_OF_SOURCE)) + flag = IProblem.EndOfSource; + else if (errorTokenName.equals(Scanner.INVALID_HEXA)) flag = IProblem.InvalidHexa; - else - if (errorTokenName.equals(Scanner.INVALID_OCTAL)) - flag = IProblem.InvalidOctal; - else - if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT)) - flag = IProblem.InvalidCharacterConstant; - else - if (errorTokenName.equals(Scanner.INVALID_ESCAPE)) - flag = IProblem.InvalidEscape; - else - if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)){ - flag = IProblem.InvalidUnicodeEscape; - // better locate the error message - char[] source = scanner.source; - int checkPos = scanner.currentPosition - 1; - if (checkPos >= source.length) checkPos = source.length - 1; - while (checkPos >= startPos){ - if (source[checkPos] == '\\') break; - checkPos --; - } - startPos = checkPos; - } else - if (errorTokenName.equals(Scanner.INVALID_FLOAT)) - flag = IProblem.InvalidFloat; - else - if (errorTokenName.equals(Scanner.UNTERMINATED_STRING)) - flag = IProblem.UnterminatedString; - else - if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT)) - flag = IProblem.UnterminatedComment; - else - if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING)) - flag = IProblem.UnterminatedString; - - String[] arguments = flag == IProblem.ParsingErrorNoSuggestion - ? new String[] {errorTokenName} - : NoArgument; - this.handle( - flag, - arguments, - arguments, + else if (errorTokenName.equals(Scanner.INVALID_OCTAL)) + flag = IProblem.InvalidOctal; + else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT)) + flag = IProblem.InvalidCharacterConstant; + else if (errorTokenName.equals(Scanner.INVALID_ESCAPE)) + flag = IProblem.InvalidEscape; + else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) { + flag = IProblem.InvalidUnicodeEscape; + // better locate the error message + char[] source = scanner.source; + int checkPos = scanner.currentPosition - 1; + if (checkPos >= source.length) + checkPos = source.length - 1; + while (checkPos >= startPos) { + if (source[checkPos] == '\\') + break; + checkPos--; + } + startPos = checkPos; + } else if (errorTokenName.equals(Scanner.INVALID_FLOAT)) + flag = IProblem.InvalidFloat; + else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING)) + flag = IProblem.UnterminatedString; + else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT)) + flag = IProblem.UnterminatedComment; + else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING)) + flag = IProblem.UnterminatedString; + String[] arguments = flag == IProblem.ParsingErrorNoSuggestion + ? new String[]{errorTokenName} + : NoArgument; + this.handle(flag, arguments, arguments, // this is the current -invalid- token position - startPos, - scanner.currentPosition - 1, - parser.compilationUnit.compilationResult); -} -public void shouldReturn(TypeBinding returnType, AstNode location) { - this.handle( - IProblem.ShouldReturnValue, - new String[] { new String (returnType.readableName())}, - new String[] { new String (returnType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) { - this.handle( - IProblem.NoImplicitStringConversionForCharArrayExpression, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) { - if (currentMethod.isStatic()) - this.handle( + startPos, scanner.currentPosition - 1, + parser.compilationUnit.compilationResult); + } + public void shouldReturn(TypeBinding returnType, AstNode location) { + this.handle(IProblem.ShouldReturnValue, new String[]{new String( + returnType.readableName())}, new String[]{new String(returnType + .shortReadableName())}, location.sourceStart, + location.sourceEnd); + } + public void signalNoImplicitStringConversionForCharArrayExpression( + Expression expression) { + this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, + NoArgument, NoArgument, expression.sourceStart, + expression.sourceEnd); + } + public void staticAndInstanceConflict(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + if (currentMethod.isStatic()) + this.handle( // This static method cannot hide the instance method from %1 - // 8.4.6.4 - If a class inherits more than one method with the same signature a static (non-abstract) method cannot hide an instance method. - IProblem.CannotHideAnInstanceMethodWithAStaticMethod, - new String[] {new String(inheritedMethod.declaringClass.readableName())}, - new String[] {new String(inheritedMethod.declaringClass.shortReadableName())}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); - else - this.handle( + // 8.4.6.4 - If a class inherits more than one method with + // the same signature a static (non-abstract) method cannot + // hide an instance method. + IProblem.CannotHideAnInstanceMethodWithAStaticMethod, + new String[]{new String(inheritedMethod.declaringClass + .readableName())}, + new String[]{new String(inheritedMethod.declaringClass + .shortReadableName())}, + currentMethod.sourceStart(), currentMethod.sourceEnd()); + else + this.handle( // This instance method cannot override the static method from %1 - // 8.4.6.4 - If a class inherits more than one method with the same signature an instance (non-abstract) method cannot override a static method. - IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, - new String[] {new String(inheritedMethod.declaringClass.readableName())}, - new String[] {new String(inheritedMethod.declaringClass.shortReadableName())}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); -} -public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) { - String[] arguments = new String[] {new String(field.readableName())}; - this.handle( - IProblem.NonStaticFieldFromStaticInvocation, - arguments, - arguments, - fieldRef.sourceStart, - fieldRef.sourceEnd); -} -public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field){ - String[] arguments = new String[] {new String(field.readableName())}; - this.handle( - IProblem.NonStaticFieldFromStaticInvocation, - arguments, - arguments, - nameRef.sourceStart, - nameRef.sourceEnd); -} -public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) { - String[] arguments = new String[] {new String(field.readableName())}; - this.handle( - IProblem.NonStaticFieldFromStaticInvocation, - arguments, - arguments, - nameRef.sourceStart, - nameRef.sourceEnd); -} -public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) { - this.handle( + // 8.4.6.4 - If a class inherits more than one method with + // the same signature an instance (non-abstract) method + // cannot override a static method. + IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, + new String[]{new String(inheritedMethod.declaringClass + .readableName())}, + new String[]{new String(inheritedMethod.declaringClass + .shortReadableName())}, + currentMethod.sourceStart(), currentMethod.sourceEnd()); + } + public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, + FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, fieldRef.sourceStart, fieldRef.sourceEnd); + } + public void staticFieldAccessToNonStaticVariable( + QualifiedNameReference nameRef, FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, nameRef.sourceStart, nameRef.sourceEnd); + } + public void staticFieldAccessToNonStaticVariable( + SingleNameReference nameRef, FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, nameRef.sourceStart, nameRef.sourceEnd); + } + public void staticInheritedMethodConflicts(SourceTypeBinding type, + MethodBinding concreteMethod, MethodBinding[] abstractMethods) { + this.handle( // The static method %1 conflicts with the abstract method in %2 - // 8.4.6.4 - If a class inherits more than one method with the same signature it is an error for one to be static (non-abstract) and the other abstract. - IProblem.StaticInheritedMethodConflicts, - new String[] { - new String(concreteMethod.readableName()), - new String(abstractMethods[0].declaringClass.readableName())}, - new String[] { - new String(concreteMethod.readableName()), - new String(abstractMethods[0].declaringClass.shortReadableName())}, - type.sourceStart(), - type.sourceEnd()); -} -public void stringConstantIsExceedingUtf8Limit(AstNode location) { - this.handle( - IProblem.StringConstantIsExceedingUtf8Limit, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) { - this.handle( - IProblem.SuperclassMustBeAClass, - new String[] {new String(superType.readableName()), new String(type.sourceName())}, - new String[] {new String(superType.shortReadableName()), new String(type.sourceName())}, - superclassRef.sourceStart, - superclassRef.sourceEnd); -} -public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) { - this.handle( - IProblem.SuperInterfaceMustBeAnInterface, - new String[] {new String(superType.readableName()), new String(type.sourceName())}, - new String[] {new String(superType.shortReadableName()), new String(type.sourceName())}, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void task(String tag, String message, String priority, int start, int end){ - this.handle( - IProblem.Task, - new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/}, - new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/}, - start, - end); -} -public void tooManyDimensions(AstNode expression) { - this.handle( - IProblem.TooManyArrayDimensions, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} -public void tooManyFields(TypeDeclaration typeDeclaration) { - this.handle( - IProblem.TooManyFields, - new String[]{ new String(typeDeclaration.binding.readableName())}, - new String[]{ new String(typeDeclaration.binding.shortReadableName())}, - Abort | Error, - typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); -} -public void tooManyMethods(TypeDeclaration typeDeclaration) { - this.handle( - IProblem.TooManyMethods, - new String[]{ new String(typeDeclaration.binding.readableName())}, - new String[]{ new String(typeDeclaration.binding.shortReadableName())}, - Abort | Error, - typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); -} -public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)){ - leftShortName = leftName; - rightShortName = rightName; - } - this.handle( - IProblem.IllegalCast, - new String[] { rightName, leftName }, - new String[] { rightShortName, leftShortName }, - expression.sourceStart, - expression.sourceEnd); -} -public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { - this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit - String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)}; - this.handle( - IProblem.TypeCollidesWithPackage, - arguments, - arguments, - typeDecl.sourceStart, - typeDecl.sourceEnd, - compUnitDecl.compilationResult); -} -public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, AstNode location) { - String resultTypeName = new String(resultType.readableName()); - String expectedTypeName = new String(expectedType.readableName()); - String resultTypeShortName = new String(resultType.shortReadableName()); - String expectedTypeShortName = new String(expectedType.shortReadableName()); - if (resultTypeShortName.equals(expectedTypeShortName)){ - resultTypeShortName = resultTypeName; - expectedTypeShortName = expectedTypeName; - } - this.handle( - IProblem.TypeMismatch, - new String[] {resultTypeName, expectedTypeName}, - new String[] {resultTypeShortName, expectedTypeShortName}, - location.sourceStart, - location.sourceEnd); -} -public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) { - String constantTypeName = new String(constantType.readableName()); - String expectedTypeName = new String(expectedType.readableName()); - String constantTypeShortName = new String(constantType.shortReadableName()); - String expectedTypeShortName = new String(expectedType.shortReadableName()); - if (constantTypeShortName.equals(expectedTypeShortName)){ - constantTypeShortName = constantTypeName; - expectedTypeShortName = expectedTypeName; - } - this.handle( - IProblem.TypeMismatch, - new String[] {constantTypeName, expectedTypeName}, - new String[] {constantTypeShortName, expectedTypeShortName}, - expression.sourceStart, - expression.sourceEnd); -} -public void undefinedLabel(BranchStatement statement) { - String[] arguments = new String[] {new String(statement.label)}; - this.handle( - IProblem.UndefinedLabel, - arguments, - arguments, - statement.sourceStart, - statement.sourceEnd); -} -public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[] {fieldDecl.name()}; - this.handle( - IProblem.UnexpectedStaticModifierForField, - arguments, - arguments, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; - this.handle( - IProblem.UnexpectedStaticModifierForMethod, - arguments, - arguments, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void unhandledException(TypeBinding exceptionType, AstNode location) { - - boolean insideDefaultConstructor = - (referenceContext instanceof ConstructorDeclaration) - && ((ConstructorDeclaration)referenceContext).isDefaultConstructor(); - boolean insideImplicitConstructorCall = - (location instanceof ExplicitConstructorCall) - && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper); - - this.handle( - insideDefaultConstructor - ? IProblem.UnhandledExceptionInDefaultConstructor - : (insideImplicitConstructorCall - ? IProblem.UndefinedConstructorInImplicitConstructorCall - : IProblem.UnhandledException), - new String[] {new String(exceptionType.readableName())}, - new String[] {new String(exceptionType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); -} -public void uninitializedBlankFinalField(FieldBinding binding, AstNode location) { - String[] arguments = new String[] {new String(binding.readableName())}; - this.handle( - IProblem.UninitializedBlankFinalField, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void uninitializedLocalVariable(LocalVariableBinding binding, AstNode location) { - String[] arguments = new String[] {new String(binding.readableName())}; - this.handle( - IProblem.UninitializedLocalVariable, - arguments, - arguments, - location.sourceStart, - location.sourceEnd); -} -public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) { - - this.handle( - IProblem.UnmatchedBracket, - NoArgument, - NoArgument, - position, - position, - context, - compilationResult); -} -public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) { - this.handle( - IProblem.IllegalEnclosingInstanceSpecification, - new String[]{ new String(targetType.readableName())}, - new String[]{ new String(targetType.shortReadableName())}, - expression.sourceStart, - expression.sourceEnd); -} -public void unnecessaryReceiverForStaticMethod(AstNode location, MethodBinding method) { - this.handle( - IProblem.NonStaticAccessToStaticMethod, - new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)}, - new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)}, - location.sourceStart, - location.sourceEnd); -} -public void unnecessaryReceiverForStaticField(AstNode location, FieldBinding field) { - this.handle( - IProblem.NonStaticAccessToStaticField, - new String[] {new String(field.declaringClass.readableName()), new String(field.name)}, - new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)}, - location.sourceStart, - location.sourceEnd); -} -public void unreachableCode(Statement statement) { - this.handle( - IProblem.CodeCannotBeReached, - NoArgument, - NoArgument, - statement.sourceStart, - statement.sourceEnd); -} -public void unreachableExceptionHandler(ReferenceBinding exceptionType, AstNode location) { - this.handle( - IProblem.UnreachableCatch, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} -public void unresolvableReference(NameReference nameRef, Binding binding) { - int severity = Error; -/* also need to check that the searchedType is the receiver type - if (binding instanceof ProblemBinding) { - ProblemBinding problem = (ProblemBinding) binding; - if (problem.searchType != null && problem.searchType.isHierarchyInconsistent()) - severity = SecondaryError; - } -*/ - String[] arguments = new String[] {new String(binding.readableName())}; - this.handle( - IProblem.UndefinedName, - arguments, - arguments, - severity, - nameRef.sourceStart, - nameRef.sourceEnd); -} -public void unusedArgument(LocalDeclaration localDecl) { - - String[] arguments = new String[] {localDecl.name()}; - this.handle( - IProblem.ArgumentIsNeverUsed, - arguments, - arguments, - localDecl.sourceStart, - localDecl.sourceEnd); -} -public void unusedImport(ImportReference importRef) { - String[] arguments = new String[] { CharOperation.toString(importRef.tokens) }; - this.handle( - IProblem.UnusedImport, - arguments, - arguments, - importRef.sourceStart, - importRef.sourceEnd); -} -public void unusedLocalVariable(LocalDeclaration localDecl) { - String[] arguments = new String[] {localDecl.name()}; - this.handle( - IProblem.LocalVariableIsNeverUsed, - arguments, - arguments, - localDecl.sourceStart, - localDecl.sourceEnd); -} -public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) { - - if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) return; - - // no complaint for no-arg constructors (or default ones) - known pattern to block instantiation - if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0) return; - - MethodBinding constructor = constructorDecl.binding; - this.handle( - IProblem.UnusedPrivateConstructor, - new String[] { - new String(constructor.declaringClass.readableName()), - parametersAsString(constructor) - }, - new String[] { - new String(constructor.declaringClass.shortReadableName()), - parametersAsShortString(constructor) - }, - constructorDecl.sourceStart, - constructorDecl.sourceEnd); -} -public void unusedPrivateField(FieldDeclaration fieldDecl) { - - if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) return; - - FieldBinding field = fieldDecl.binding; - - if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) - && field.isStatic() - && field.isFinal() - && TypeBinding.LongBinding == field.type) { - return; // do not report unused serialVersionUID field + // 8.4.6.4 - If a class inherits more than one method with the + // same signature it is an error for one to be static + // (non-abstract) and the other abstract. + IProblem.StaticInheritedMethodConflicts, new String[]{ + new String(concreteMethod.readableName()), + new String(abstractMethods[0].declaringClass + .readableName())}, new String[]{ + new String(concreteMethod.readableName()), + new String(abstractMethods[0].declaringClass + .shortReadableName())}, type.sourceStart(), + type.sourceEnd()); + } + public void stringConstantIsExceedingUtf8Limit(AstNode location) { + this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, + NoArgument, location.sourceStart, location.sourceEnd); + } + public void superclassMustBeAClass(SourceTypeBinding type, + TypeReference superclassRef, ReferenceBinding superType) { + this.handle(IProblem.SuperclassMustBeAClass, new String[]{ + new String(superType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(superType.shortReadableName()), + new String(type.sourceName())}, superclassRef.sourceStart, + superclassRef.sourceEnd); + } + public void superinterfaceMustBeAnInterface(SourceTypeBinding type, + TypeDeclaration typeDecl, ReferenceBinding superType) { + this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{ + new String(superType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(superType.shortReadableName()), + new String(type.sourceName())}, typeDecl.sourceStart, + typeDecl.sourceEnd); + } + public void task(String tag, String message, String priority, int start, + int end) { + this + .handle( + IProblem.Task, + new String[]{tag, message, priority/* + * secret argument + * that is not + * surfaced in + * getMessage() + */}, + new String[]{tag, message, priority/* + * secret argument + * that is not + * surfaced in + * getMessage() + */}, + start, end); + } + public void tooManyDimensions(AstNode expression) { + this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void tooManyFields(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyFields, new String[]{new String( + typeDeclaration.binding.readableName())}, + new String[]{new String(typeDeclaration.binding + .shortReadableName())}, Abort | Error, + typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + public void tooManyMethods(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyMethods, new String[]{new String( + typeDeclaration.binding.readableName())}, + new String[]{new String(typeDeclaration.binding + .shortReadableName())}, Abort | Error, + typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + public void typeCastError(CastExpression expression, TypeBinding leftType, + TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; } - this.handle( - IProblem.UnusedPrivateField, - new String[] { - new String(field.declaringClass.readableName()), - new String(field.name), - }, - new String[] { - new String(field.declaringClass.shortReadableName()), - new String(field.name), - }, - fieldDecl.sourceStart, - fieldDecl.sourceEnd); -} -public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) { - - if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) return; - - MethodBinding method = methodDecl.binding; - - // no report for serialization support 'void readObject(ObjectInputStream)' - if (!method.isStatic() - && TypeBinding.VoidBinding == method.returnType - && method.parameters.length == 1 - && method.parameters[0].dimensions() == 0 - && CharOperation.equals(method.selector, TypeConstants.READOBJECT) - && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) { - return; - } - // no report for serialization support 'void writeObject(ObjectOutputStream)' - if (!method.isStatic() - && TypeBinding.VoidBinding == method.returnType - && method.parameters.length == 1 - && method.parameters[0].dimensions() == 0 - && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT) - && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) { - return; - } - // no report for serialization support 'Object readResolve()' - if (!method.isStatic() - && TypeBinding.T_Object == method.returnType.id - && method.parameters.length == 0 - && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) { - return; - } - // no report for serialization support 'Object writeReplace()' - if (!method.isStatic() - && TypeBinding.T_Object == method.returnType.id - && method.parameters.length == 0 - && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) { - return; - } - this.handle( - IProblem.UnusedPrivateMethod, - new String[] { - new String(method.declaringClass.readableName()), - new String(method.selector), - parametersAsString(method) - }, - new String[] { - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method) - }, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} -public void unusedPrivateType(TypeDeclaration typeDecl) { - - if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) return; - - ReferenceBinding type = typeDecl.binding; - this.handle( - IProblem.UnusedPrivateType, - new String[] { - new String(type.readableName()), - }, - new String[] { - new String(type.shortReadableName()), - }, - typeDecl.sourceStart, - typeDecl.sourceEnd); -} -public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) { - this.handle( - IProblem.UseAssertAsAnIdentifier, - NoArgument, - NoArgument, - sourceStart, - sourceEnd); -} - -public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) { - String[] arguments = new String[] {new String(varDecl.name)}; - this.handle( - IProblem.VariableTypeCannotBeVoid, - arguments, - arguments, - varDecl.sourceStart, - varDecl.sourceEnd); -} -public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) { - String[] arguments = new String[] {new String(varDecl.name)}; - this.handle( - IProblem.VariableTypeCannotBeVoidArray, - arguments, - arguments, - varDecl.sourceStart, - varDecl.sourceEnd); -} -public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) { - this.handle( + this.handle(IProblem.IllegalCast, new String[]{rightName, leftName}, + new String[]{rightShortName, leftShortName}, + expression.sourceStart, expression.sourceEnd); + } + public void typeCollidesWithPackage( + CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + String[] arguments = new String[]{ + new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void typeMismatchError(TypeBinding resultType, + TypeBinding expectedType, AstNode location) { + String resultTypeName = new String(resultType.readableName()); + String expectedTypeName = new String(expectedType.readableName()); + String resultTypeShortName = new String(resultType.shortReadableName()); + String expectedTypeShortName = new String(expectedType + .shortReadableName()); + if (resultTypeShortName.equals(expectedTypeShortName)) { + resultTypeShortName = resultTypeName; + expectedTypeShortName = expectedTypeName; + } + this.handle(IProblem.TypeMismatch, new String[]{resultTypeName, + expectedTypeName}, new String[]{resultTypeShortName, + expectedTypeShortName}, location.sourceStart, + location.sourceEnd); + } + public void typeMismatchErrorActualTypeExpectedType(Expression expression, + TypeBinding constantType, TypeBinding expectedType) { + String constantTypeName = new String(constantType.readableName()); + String expectedTypeName = new String(expectedType.readableName()); + String constantTypeShortName = new String(constantType + .shortReadableName()); + String expectedTypeShortName = new String(expectedType + .shortReadableName()); + if (constantTypeShortName.equals(expectedTypeShortName)) { + constantTypeShortName = constantTypeName; + expectedTypeShortName = expectedTypeName; + } + this.handle(IProblem.TypeMismatch, new String[]{constantTypeName, + expectedTypeName}, new String[]{constantTypeShortName, + expectedTypeShortName}, expression.sourceStart, + expression.sourceEnd); + } + public void undefinedLabel(BranchStatement statement) { + String[] arguments = new String[]{new String(statement.label)}; + this.handle(IProblem.UndefinedLabel, arguments, arguments, + statement.sourceStart, statement.sourceEnd); + } + public void unexpectedStaticModifierForField(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.UnexpectedStaticModifierForField, arguments, + arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void unexpectedStaticModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void unhandledException(TypeBinding exceptionType, AstNode location) { + boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) + && ((ConstructorDeclaration) referenceContext) + .isDefaultConstructor(); + boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall) + && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper); + this + .handle( + insideDefaultConstructor + ? IProblem.UnhandledExceptionInDefaultConstructor + : (insideImplicitConstructorCall + ? IProblem.UndefinedConstructorInImplicitConstructorCall + : IProblem.UnhandledException), + new String[]{new String(exceptionType.readableName())}, + new String[]{new String(exceptionType + .shortReadableName())}, location.sourceStart, + location.sourceEnd); + } + public void uninitializedBlankFinalField(FieldBinding binding, + AstNode location) { + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UninitializedBlankFinalField, arguments, + arguments, location.sourceStart, location.sourceEnd); + } + public void uninitializedLocalVariable(LocalVariableBinding binding, + AstNode location) { + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void unmatchedBracket(int position, ReferenceContext context, + CompilationResult compilationResult) { + this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, + position, position, context, compilationResult); + } + public void unnecessaryEnclosingInstanceSpecification( + Expression expression, ReferenceBinding targetType) { + this.handle(IProblem.IllegalEnclosingInstanceSpecification, + new String[]{new String(targetType.readableName())}, + new String[]{new String(targetType.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void unnecessaryReceiverForStaticMethod(AstNode location, + MethodBinding method) { + this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, location.sourceStart, + location.sourceEnd); + } + public void unnecessaryReceiverForStaticField(AstNode location, + FieldBinding field) { + this.handle(IProblem.NonStaticAccessToStaticField, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, + location.sourceEnd); + } + public void unreachableCode(Statement statement) { + this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void unreachableExceptionHandler(ReferenceBinding exceptionType, + AstNode location) { + this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void unresolvableReference(NameReference nameRef, Binding binding) { + int severity = Error; + /* + * also need to check that the searchedType is the receiver type if + * (binding instanceof ProblemBinding) { ProblemBinding problem = + * (ProblemBinding) binding; if (problem.searchType != null && + * problem.searchType.isHierarchyInconsistent()) severity = + * SecondaryError; } + */ + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UndefinedName, arguments, arguments, severity, + nameRef.sourceStart, nameRef.sourceEnd); + } + public void unusedArgument(LocalDeclaration localDecl) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void unusedImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation + .toString(importRef.tokens)}; + this.handle(IProblem.UnusedImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void unusedLocalVariable(LocalDeclaration localDecl) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) { + if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) + return; + // no complaint for no-arg constructors (or default ones) - known + // pattern to block instantiation + if (constructorDecl.arguments == null + || constructorDecl.arguments.length == 0) + return; + MethodBinding constructor = constructorDecl.binding; + this.handle(IProblem.UnusedPrivateConstructor, new String[]{ + new String(constructor.declaringClass.readableName()), + parametersAsString(constructor)}, new String[]{ + new String(constructor.declaringClass.shortReadableName()), + parametersAsShortString(constructor)}, + constructorDecl.sourceStart, constructorDecl.sourceEnd); + } + public void unusedPrivateField(FieldDeclaration fieldDecl) { + if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) + return; + FieldBinding field = fieldDecl.binding; + if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) + && field.isStatic() && field.isFinal() + && TypeBinding.LongBinding == field.type) { + return; // do not report unused serialVersionUID field + } + this.handle(IProblem.UnusedPrivateField, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name),}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name),}, fieldDecl.sourceStart, + fieldDecl.sourceEnd); + } + public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) { + if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) + return; + MethodBinding method = methodDecl.binding; + // no report for serialization support 'void + // readObject(ObjectInputStream)' + if (!method.isStatic() + && TypeBinding.VoidBinding == method.returnType + && method.parameters.length == 1 + && method.parameters[0].dimensions() == 0 + && CharOperation.equals(method.selector, + TypeConstants.READOBJECT) + && CharOperation.equals( + TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, + method.parameters[0].readableName())) { + return; + } + // no report for serialization support 'void + // writeObject(ObjectOutputStream)' + if (!method.isStatic() + && TypeBinding.VoidBinding == method.returnType + && method.parameters.length == 1 + && method.parameters[0].dimensions() == 0 + && CharOperation.equals(method.selector, + TypeConstants.WRITEOBJECT) + && CharOperation.equals( + TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, + method.parameters[0].readableName())) { + return; + } + // no report for serialization support 'Object readResolve()' + if (!method.isStatic() + && TypeBinding.T_Object == method.returnType.id + && method.parameters.length == 0 + && CharOperation.equals(method.selector, + TypeConstants.READRESOLVE)) { + return; + } + // no report for serialization support 'Object writeReplace()' + if (!method.isStatic() + && TypeBinding.T_Object == method.returnType.id + && method.parameters.length == 0 + && CharOperation.equals(method.selector, + TypeConstants.WRITEREPLACE)) { + return; + } + this.handle(IProblem.UnusedPrivateMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), + parametersAsShortString(method)}, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void unusedPrivateType(TypeDeclaration typeDecl) { + if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) + return; + ReferenceBinding type = typeDecl.binding; + this.handle(IProblem.UnusedPrivateType, new String[]{new String(type + .readableName()),}, new String[]{new String(type + .shortReadableName()),}, typeDecl.sourceStart, + typeDecl.sourceEnd); + } + public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) { + this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, + sourceStart, sourceEnd); + } + public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) { + String[] arguments = new String[]{new String(varDecl.name)}; + this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, + varDecl.sourceStart, varDecl.sourceEnd); + } + public void variableTypeCannotBeVoidArray( + AbstractVariableDeclaration varDecl) { + String[] arguments = new String[]{new String(varDecl.name)}; + this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, + arguments, varDecl.sourceStart, varDecl.sourceEnd); + } + public void visibilityConflict(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + this.handle( // Cannot reduce the visibility of the inherited method from %1 - // 8.4.6.3 - The access modifier of an hiding method must provide at least as much access as the hidden method. - // 8.4.6.3 - The access modifier of an overiding method must provide at least as much access as the overriden method. - IProblem.MethodReducesVisibility, - new String[] {new String(inheritedMethod.declaringClass.readableName())}, - new String[] {new String(inheritedMethod.declaringClass.shortReadableName())}, - currentMethod.sourceStart(), - currentMethod.sourceEnd()); -} -public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) { - //the two catch block under and upper are in an incorrect order. - //under should be define BEFORE upper in the source - - TypeReference typeRef = statement.catchArguments[under].type; - this.handle( - IProblem.UnreachableCatch, - NoArgument, - NoArgument, - typeRef.sourceStart, - typeRef.sourceEnd); -} - -public void nonExternalizedStringLiteral(AstNode location) { - this.handle( - IProblem.NonExternalizedStringLiteral, - NoArgument, - NoArgument, - location.sourceStart, - location.sourceEnd); -} - -public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) { - this.handle( - IProblem.TooManyBytesForStringConstant, - new String[]{ new String(typeDeclaration.binding.readableName())}, - new String[]{ new String(typeDeclaration.binding.shortReadableName())}, - Abort | Error, - typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); -} - -public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) { - this.handle( - IProblem.TooManyConstantsInConstantPool, - new String[]{ new String(typeDeclaration.binding.readableName())}, - new String[]{ new String(typeDeclaration.binding.shortReadableName())}, - Abort | Error, - typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); -} - -private boolean isKeyword(char[] tokenSource) { - /* - * This code is heavily grammar dependant - */ - - if (tokenSource == null) { - return false; - } - try { - Scanner scanner = new Scanner(); - scanner.setSource(tokenSource); - int token = scanner.getNextToken(); - char[] currentKeyword; - try { - currentKeyword = scanner.getCurrentIdentifierSource(); - } catch (ArrayIndexOutOfBoundsException e) { + // 8.4.6.3 - The access modifier of an hiding method must + // provide at least as much access as the hidden method. + // 8.4.6.3 - The access modifier of an overiding method must + // provide at least as much access as the overriden method. + IProblem.MethodReducesVisibility, new String[]{new String( + inheritedMethod.declaringClass.readableName())}, + new String[]{new String(inheritedMethod.declaringClass + .shortReadableName())}, currentMethod.sourceStart(), + currentMethod.sourceEnd()); + } + public void wrongSequenceOfExceptionTypesError(TryStatement statement, + int under, int upper) { + //the two catch block under and upper are in an incorrect order. + //under should be define BEFORE upper in the source + TypeReference typeRef = statement.catchArguments[under].type; + this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, + typeRef.sourceStart, typeRef.sourceEnd); + } + public void nonExternalizedStringLiteral(AstNode location) { + this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, + NoArgument, location.sourceStart, location.sourceEnd); + } + public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) { + this + .handle(IProblem.TooManyBytesForStringConstant, + new String[]{new String(typeDeclaration.binding + .readableName())}, new String[]{new String( + typeDeclaration.binding.shortReadableName())}, + Abort | Error, typeDeclaration.sourceStart, + typeDeclaration.sourceEnd); + } + public void noMoreAvailableSpaceInConstantPool( + TypeDeclaration typeDeclaration) { + this + .handle(IProblem.TooManyConstantsInConstantPool, + new String[]{new String(typeDeclaration.binding + .readableName())}, new String[]{new String( + typeDeclaration.binding.shortReadableName())}, + Abort | Error, typeDeclaration.sourceStart, + typeDeclaration.sourceEnd); + } + private boolean isKeyword(char[] tokenSource) { + /* + * This code is heavily grammar dependant + */ + if (tokenSource == null) { return false; } - int nextToken= scanner.getNextToken(); - if (nextToken == Scanner.TokenNameEOF - && scanner.startPosition == scanner.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException - // while reading the last token - switch(token) { - case Scanner.TokenNameERROR: - if (CharOperation.equals("goto".toCharArray(), currentKeyword) ||CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$ + try { + Scanner scanner = new Scanner(); + scanner.setSource(tokenSource); + int token = scanner.getNextToken(); + char[] currentKeyword; + try { + currentKeyword = scanner.getCurrentIdentifierSource(); + } catch (ArrayIndexOutOfBoundsException e) { + return false; + } + int nextToken = scanner.getNextToken(); + if (nextToken == Scanner.TokenNameEOF + && scanner.startPosition == scanner.source.length) { // to + // handle + // case + // where + // we + // had + // an + // ArrayIndexOutOfBoundsException + // while reading the last token + switch (token) { + case Scanner.TokenNameERROR : + if (CharOperation.equals("goto".toCharArray(), + currentKeyword) + || CharOperation.equals("const".toCharArray(), + currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$ + return true; + } else { + return false; + } + case Scanner.TokenNameabstract : + // case Scanner.TokenNameassert: + // case Scanner.TokenNamebyte: + case Scanner.TokenNamebreak : + // case Scanner.TokenNameboolean: + case Scanner.TokenNamecase : + // case Scanner.TokenNamechar: + case Scanner.TokenNamecatch : + case Scanner.TokenNameclass : + case Scanner.TokenNamecontinue : + case Scanner.TokenNamedo : + // case Scanner.TokenNamedouble: + case Scanner.TokenNamedefault : + case Scanner.TokenNameelse : + case Scanner.TokenNameextends : + case Scanner.TokenNamefor : + // case Scanner.TokenNamefinal: + // case Scanner.TokenNamefloat: + case Scanner.TokenNamefalse : + case Scanner.TokenNamefinally : + case Scanner.TokenNameif : + // case Scanner.TokenNameint: + // case Scanner.TokenNameimport: + case Scanner.TokenNameinterface : + case Scanner.TokenNameimplements : + case Scanner.TokenNameinstanceof : + // case Scanner.TokenNamelong: + case Scanner.TokenNamenew : + case Scanner.TokenNamenull : + // case Scanner.TokenNamenative: + case Scanner.TokenNamepublic : + // case Scanner.TokenNamepackage: + case Scanner.TokenNameprivate : + case Scanner.TokenNameprotected : + case Scanner.TokenNamereturn : + // case Scanner.TokenNameshort: + case Scanner.TokenNamesuper : + case Scanner.TokenNamestatic : + case Scanner.TokenNameswitch : + // case Scanner.TokenNamestrictfp: + // case Scanner.TokenNamesynchronized: + case Scanner.TokenNametry : + case Scanner.TokenNamethis : + case Scanner.TokenNametrue : + case Scanner.TokenNamethrow : + // case Scanner.TokenNamethrows: + // case Scanner.TokenNametransient: + // case Scanner.TokenNamevoid: + // case Scanner.TokenNamevolatile: + case Scanner.TokenNamewhile : return true; - } else { + default : return false; - } - case Scanner.TokenNameabstract: -// case Scanner.TokenNameassert: -// case Scanner.TokenNamebyte: - case Scanner.TokenNamebreak: -// case Scanner.TokenNameboolean: - case Scanner.TokenNamecase: -// case Scanner.TokenNamechar: - case Scanner.TokenNamecatch: - case Scanner.TokenNameclass: - case Scanner.TokenNamecontinue: - case Scanner.TokenNamedo: -// case Scanner.TokenNamedouble: - case Scanner.TokenNamedefault: - case Scanner.TokenNameelse: - case Scanner.TokenNameextends: - case Scanner.TokenNamefor: -// case Scanner.TokenNamefinal: -// case Scanner.TokenNamefloat: - case Scanner.TokenNamefalse: - case Scanner.TokenNamefinally: - case Scanner.TokenNameif: -// case Scanner.TokenNameint: -// case Scanner.TokenNameimport: - case Scanner.TokenNameinterface: - case Scanner.TokenNameimplements: - case Scanner.TokenNameinstanceof: -// case Scanner.TokenNamelong: - case Scanner.TokenNamenew: - case Scanner.TokenNamenull: -// case Scanner.TokenNamenative: - case Scanner.TokenNamepublic: -// case Scanner.TokenNamepackage: - case Scanner.TokenNameprivate: - case Scanner.TokenNameprotected: - case Scanner.TokenNamereturn: -// case Scanner.TokenNameshort: - case Scanner.TokenNamesuper: - case Scanner.TokenNamestatic: - case Scanner.TokenNameswitch: -// case Scanner.TokenNamestrictfp: -// case Scanner.TokenNamesynchronized: - case Scanner.TokenNametry: - case Scanner.TokenNamethis: - case Scanner.TokenNametrue: - case Scanner.TokenNamethrow: -// case Scanner.TokenNamethrows: -// case Scanner.TokenNametransient: -// case Scanner.TokenNamevoid: -// case Scanner.TokenNamevolatile: - case Scanner.TokenNamewhile: - return true; - default: - return false; + } + } else { + return false; } - } else { + } catch (InvalidInputException e) { return false; } } - catch (InvalidInputException e) { - return false; + // jsurfer start + public void phpParsingError(String[] messageArguments, + int problemStartPosition, int problemEndPosition, + ReferenceContext context, CompilationResult compilationResult) { + this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, + problemStartPosition, problemEndPosition, context, + compilationResult); } - -} -// jsurfer start -public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition, ReferenceContext context, CompilationResult compilationResult) { - - this.handle( - IProblem.PHPParsingError, - NoArgument, - messageArguments, - problemStartPosition, - problemEndPosition, - context, - compilationResult); -} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index 1ac320c..0157acb 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -6,7 +6,7 @@ * Created on 05.03.2003 * * @author Stefan Langer (musk) - * @version $Revision: 1.21 $ + * @version $Revision: 1.22 $ */ package net.sourceforge.phpeclipse.phpeditor.php; @@ -43,6 +43,10 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { private int fFileType; private Map tokens = new HashMap(); + public PHPPartitionScanner() { + this(IPHPPartitionScannerConstants.PHP_FILE); + } + public PHPPartitionScanner(int fileType) { this.tokens.put(IPHPPartitionScannerConstants.PHP, new Token(IPHPPartitionScannerConstants.PHP)); this.tokens.put( -- 1.7.1