List of usage examples for org.eclipse.jdt.internal.core SourceType getCompilationUnit
ICompilationUnit getCompilationUnit();
null if this member is not declared in a compilation unit (for example, a binary type). From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java
License:Open Source License
public void testMapping1FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);//www .j a v a 2 s.c o m IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS); IMethodMapping mapping = callinMethodMappings[0]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); assertFalse("Mapping should not have signature", ((IMethodMapping) fromMemento).hasSignature()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java
License:Open Source License
public void testMapping5FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);//from w ww.j a v a2s.c om IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS); IMethodMapping mapping = callinMethodMappings[4]; assertNotNull(mapping); assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); ICallinMapping callinMapping = (ICallinMapping) fromMemento; IMethod[] boundBaseMethods = callinMapping.getBoundBaseMethods(); assertNotNull(boundBaseMethods); assertEquals(2, boundBaseMethods.length); assertEquals("baseMethod3", boundBaseMethods[0].getElementName()); assertEquals("baseMethod4", boundBaseMethods[1].getElementName()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java
License:Open Source License
public void testMapping7FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);//w w w . j a v a 2s . com IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS); IMethodMapping mapping = callinMethodMappings[6]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); assertTrue("Mapping should have signature", ((IMethodMapping) fromMemento).hasSignature()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java
License:Open Source License
public void testMapping1FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);/*from ww w. j a v a 2 s.c o m*/ IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS); IMethodMapping mapping = calloutMethodMappings[0]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); assertTrue("Mapping should have signature", ((IMethodMapping) fromMemento).hasSignature()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java
License:Open Source License
public void testMapping2FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);// w w w . ja v a 2s . com IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS); IMethodMapping mapping = calloutMethodMappings[1]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); assertFalse("Mapping should not have signature", ((IMethodMapping) fromMemento).hasSignature()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java
License:Open Source License
public void testMapping3FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);/*from w w w . j av a2 s.c o m*/ IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS); IMethodMapping mapping = calloutMethodMappings[2]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); ICalloutMapping mappingFromMemento = (ICalloutMapping) fromMemento; assertTrue("Mapping should have signature", mappingFromMemento.hasSignature()); assertTrue("Expecting 1 role parameter", mappingFromMemento.getRoleMethodHandle().getArgumentTypes().length == 1); assertTrue("Expecting 2 base parameters", mappingFromMemento.getBaseMethodHandle().getArgumentTypes().length == 2); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java
License:Open Source License
public void testMapping4FromMemento() throws JavaModelException { IRoleType roleOTElem = getRoleOTElem(); assertNotNull(roleOTElem);/*from ww w .j a va 2 s .com*/ IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS); IMethodMapping mapping = calloutMethodMappings[3]; assertNotNull(mapping); String token = mapping.getHandleIdentifier(); SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement(); IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner()); assertEquals("Elements should be equal", mapping, fromMemento); assertTrue("Element should exist", fromMemento.exists()); assertTrue("Expecting callout to field", fromMemento instanceof ICalloutToFieldMapping); ICalloutToFieldMapping mappingFromMemento = (ICalloutToFieldMapping) fromMemento; assertTrue("Mapping should have signature", mappingFromMemento.hasSignature()); assertFalse("Expecting no setter", mappingFromMemento.getBaseFieldHandle().isSetter()); }
From source file:org.springframework.ide.eclipse.quickfix.jdt.computers.ConfigurationLocationProposalComputer.java
License:Open Source License
@Override protected List<ICompletionProposal> computeCompletionProposals(SourceType type, String value, IAnnotation a, JavaContentAssistInvocationContext javaContext) throws JavaModelException { // }/*from ww w . j a v a 2s .co m*/ // @Override // protected List<ICompletionProposal> // computeCompletionProposals(SourceType type, LocationInformation // locationInfo, // Annotation annotation, JavaContentAssistInvocationContext // javaContext) throws JavaModelException { // // TODO Auto-generated method stub // return super.computeCompletionProposals(type, locationInfo, // annotation, javaContext); // } // @Override // protected List<ICompletionProposal> // computeCompletionProposals(SourceType type, IAnnotation annotation, // JavaContentAssistInvocationContext javaContext) throws // JavaModelException { // IMemberValuePair[] memberValuePairs = // annotation.getMemberValuePairs(); // for (IMemberValuePair memberValuePair : memberValuePairs) { // if ("locations".equals(memberValuePair.getMemberName()) || // "value".equals(memberValuePair.getMemberName())) { ITextViewer viewer = javaContext.getViewer(); if (viewer instanceof SourceViewer) { ICompilationUnit cu = javaContext.getCompilationUnit(); SourceViewer sourceViewer = (SourceViewer) javaContext.getViewer(); int invocationOffset = javaContext.getInvocationOffset(); AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0); ASTNode node = ((SourceRefElement) a).findNode(assistContext.getASTRoot()); if (node == null) { node = assistContext.getCoveredNode(); } if (!(a instanceof Annotation)) { return Collections.emptyList(); } Annotation annotation = (Annotation) a; LocationInformation locationInfo = null; if (node instanceof NormalAnnotation) { NormalAnnotation normalAnnotation = (NormalAnnotation) node; @SuppressWarnings("unchecked") List<MemberValuePair> pairs = normalAnnotation.values(); for (MemberValuePair pair : pairs) { Expression expression = pair.getValue(); if (expression instanceof StringLiteral) { locationInfo = getLocationInformation((StringLiteral) expression, javaContext); } } } else if (node instanceof SingleMemberAnnotation) { SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node; Expression expression = singleMemberAnnotation.getValue(); locationInfo = getLocationInformation((StringLiteral) expression, javaContext); } if (locationInfo == null) { return Collections.emptyList(); } Name typeName = annotation.getTypeName(); return getBeanProposals(javaContext, type.getCompilationUnit(), javaContext.getInvocationOffset(), typeName.getFullyQualifiedName(), typeName.getStartPosition(), typeName.getLength()); } // } // } return Collections.emptyList(); }