List of usage examples for org.eclipse.jdt.core IJavaProject setOption
void setOption(String optionName, String optionValue);
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testRoFiNestedTeam() throws CoreException { try {/* w w w . j av a 2 s.c o m*/ // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.ERROR); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); this.createFolder("/P/MyTeam"); String role1SourceString = "team package MyTeam;\n" + "public class Role1 {\n" + "}\n"; this.createFile("/P/MyTeam/Role1.java", role1SourceString); String role2SourceString = "team package MyTeam;\n" + "public team class Role2 extends Role1 {\n" + "}\n"; this.createFile("/P/MyTeam/Role2.java", role2SourceString); String teamSourceString = "public team class MyTeam {\n" + " Role1 r;\n" + "}\n"; this.createFile("/P/MyTeam.java", teamSourceString); char[] role2SourceChars = role2SourceString.toCharArray(); this.problemRequestor.initialize(role2SourceChars); getCompilationUnit("/P/MyTeam/Role2.java").getWorkingCopy(this.wcOwner, null); assertProblems("Unexpected problems", "----------\n" + "----------\n"); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testRoFiNestedTeam_SyntaxError() throws CoreException { try {// w w w. j av a 2 s . c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.ERROR); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); this.createFile("/P/JavaLinkedModeProposal.java", "public class JavaLinkedModeProposal {\n" + " String baseMethod() { return null; }\n" + "}\n"); this.createFolder("/P/MyTeam"); String role1SourceString = "team package MyTeam;\n" + "public class Role1 {\n" + "}\n"; this.createFile("/P/MyTeam/Role1.java", role1SourceString); String role2SourceString = "team package MyTeam;\n" + "\n" + "import static org.eclipse.objectteams.otdt.ui.ImageConstants.CALLINBINDING_AFTER_IMG;\n" + "import static org.eclipse.objectteams.otdt.ui.ImageConstants.CALLINBINDING_BEFORE_IMG;\n" + "import static org.eclipse.objectteams.otdt.ui.ImageConstants.CALLINBINDING_REPLACE_IMG;\n" + "import static org.eclipse.objectteams.otdt.ui.ImageConstants.CALLOUTBINDING_IMG;\n" + "\n" + "import java.util.List;\n" + "\n" + "import org.eclipse.core.runtime.CoreException;\n" + "import org.eclipse.jdt.core.CompletionProposal;\n" + "import org.eclipse.jdt.core.ICompilationUnit;\n" + "import org.eclipse.jdt.core.IJavaProject;\n" + "import org.eclipse.jdt.core.JavaModelException;\n" + "import org.eclipse.jdt.core.dom.AST;\n" + "import org.eclipse.jdt.core.dom.ASTNode;\n" + "import org.eclipse.jdt.core.dom.AbstractMethodMappingDeclaration;\n" + "import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;\n" + "import org.eclipse.jdt.core.dom.IMethodBinding;\n" + "import org.eclipse.jdt.core.dom.ITypeBinding;\n" + "import org.eclipse.jdt.core.dom.MethodBindingOperator;\n" + "import org.eclipse.jdt.core.dom.MethodSpec;\n" + "import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;\n" + "import org.eclipse.jdt.core.dom.SingleVariableDeclaration;\n" + "import org.eclipse.jdt.core.dom.Type;\n" + "import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;\n" + "import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;\n" + "import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;\n" + "import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;\n" + "import org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup;\n" + "import org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup.Proposal;\n" + "import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;\n" + "import org.eclipse.jface.text.link.LinkedModeModel;\n" + "import org.eclipse.jface.text.link.LinkedPosition;\n" + "import org.eclipse.objectteams.otdt.internal.ui.util.Images;\n" + "import org.eclipse.objectteams.otdt.internal.ui.util.OTStubUtility;\n" + "import org.eclipse.swt.graphics.Image;\n" + "import org.eclipse.text.edits.DeleteEdit;\n" + "import org.eclipse.text.edits.MultiTextEdit;\n" + "import org.eclipse.text.edits.ReplaceEdit;\n" + "import org.eclipse.text.edits.TextEdit;\n" + "\n" + "/** \n" + " */ \n" + "@SuppressWarnings(\"restriction\")\n" + "protected team class CreateMethodMappingCompletionProposal extends MethodMappingCompletionProposal \n" + "{\n" + "\n" + " /* gateway to private final base class. */\n" + " @SuppressWarnings(\"decapsulation\")\n" + " protected class MyJavaLinkedModeProposal playedBy JavaLinkedModeProposal {\n" + "\n" + " public MyJavaLinkedModeProposal(ICompilationUnit unit, ITypeBinding typeProposal, int relevance) {\n" + " base(unit, typeProposal, relevance);\n" + " }\n" + " TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model) \n" + " -> TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model);\n" + " }\n" + "\n" + "\n" + "\n" + " boolean fIsOverride = false;\n" + " boolean fIsOnlyCallin = false; \n" + " \n" + " protected CreateMethodMappingCompletionProposal(IJavaProject jProject, \n" + " ICompilationUnit cu,\n" + " CompletionProposal proposal,\n" + " String[] paramTypes,\n" + " boolean isOverride,\n" + " boolean isOnlyCallin,\n" + " int length,\n" + " String displayName, \n" + " Image image)\n" + " {\n" + " super(jProject, cu, proposal, paramTypes, length, displayName, image);\n" + " this.fIsOverride= isOverride;\n" + " this.fIsOnlyCallin = isOnlyCallin;\n" + " }\n" + " protected CreateMethodMappingCompletionProposal(IJavaProject jProject, \n" + " ICompilationUnit cu, \n" + " CompletionProposal proposal,\n" + " int length,\n" + " String displayName,\n" + " Image image) \n" + " {\n" + " super(jProject, cu, proposal, length, displayName, image);\n" + " }\n" + " \n" + " /** Create a rewrite that additionally removes typed fragment if needed. \n" + " * That fragment will not be represented by an AST-node, that could be removed.\n" + " */\n" + " ASTRewrite createRewrite(AST ast) \n" + " {\n" + " if (fLength == 0)\n" + " return ASTRewrite.create(ast);\n" + " \n" + " // the typed prefix will have to be deleted:\n" + " final TextEdit delete= new DeleteEdit(fReplaceStart, fLength);\n" + " \n" + " // return a custom rewrite that additionally deletes typed fragment\n" + " return new ASTRewrite(ast) {\n" + " @Override\n" + " public TextEdit rewriteAST() \n" + " throws JavaModelException, IllegalArgumentException \n" + " {\n" + " TextEdit edits = super.rewriteAST();\n" + " if (edits instanceof MultiTextEdit) {\n" + " MultiTextEdit multi = (MultiTextEdit) edits;\n" + " multi.addChild(delete);\n" + " }\n" + " return edits;\n" + " }\n" + " };\n" + " }\n" + " \n" + " /** Overridable, see CalloutToFieldCompletionProposal.\n" + " * At least baseBinding must be set, roleBinding is optional.\n" + " */\n" + " boolean setupRewrite(ICompilationUnit iCU, \n" + " ASTRewrite rewrite, \n" + " ImportRewrite importRewrite,\n" + " ITypeBinding roleBinding,\n" + " ITypeBinding baseBinding,\n" + " ASTNode type,\n" + " AbstractMethodMappingDeclaration partialMapping,\n" + " ChildListPropertyDescriptor bodyProperty) \n" + " throws CoreException\n" + " {\n" + " // find base method:\n" + " IMethodBinding method= findMethod(baseBinding, fMethodName, fParamTypes);\n" + " if (method == null)\n" + " return false;\n" + " \n" + " CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(fJavaProject);\n" + " // create callout:\n" + " AbstractMethodMappingDeclaration stub= this.fIsOnlyCallin \n" + " ? OTStubUtility.createCallin(iCU, rewrite, importRewrite,\n" + " method, baseBinding.getName(), ModifierKeyword.BEFORE_KEYWORD, settings)\n" + " : OTStubUtility.createCallout(iCU, rewrite, importRewrite,\n" + " method, baseBinding.getName(), settings);\n" + " if (stub != null) {\n" + " insertStub(rewrite, type, bodyProperty, fReplaceStart, stub);\n" + " \n" + " MethodSpec roleMethodSpec = (MethodSpec)stub.getRoleMappingElement();\n" + " \n" + " // return type:\n" + " ITrackedNodePosition returnTypePosition = null;\n" + " ITypeBinding returnType = method.getReturnType();\n" + " if (!(returnType.isPrimitive() && \"void\".equals(returnType.getName()))) {\n" + " returnTypePosition = rewrite.track(roleMethodSpec.getReturnType2());\n" + " addLinkedPosition(returnTypePosition, true, ROLEMETHODRETURN_KEY);\n" + " LinkedProposalPositionGroup group1 = getLinkedProposalModel().getPositionGroup(ROLEMETHODRETURN_KEY, true);\n" + " group1.addProposal(new MyJavaLinkedModeProposal(iCU, method.getReturnType(), 13)); //$NON-NLS-1$\n" + " group1.addProposal(\"void\", null, 13); //$NON-NLS-1$\n" + " }\n" + " \n" + " // role method name:\n" + " addLinkedPosition(rewrite.track(roleMethodSpec.getName()), false, ROLEMETHODNAME_KEY);\n" + " \n" + " // argument lifting?\n" + " if (roleBinding != null)\n" + " addLiftingProposals(roleBinding, method, stub, rewrite);\n" + " \n" + " // binding operator:\n" + " addLinkedPosition(rewrite.track(stub.bindingOperator()), false, BINDINGKIND_KEY);\n" + " LinkedProposalPositionGroup group2= getLinkedProposalModel().getPositionGroup(BINDINGKIND_KEY, true);\n" + " if (!this.fIsOnlyCallin) {\n" + " String calloutToken = \"->\";\n" + " if (this.fIsOverride) {\n" + " calloutToken = \"=>\";\n" + " stub.bindingOperator().setBindingKind(MethodBindingOperator.KIND_CALLOUT_OVERRIDE);\n" + " }\n" + " group2.addProposal(calloutToken, Images.getImage(CALLOUTBINDING_IMG), 13); //$NON-NLS-1$\n" + " }\n" + " group2.addProposal(makeBeforeAfterBindingProposal(\"<- before\", Images.getImage(CALLINBINDING_BEFORE_IMG), returnTypePosition)); //$NON-NLS-1$\n" + " group2.addProposal(\"<- replace\", Images.getImage(CALLINBINDING_REPLACE_IMG), 13); //$NON-NLS-1$\n" + " group2.addProposal(makeBeforeAfterBindingProposal(\"<- after\", Images.getImage(CALLINBINDING_AFTER_IMG), returnTypePosition)); //$NON-NLS-1$\n" + " }\n" + " return true; \n" + " }\n" + " /** Create a method-binding proposal that, when applied, will change the role-returntype to \"void\": */\n" + " Proposal makeBeforeAfterBindingProposal(String displayString, Image image, final ITrackedNodePosition returnTypePosition) {\n" + " return new Proposal(displayString, image, 13) {\n" + " @Override\n" + " public TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model)\n" + " throws CoreException \n" + " {\n" + " MultiTextEdit edits = new MultiTextEdit();\n" + " if (returnTypePosition != null)\n" + " edits.addChild(new ReplaceEdit(returnTypePosition.getStartPosition(), returnTypePosition.getLength(), \"void\"));\n" + " edits.addChild(super.computeEdits(offset, position, trigger, stateMask, model));\n" + " return edits;\n" + " }\n" + " };\n" + " }\n" + " \n" + " /** Check if any parameters or the return type are candidates for lifting/lowering. */\n" + " @SuppressWarnings(\"rawtypes\")\n" + " private void addLiftingProposals(ITypeBinding roleTypeBinding, IMethodBinding methodBinding,\n" + " AbstractMethodMappingDeclaration stub, ASTRewrite rewrite) \n" + " {\n" + " ITypeBinding[] roles= roleTypeBinding.getDeclaringClass().getDeclaredTypes();\n" + " MethodSpec roleSpec= (MethodSpec)stub.getRoleMappingElement();\n" + " List params= roleSpec.parameters();\n" + " ITypeBinding[] paramTypes = methodBinding.getParameterTypes();\n" + " for (int i= 0; i<params.size(); i++)\n" + " addLiftingProposalGroup(rewrite, ROLEPARAM_KEY+i, roles, \n" + " ((SingleVariableDeclaration)params.get(i)).getType(), paramTypes[i]);\n" + " addLiftingProposalGroup(rewrite, ROLEPARAM_KEY+\"return\", roles, //$NON-NLS-1$\n" + " roleSpec.getReturnType2(), methodBinding.getReturnType());\n" + " }\n" + " /**\n" + " * check whether a given type is played by a role from a given array and create a proposal group containing base and role type. \n" + " * @param rewrite\n" + " * @param positionGroupID \n" + " * @param roles available roles in the enclosing team\n" + " * @param type AST node to investigate\n" + " * @param typeBinding type binding of AST node to investigate\n" + " */\n" + " void addLiftingProposalGroup(ASTRewrite rewrite, String positionGroupID, ITypeBinding[] roles, Type type, ITypeBinding typeBinding)\n" + " {\n" + " for (ITypeBinding roleBinding : roles) {\n" + " if (roleBinding.isSynthRoleIfc()) continue; // synth ifcs would otherwise cause dupes\n" + " if (typeBinding.equals(roleBinding.getBaseClass())) {\n" + " ITrackedNodePosition argTypePos= rewrite.track(type);\n" + " addLinkedPosition(argTypePos, true, positionGroupID);\n" + " LinkedProposalPositionGroup group=\n" + " getLinkedProposalModel().getPositionGroup(positionGroupID, true);\n" + " group.addProposal(type.toString(), null, 13);\n" + " group.addProposal(roleBinding.getName(), null, 13);\n" + " break;\n" + " }\n" + " } \n" + " }\n" + "}"; this.createFile("/P/MyTeam/CreateMethodMappingCompletionProposal.java", role2SourceString); String teamSourceString = "public team class MyTeam {\n" + " CreateMethodMappingCompletionProposal r;\n" + "}\n"; this.createFile("/P/MyTeam.java", teamSourceString); char[] role2SourceChars = role2SourceString.toCharArray(); this.problemRequestor.initialize(role2SourceChars); ICompilationUnit cu = getCompilationUnit("/P/MyTeam/CreateMethodMappingCompletionProposal.java") .getWorkingCopy(this.wcOwner, null); // inject an error at 'random' location cu.applyTextEdit(new InsertEdit(1000, "\t\t@"), null); IType r2 = cu.getType("CreateMethodMappingCompletionProposal"); IType inner = r2.getType("MyJavaLinkedModeProposal"); IRoleType innerRole = (IRoleType) OTModelManager.getOTElement(inner); IType base = innerRole.getBaseClass(); assertTrue("base should not null", base != null); assertEquals("wrong name of baseclass", "JavaLinkedModeProposal", base.getElementName()); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testClassLiteralForRoFi() throws CoreException { try {//from w w w. jav a 2 s . c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.ERROR); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); this.createFolder("/P/MyTeam"); String roleSourceString = "team package MyTeam;\n" + "public class Role {\n" + " void foo() {\n" + " String val= \"OK\";\n" + " }\n" + "}\n"; this.createFile("/P/MyTeam/Role.java", roleSourceString); String teamSourceString = "public team class MyTeam {\n" + " final MyTeam other = new MyTeam();\n" + " Class c = Role<@other>.class;\n" + "}\n"; this.createFile("/P/MyTeam.java", teamSourceString); char[] teamSourceChars = teamSourceString.toCharArray(); this.problemRequestor.initialize(teamSourceChars); getCompilationUnit("/P/MyTeam.java").getWorkingCopy(this.wcOwner, null); assertProblems("Unexpected problems", "----------\n" + "1. WARNING in /P/MyTeam.java (at line 3)\n" + " Class c = Role<@other>.class;\n" + " ^^^^^\n" + "Class is a raw type. References to generic type Class<T> should be parameterized\n" + "----------\n"); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testSubTeamIntroducesBindingAmbiguity() throws CoreException { try {// w w w. j av a2s .c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.ERROR); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); String baseSourceString = "public class Base {\n" + "}\n"; this.createFile("/P/Base.java", baseSourceString); String superTeamSourceString = "public team class SuperTeam {\n" + " protected class R0 playedBy Base {}\n" + " protected class R1 extends R0 {}\n" + " public void foo(Base as R0 bar) {}\n" + "}\n"; this.createFile("/P/SuperTeam.java", superTeamSourceString); String subTeamSourceString = "public team class SubTeam extends SuperTeam {\n" + " protected class R2 extends R0 {}\n" + "}\n"; this.createFile("/P/SubTeam.java", subTeamSourceString); char[] subTeamSourceChars = subTeamSourceString.toCharArray(); this.problemRequestor.initialize(subTeamSourceChars); getCompilationUnit("/P/SubTeam.java").getWorkingCopy(this.wcOwner, null); assertProblems("Unexpected problems", "----------\n" + "1. WARNING in /P/SubTeam.java (at line 1)\n" + " public team class SubTeam extends SuperTeam {\n" + " ^^^^^^^\n" + "Potential ambiguity in role binding. The base \'Base\' is bound to the following roles: SubTeam.R1,SubTeam.R2 (OTJLD 2.3.4(a)).\n" + "----------\n" + "2. ERROR in /P/SubTeam.java (at line 1)\n" + " public team class SubTeam extends SuperTeam {\n" + " ^^^^^^^\n" + "Team introduces binding ambiguity for role R0<@tthis[SubTeam]>, which may break clients of the super team (OTJLD 2.3.5(d)).\n" + "----------\n" + "3. ERROR in /P/SubTeam.java (at line 1)\n" + " public team class SubTeam extends SuperTeam {\n" + " ^^^^^^^\n" + "Team introduces binding ambiguity for role R1<@tthis[SubTeam]>, which may break clients of the super team (OTJLD 2.3.5(d)).\n" + "----------\n"); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testBug348574a() throws CoreException { try {// w ww .ja v a 2 s . com // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); String superTeamSourceString = "public team class SuperTeam {\n" + " protected abstract class R0 {\n" + " abstract void foo();" + " abstract static void fooStatic();" + " }\n" + "}\n"; this.createFile("/P/SuperTeam.java", superTeamSourceString); String subTeamSourceString = "public team class SubTeam extends SuperTeam {\n" + " protected class R0 {}\n" + "}\n"; this.createFile("/P/SubTeam.java", subTeamSourceString); char[] subTeamSourceChars = subTeamSourceString.toCharArray(); this.problemRequestor.initialize(subTeamSourceChars); getCompilationUnit("/P/SubTeam.java").getWorkingCopy(this.wcOwner, null); assertProblems("Unexpected problems", "----------\n" + "1. ERROR in /P/SubTeam.java (at line 2)\n" + " protected class R0 {}\n" + " ^^\n" + "The abstract method foo in type R0 can only be defined by an abstract class\n" + "----------\n" + "2. ERROR in /P/SubTeam.java (at line 2)\n" + " protected class R0 {}\n" + " ^^\n" + "The type SubTeam.R0 must implement the inherited abstract method SubTeam.R0.foo()\n" + "----------\n" + "3. ERROR in /P/SubTeam.java (at line 2)\n" + " protected class R0 {}\n" + " ^^\n" + "The abstract method fooStatic in type R0 can only be defined by an abstract class\n" + "----------\n" + "4. ERROR in /P/SubTeam.java (at line 2)\n" + " protected class R0 {}\n" + " ^^\n" + "The type SubTeam.R0 must implement the inherited abstract method SubTeam.R0.fooStatic()\n" + "----------\n"); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testEmptyNestedExternalTeam() throws CoreException, InterruptedException { try {// w ww.j a va 2 s . c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); this.createFolder("/P/p"); String superTeamSourceString = "package p;\n" + "public team class SuperTeam {\n" + "}\n"; this.createFile("/P/p/SuperTeam.java", superTeamSourceString); String superMidString = "team package p.SuperTeam;\n" + "protected team class Mid {\n" + " protected class Inner {}\n" + "}\n"; this.createFolder("/P/p/SuperTeam"); this.createFile("/P/p/SuperTeam/Mid.java", superMidString); String subTeamSourceString = "package p;\n" + "public team class SubTeam extends SuperTeam {\n" + " protected class Mid2 {}\n" + "}\n"; this.createFile("/P/p/SubTeam.java", subTeamSourceString); this.createFolder("/P/p/SubTeam"); String subMidCompleteSourceString = "team package p/SubTeam;\n" + "protected team class Mid {\n" + " protected class Inner {}\n" + "}\n"; this.createFile("/P/p/SubTeam/Mid.java", subMidCompleteSourceString); project.build(IncrementalProjectBuilder.FULL_BUILD, null); String subMidSourceString = "team package p.SubTeam;\n" + "protected team class Mid {\n" + "}\n"; char[] subMidSourceChars = subMidSourceString.toCharArray(); this.problemRequestor.initialize(subMidSourceChars); ICompilationUnit icu = getCompilationUnit("/P/p/SubTeam/Mid.java").getWorkingCopy(this.wcOwner, null); assertNoProblem(subMidSourceChars, icu); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testBug400360() throws CoreException, InterruptedException { try {/*from w w w.j a va2s .c o m*/ // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); String allShapesSourceString = "public team class AllShapes {\n" + "\n" + " public abstract class Connector { }\n" + " public abstract class RectangularConnector extends Connector { }\n" + "}\n"; this.createFile("/P/AllShapes.java", allShapesSourceString); String chdSourceString = "public team class CompanyHierarchyDisplay {\n" + " \n" + " public final AllShapes _shapes = new AllShapes();\n" + " \n" + " public class Connection {\n" + " Connector<@_shapes> connShape;\n" + " }\n" + "}\n"; this.createFile("/P/CompanyHierarchyDisplay.java", chdSourceString); String versionASourceString = "public team class VersionA {\n" + " private final CompanyHierarchyDisplay _chd;\n" + " \n" + " public VersionA(CompanyHierarchyDisplay chd) {\n" + " _chd = chd;\n" + " }\n" + " \n" + " public class RectangularConnections playedBy Connection<@_chd> {\n" + " final AllShapes _shapesX = _chd._shapes;\n" + " @SuppressWarnings(\"decapsulation\")\n" + " void setShape(RectangularConnector<@_shapesX> shape) -> set Connector<@_chd._shapes> connShape;\n" + " }\n" + "}\n"; this.createFile("/P/VersionA.java", versionASourceString); char[] versionASourceChars = versionASourceString.toCharArray(); this.problemRequestor.initialize(versionASourceChars); ICompilationUnit unit = getCompilationUnit("/P/VersionA.java").getWorkingCopy(this.wcOwner, null); assertNoProblem(versionASourceChars, unit); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
public void testDecodeTeamAnchor() throws CoreException, InterruptedException { try {//from w ww.j a v a 2s .c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); p.setOption(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.ERROR); p.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); OTREContainer.initializeOTJProject(project); String teamSourceString = "public team class DomainObject {\n" + " public class Item{}\n" + " public void processItem(Item it) {}\n" + "}\n"; this.createFile("/P/DomainObject.java", teamSourceString); this.createFile("/P/ItemService.java", "public class ItemService<DomainObject theDO> {\n" + " public void processItem(Item<@theDO> item) { }\n" + "}\n"); project.build(IncrementalProjectBuilder.FULL_BUILD, null); String clientSourceString = "public class Client {\n" + " void foo(final DomainObject theDO) {\n" + " ItemService<@theDO> service = new ItemService<@theDO>();" + " Item<@theDO> myItem = new Item<@theDO>();\n" + " service.processItem(myItem);\n" + " }\n" + "}\n"; this.createFile("/P/Client.java", clientSourceString); char[] clientSourceChars = clientSourceString.toCharArray(); this.problemRequestor.initialize(clientSourceChars); ICompilationUnit unit = getCompilationUnit("/P/Client.java").getWorkingCopy(this.wcOwner, null); assertNoProblem(clientSourceChars, unit); } finally { deleteProject("P"); } }
From source file:org.eclipse.pde.ui.tests.ee.ExecutionEnvironmentTests.java
License:Open Source License
/** * Creates a plug-in project with a J2SE-1.4 execution environment. Validates that * compiler compliance settings and build path are correct. Modifies the compliance * options and then updates the class path again. Ensures that the enum and assert * identifier options get overwritten with minimum 'warning' severity. * /* www . j a v a 2 s .c om*/ * @throws Exception */ public void testMinimumComplianceOverwrite() throws Exception { try { IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("J2SE-1.4"); IJavaProject project = ProjectUtils.createPluginProject("j2se14.ignore", env); assertTrue("Project was not created", project.exists()); validateOption(project, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); validateOption(project, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); validateOption(project, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); validateSystemLibrary(project, JavaRuntime.newJREContainerPath(env)); // set to ignore assert/enum options project.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE); project.setOption(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE); // updating class path should increase severity to warning IPluginModelBase model = PluginRegistry.findModel(project.getProject()); UpdateClasspathJob job = new UpdateClasspathJob(new IPluginModelBase[] { model }); job.schedule(); job.join(); // re-validate options validateOption(project, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); validateOption(project, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); validateOption(project, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); } finally { deleteProject("j2se14.ignore"); } }
From source file:org.eclipse.pde.ui.tests.ee.ExecutionEnvironmentTests.java
License:Open Source License
/** * Creates a plug-in project with a J2SE-1.4 execution environment. Validates that * compiler compliance settings and build path are correct. Modifies the compliance * options and then updates the class path again. Ensures that the enum and assert * identifier options do not overwrite existing 'error' severity. * // w ww. j a v a2 s .com * @throws Exception */ public void testMinimumComplianceNoOverwrite() throws Exception { try { IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("J2SE-1.4"); IJavaProject project = ProjectUtils.createPluginProject("j2se14.error", env); assertTrue("Project was not created", project.exists()); validateOption(project, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); validateOption(project, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); validateOption(project, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); validateSystemLibrary(project, JavaRuntime.newJREContainerPath(env)); // set to ignore assert/enum options project.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); project.setOption(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); // updating class path should increase severity to warning IPluginModelBase model = PluginRegistry.findModel(project.getProject()); UpdateClasspathJob job = new UpdateClasspathJob(new IPluginModelBase[] { model }); job.schedule(); job.join(); // re-validate options validateOption(project, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); validateOption(project, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); validateOption(project, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); validateOption(project, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); validateOption(project, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); } finally { deleteProject("j2se14.error"); } }