summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-08-07 15:56:04 -0400
committerStephan Herrmann2018-08-07 15:56:04 -0400
commitbffa480010e36f8e498b11130836782ffca09566 (patch)
tree9c55cb516e000e3bd10447498c70b6c4e03faa34
parent73901481c73753772d1ee4e1942343f115c71f96 (diff)
downloadorg.eclipse.objectteams-bffa480010e36f8e498b11130836782ffca09566.tar.gz
org.eclipse.objectteams-bffa480010e36f8e498b11130836782ffca09566.tar.xz
org.eclipse.objectteams-bffa480010e36f8e498b11130836782ffca09566.zip
Bug 537772 - Attribute OTCompilerVersion should not be set for o.o.Team
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java13
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.tests/compiler/org/eclipse/objectteams/otdt/tests/compiler/AttributesTest.java130
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/AllTests.java3
3 files changed, 143 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
index e5468c6fd..825d7bef4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
@@ -1,7 +1,7 @@
/**********************************************************************
* This file is part of "Object Teams Development Tooling"-Software
*
- * Copyright 2004, 2016 Fraunhofer Gesellschaft, Munich, Germany,
+ * Copyright 2004, 2018 Fraunhofer Gesellschaft, Munich, Germany,
* for its Fraunhofer Institute for Computer Architecture and Software
* Technology (FIRST), Berlin, Germany and Technical University Berlin,
* Germany.
@@ -36,6 +36,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme;
import org.eclipse.jdt.internal.compiler.impl.IntConstant;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
+import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
@@ -63,6 +64,7 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TThisBinding;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.Protections;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper;
+import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer;
/**
* This class models properties of Teams.
@@ -121,11 +123,18 @@ public class TeamModel extends TypeModel {
public TeamModel(TypeDeclaration teamAst)
{
super(teamAst);
- if (teamAst.enclosingType == null)
+ if (teamAst.enclosingType == null && !isOrgObjectteamsTeam(teamAst))
addAttribute(WordValueAttribute.compilerVersionAttribute());
if (Config.clientIsBatchCompiler())
this.knownRoleFiles = new RoleFileCache(teamAst);
}
+ private static boolean isOrgObjectteamsTeam(TypeDeclaration teamAst) {
+ ClassScope scope = teamAst.scope;
+ if (scope != null) {
+ return TypeAnalyzer.isOrgObjectteamsTeam(scope.referenceCompilationUnit());
+ }
+ return false;
+ }
public TeamModel(ReferenceBinding teamBinding)
{
super(teamBinding);
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/compiler/org/eclipse/objectteams/otdt/tests/compiler/AttributesTest.java b/testplugins/org.eclipse.objectteams.otdt.tests/compiler/org/eclipse/objectteams/otdt/tests/compiler/AttributesTest.java
new file mode 100644
index 000000000..666823a14
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/compiler/org/eclipse/objectteams/otdt/tests/compiler/AttributesTest.java
@@ -0,0 +1,130 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2018 Stephan Herrmann
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.tests.compiler;
+
+import java.io.File;
+import java.util.Map;
+
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.tests.util.Util;
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+public class AttributesTest extends AbstractOTJLDTest {
+
+ String versionString = null;
+
+ public AttributesTest(String name) {
+ super(name);
+ }
+ public static Class<? extends TestCase> testClass() {
+ return AttributesTest.class;
+ }
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.versionString = (this.complianceLevel < ClassFileConstants.JDK9)
+ ? "version 1.8 : 52.0"
+ : (this.complianceLevel < ClassFileConstants.JDK10 ? "version 9 : 53.0" : "version 10 : 54.0");
+ }
+
+
+ // Use this static initializer to specify subset for tests
+ // All specified tests which does not belong to the class are skipped...
+ static {
+// TESTS_PREFIX = "test012";
+// TESTS_NAMES = new String[] { "testBug359495" };
+// TESTS_NUMBERS = new int[] { 53 };
+// TESTS_RANGE = new int[] { 23 -1,};
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_1_8);
+ }
+
+ private void assertSubstring(String actualOutput, String expectedOutput) {
+ int index = actualOutput.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(actualOutput, 2));
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, actualOutput);
+ }
+ }
+
+ // https://bugs.eclipse.org/537772 - Attribute OTCompilerVersion should not be set for o.o.Team
+ public void testAttributesInOOTeam() throws Exception {
+ Map<String,String> customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_PureJavaOnly, CompilerOptions.ENABLED);
+ runConformTest(
+ new String[] {
+ "org/objectteams/Team.java",
+ "package org.objectteams;\n" +
+ "public class Team {\n" +
+ "}\n"
+ },
+ customOptions);
+
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String path = OUTPUT_DIR + File.separator + "org/objectteams/Team.class";
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path));
+ String actualOutput =
+ disassembler.disassemble(
+ classFileBytes,
+ "\n",
+ ClassFileBytesDisassembler.SYSTEM);
+
+ String expectedOutput =
+ "// Compiled from Team.java ("+versionString+", super bit)\n" +
+ "public class org.objectteams.Team {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 org/objectteams/Team\n" +
+ " constant #2 utf8: \"org/objectteams/Team\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"<init>\"\n" +
+ " constant #6 utf8: \"()V\"\n" +
+ " constant #7 utf8: \"Code\"\n" +
+ " constant #8 method_ref: #3.#9 java/lang/Object.<init> ()V\n" +
+ " constant #9 name_and_type: #5.#6 <init> ()V\n" +
+ " constant #10 utf8: \"LineNumberTable\"\n" +
+ " constant #11 utf8: \"LocalVariableTable\"\n" +
+ " constant #12 utf8: \"this\"\n" +
+ " constant #13 utf8: \"Lorg/objectteams/Team;\"\n" +
+ " constant #14 utf8: \"SourceFile\"\n" +
+ " constant #15 utf8: \"Team.java\"\n" +
+ " constant #16 utf8: \"OTClassFlags\"\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public Team();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: org.objectteams.Team\n" +
+ "\n" +
+ " Attribute: OTClassFlags Length: 2\n" +
+ "}";
+
+ assertSubstring(actualOutput, expectedOutput);
+}
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/AllTests.java
index 8766cc955..8fd0e4593 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/AllTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/AllTests.java
@@ -1,7 +1,7 @@
/**********************************************************************
* This file is part of "Object Teams Development Tooling"-Software
*
- * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * Copyright 2004, 2018 Fraunhofer Gesellschaft, Munich, Germany,
* for its Fraunhofer Institute and Computer Architecture and Software
* Technology (FIRST), Berlin, Germany and Technical University Berlin,
* Germany.
@@ -39,6 +39,7 @@ public class AllTests
suite.addTest(org.eclipse.objectteams.otdt.tests.compiler.errorreporting.TestAll.suite());
suite.addTest(org.eclipse.objectteams.otdt.tests.compiler.ast.TypeDeclarationTest.suite());
suite.addTest(org.eclipse.objectteams.otdt.tests.compiler.smap.AllTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.tests.compiler.AttributesTest.suite());
//hierarchy
suite.addTest(org.eclipse.objectteams.otdt.tests.hierarchy.AllTests.suite());