Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType

The following examples show how to use org.eclipse.xtext.common.types.JvmDeclaredType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-extras   Source File: OverrideProposalUtil.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isCandidate(LightweightTypeReference type, IResolvedExecutable executable,
		IVisibilityHelper visibilityHelper) {
	JvmDeclaredType declaringType = executable.getDeclaration().getDeclaringType();
	if (type.getType() != declaringType && isVisible(executable, visibilityHelper)) {
		JvmExecutable rawExecutable = executable.getDeclaration();
		if (rawExecutable instanceof JvmOperation) {
			JvmOperation operation = (JvmOperation) rawExecutable;
			if (operation.isFinal() || operation.isStatic()) {
				return false;
			} else {
				if (type.getType() instanceof JvmGenericType && ((JvmGenericType) type.getType()).isInterface()) {
					return  declaringType instanceof JvmGenericType
							&& ((JvmGenericType) declaringType).isInterface() && !operation.isAbstract();
				} else {
					return true;
				}
			}
		} else {
			return true;
		}
	}
	return false;
}
 
Example 2
Source Project: sarl   Source File: AbstractNewSarlElementWizardPage.java    License: Apache License 2.0 6 votes vote down vote up
private static void createInfoCall(IExpressionBuilder builder, String message) {
	final JvmParameterizedTypeReference capacity = builder.newTypeRef(null, LOGGING_CAPACITY_NAME);
	final String objectType = Object.class.getName();
	final String objectArrayType = objectType + "[]"; //$NON-NLS-1$
	final JvmOperation infoMethod = Iterables.find(
			((JvmDeclaredType) capacity.getType()).getDeclaredOperations(), it -> {
			if (Objects.equals(it.getSimpleName(), "info") //$NON-NLS-1$
					&& it.getParameters().size() == 2) {
				final String type1 = it.getParameters().get(0).getParameterType().getIdentifier();
				final String type2 = it.getParameters().get(1).getParameterType().getIdentifier();
				return Objects.equals(objectType, type1) && Objects.equals(objectArrayType, type2);
			}
			return false;
		},
		null);
	if (infoMethod != null) {
		builder.setExpression("info(\"" + message + "\")"); //$NON-NLS-1$ //$NON-NLS-2$
		((XFeatureCall) builder.getXExpression()).setFeature(infoMethod);
	}
}
 
Example 3
protected void buildDispatchers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, final IXtendOutlineContext context) {
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    return Boolean.valueOf(this.dispatchHelper.isDispatcherFunction(it));
  };
  Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(inferredType.getDeclaredOperations(), _function);
  for (final JvmOperation dispatcher : _filter) {
    {
      final List<JvmOperation> dispatchCases = this.getDispatchCases(dispatcher, baseType, context);
      final IXtendOutlineContext dispatcherContext = this.xtendOutlineNodeBuilder.buildDispatcherNode(baseType, dispatcher, dispatchCases, context).markAsProcessed(dispatcher);
      for (final JvmOperation dispatchCase : dispatchCases) {
        EObject _elvis = null;
        XtendFunction _xtendFunction = this._iXtendJvmAssociations.getXtendFunction(dispatchCase);
        if (_xtendFunction != null) {
          _elvis = _xtendFunction;
        } else {
          _elvis = dispatchCase;
        }
        this.buildFeature(baseType, dispatchCase, _elvis, dispatcherContext).markAsProcessed(dispatchCase);
      }
    }
  }
}
 
Example 4
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) {
  final JvmExecutable executable = overridden.getDeclaration();
  builder.setContext(overrider);
  builder.setVisibility(overridden.getDeclaration().getVisibility());
  final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> {
    final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue());
    final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder();
    parameterBuilder.setName(declaredParameter.getSimpleName());
    parameterBuilder.setType(it);
    JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class);
    boolean _tripleNotEquals = (_findAnnotation != null);
    parameterBuilder.setExtensionFlag(_tripleNotEquals);
  };
  IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function);
  builder.setVarArgsFlag(executable.isVarArgs());
  builder.setExceptions(overridden.getResolvedExceptions());
}
 
Example 5
public void installStubs(Resource resource) {
	if (isInfoFile(resource)) {
		return;
	}
	CompilationUnit compilationUnit = getCompilationUnit(resource);
	ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			getCompilerOptions(resource), new DefaultProblemFactory());
	Parser parser = new Parser(problemReporter, true);
	CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, -1);
	CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
	if (result.types != null) {
		for (TypeDeclaration type : result.types) {
			ImportReference currentPackage = result.currentPackage;
			String packageName = null;
			if (currentPackage != null) {
				char[][] importName = currentPackage.getImportName();
				if (importName != null) {
					packageName = CharOperation.toString(importName);
				}
			}
			JvmDeclaredType jvmType = createType(type, packageName);
			resource.getContents().add(jvmType);
		}
	}
}
 
Example 6
/**
 * @since 2.18
 */
protected JvmOperation findCloseMethod(LightweightTypeReference resourceType) {
	// Find the real close method,
	// which is an operation without arguments.
	// There can only be one real close method.
	for(JvmType rawType: resourceType.getRawTypes()) {
		if (rawType instanceof JvmDeclaredType) {
			Iterable<JvmFeature> candidates = ((JvmDeclaredType) rawType).findAllFeaturesByName("close");
			for(JvmFeature candidate: candidates) {
				if (candidate instanceof JvmOperation
						&& ((JvmOperation) candidate).getParameters().isEmpty()) {
					return (JvmOperation) candidate;
				}
			}
		}
	}
	return null;
}
 
Example 7
Source Project: xtext-xtend   Source File: LinkingTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeclaredConstructor_01() throws Exception {
	XtendClass clazz = clazz(
			"class Foo { " +
			"  int i" +
			"  new(int i) { this.i = i }" +
			"}");
	assertEquals(2, clazz.getMembers().size());
	
	XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
	XAssignment assignment = (XAssignment) ((XBlockExpression)constructor.getExpression()).getExpressions().get(0);
	JvmField field = (JvmField) assignment.getFeature();
	assertEquals("i", field.getSimpleName());
	XFeatureCall target = (XFeatureCall) assignment.getAssignable();
	JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
	assertEquals("Foo", identifiableElement.getSimpleName());
	XFeatureCall value = (XFeatureCall) assignment.getValue();
	JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
	assertEquals("i", parameter.getSimpleName());
}
 
Example 8
public boolean isLocalTypeParameter(EObject context, JvmTypeParameter parameter) {
	if (context == parameter.getDeclarator()) 
		return true;
	if (context instanceof JvmOperation && ((JvmOperation) context).isStatic())
		return false;
	if (context instanceof JvmDeclaredType && ((JvmDeclaredType) context).isStatic())
		return false;
	JvmIdentifiableElement jvmElement = contextProvider.getNearestLogicalContainer(context);
	if (jvmElement != null) {
		return isLocalTypeParameter(jvmElement, parameter);
	}
	EObject container = context.eContainer();
	if (container == null) {
		return false;
	}
	return isLocalTypeParameter(container, parameter);
}
 
Example 9
Source Project: sarl   Source File: PyGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/** Generate the given object.
 *
 * @param behavior the behavior.
 * @param context the context.
 */
protected void _generate(SarlBehavior behavior, IExtraLanguageGeneratorContext context) {
	final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(behavior);
	final PyAppendable appendable = createAppendable(jvmType, context);
	final List<JvmTypeReference> superTypes;
	if (behavior.getExtends() != null) {
		superTypes = Collections.singletonList(behavior.getExtends());
	} else {
		superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Behavior.class, behavior));
	}
	final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(behavior).toString();
	if (generateTypeDeclaration(
			qualifiedName,
			behavior.getName(), behavior.isAbstract(), superTypes,
			getTypeBuilder().getDocumentation(behavior),
			true,
			behavior.getMembers(), appendable, context, (it, context2) -> {
			generateGuardEvaluators(qualifiedName, it, context2);
		})) {
		final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(behavior);
		writeFile(name, appendable, context);
	}
}
 
Example 10
protected void newMethodQuickfixes(LightweightTypeReference containerType, String name, /* @Nullable */ LightweightTypeReference returnType,
	List<LightweightTypeReference> argumentTypes, XAbstractFeatureCall call, JvmDeclaredType callersType,
	final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
	boolean isLocal = callersType == containerType.getType();
	boolean isStatic = isStaticAccess(call);
	boolean isAbstract = true;
	if(containerType.getType() instanceof JvmGenericType) {
		isAbstract = !((JvmGenericType) containerType.getType()).isInstantiateable();
	} else if(containerType.getType() instanceof JvmDeclaredType) {
		isAbstract = ((JvmDeclaredType) containerType.getType()).isAbstract();
	}
	if(containerType.getType() instanceof JvmDeclaredType) {
		JvmDeclaredType declaredType = (JvmDeclaredType) containerType.getType();
		newMethodQuickfix(declaredType, name, returnType, argumentTypes, isStatic, isAbstract, false, isLocal, call, issue, issueResolutionAcceptor);
	}
	if(!isLocal && !isStatic) {
		List<LightweightTypeReference> extensionMethodParameterTypes = newArrayList(argumentTypes);
		extensionMethodParameterTypes.add(0, containerType);
		newMethodQuickfix(callersType, name, returnType, extensionMethodParameterTypes, false, isAbstract, true, true, call, issue, issueResolutionAcceptor);
	}
}
 
Example 11
Source Project: xtext-extras   Source File: JvmModelGenerator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected String reassignThisType(final ITreeAppendable b, final JvmDeclaredType declaredType) {
  String _xblockexpression = null;
  {
    boolean _hasObject = b.hasObject("this");
    if (_hasObject) {
      final Object element = b.getObject("this");
      if ((element instanceof JvmDeclaredType)) {
        boolean _isLocal = ((JvmDeclaredType)element).isLocal();
        if (_isLocal) {
          b.declareVariable(element, "");
        } else {
          String _simpleName = ((JvmDeclaredType)element).getSimpleName();
          final String proposedName = (_simpleName + ".this");
          b.declareVariable(element, proposedName);
        }
      }
    }
    String _xifexpression = null;
    if ((declaredType != null)) {
      _xifexpression = b.declareVariable(declaredType, "this");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 12
Source Project: sarl   Source File: SARLJvmGenerator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void _internalDoGenerate(JvmDeclaredType type, IFileSystemAccess fsa) {
	if (DisableCodeGenerationAdapter.isDisabled(type)) {
		return;
	}
	final String qn = type.getQualifiedName();
	if (!Strings.isEmpty(qn)) {
		final String fn = qn.replace('.', '/') + ".java"; //$NON-NLS-1$
		final CharSequence content = generateType(type, this.generatorConfigProvider.get(type));
		final String outputConfigurationName;
		final Boolean isTest = this.resourceTypeDetector.isTestResource(type.eResource());
		if (isTest != null && isTest.booleanValue()) {
			outputConfigurationName = SARLConfig.TEST_OUTPUT_CONFIGURATION;
		} else {
			outputConfigurationName = IFileSystemAccess.DEFAULT_OUTPUT;
		}
		fsa.generateFile(fn, outputConfigurationName, content);
	}
}
 
Example 13
Source Project: xtext-extras   Source File: FeatureCallCompiler.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private boolean isPotentialJavaOperation(XAbstractFeatureCall featureCall) {
	if (featureCall.isOperation()) {
		return true;
	}
	if (featureCall.eClass() == XbasePackage.Literals.XMEMBER_FEATURE_CALL && featureCall.isStatic() && featureCall.isExtension() && featureCall.getActualArguments().size() == 2) {
		JvmIdentifiableElement feature = featureCall.getFeature();
		if (feature.eClass() == TypesPackage.Literals.JVM_OPERATION) {
			JvmDeclaredType declarator = ((JvmOperation) feature).getDeclaringType();
			if (IntegerExtensions.class.getName().equals(declarator.getIdentifier()) || LongExtensions.class.getName().equals(declarator.getIdentifier())) {
				String simpleName = feature.getSimpleName();
				if (simpleName.startsWith("bitwise") || simpleName.startsWith("shift")) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 14
Source Project: xtext-xtend   Source File: XtendValidator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private boolean contributesToConflict(JvmDeclaredType type, Set<JvmDeclaredType> involvedInterfaces,
		RecursionGuard<JvmDeclaredType> guard) {
	if (!guard.tryNext(type)) {
		return false;
	}
	if (involvedInterfaces.contains(type)) {
		return true;
	}
	for (JvmTypeReference typeRef : type.getExtendedInterfaces()) {
		JvmType rawType = typeRef.getType();
		if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, guard)) {
			return true;
		}
	}
	return false;
}
 
Example 15
public String generate(final Resource res, final JvmDeclaredType type) {
  String _xblockexpression = null;
  {
    res.eSetDeliver(false);
    EList<EObject> _contents = res.getContents();
    this.builder.<JvmDeclaredType>operator_add(_contents, type);
    res.eSetDeliver(true);
    final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    this.generator.doGenerate(res, fsa);
    Map<String, CharSequence> _textFiles = fsa.getTextFiles();
    String _replace = type.getIdentifier().replace(".", "/");
    String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace);
    String _plus_1 = (_plus + ".java");
    _xblockexpression = _textFiles.get(_plus_1).toString();
  }
  return _xblockexpression;
}
 
Example 16
Source Project: xtext-extras   Source File: JvmModelGenerator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    appendable.openScope();
    this.assignThisAndSuper(appendable, it, config);
    ITreeAppendable _xtrycatchfinallyexpression = null;
    try {
      _xtrycatchfinallyexpression = this.generateBody(it, appendable, config);
    } finally {
      appendable.closeScope();
    }
    _xblockexpression = _xtrycatchfinallyexpression;
  }
  return _xblockexpression;
}
 
Example 17
@Test
public void testBug337307() {
	String typeName = "ClassWithDefaultPackage";
	JvmType type = getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type instanceof JvmGenericType);
	assertEquals(typeName, type.getIdentifier());
	assertEquals(typeName, type.getQualifiedName());
	assertEquals(typeName, type.getSimpleName());
	assertNull(((JvmDeclaredType) type).getPackageName());
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
}
 
Example 18
Source Project: xtext-extras   Source File: DeprecationUtilTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected JvmOperation getOperation(JvmDeclaredType type, final String name) {
	JvmOperation operation = find(type.getDeclaredOperations(), new Predicate<JvmOperation>() {
		@Override
		public boolean apply(JvmOperation op) {
			return equal(name, op.getSimpleName());
		}
	});
	return operation;
}
 
Example 19
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) {
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name);
	EcoreUtil.resolveAll(type.eResource());
	EcoreUtil.resolveAll(type.eResource().getResourceSet());
	Assert.assertNotNull(name, type);
	
	if (accessAnnotations) {
		type.getAnnotations();
	}
	
	if (accessMembers) {
		EList<JvmMember> members = type.getMembers();
		for (JvmMember member : members) {
			if (accessAnnotations) {
				member.getAnnotations();
			}
			if (member instanceof JvmExecutable) {
				JvmExecutable operation = (JvmExecutable) member;
				if (accessParameter) {
					EList<JvmFormalParameter> parameters = operation.getParameters();
					for (JvmFormalParameter jvmFormalParameter : parameters) {
						if (accessAnnotations) {
							jvmFormalParameter.getAnnotations();
						}
						if (accessParameterNames) {
							jvmFormalParameter.getName();
						}
					}
				}
			}
		}
	}
	return type;
}
 
Example 20
Source Project: xtext-extras   Source File: JvmModelAssociator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T extends JvmDeclaredType> IPostIndexingInitializing<T> accept(T type) {
	if (type != null && type.eContainer() == null)
		resource.getContents().add(type);
	return (IPostIndexingInitializing<T>) new JvmPostIndexingInitializing(type);
}
 
Example 21
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes, ITypeReferenceOwner owner) {
	XExpression receiver = featureCall.getActualReceiver();
	if (receiver == null) {
		// static feature call
		JvmOperation operation = (JvmOperation) featureCall.getFeature();
		JvmDeclaredType declaringType = operation.getDeclaringType();
		return owner.newParameterizedTypeReference(declaringType);
	}
	return resolvedTypes.getActualType(receiver);
}
 
Example 22
@Override
public IXtendOutlineContext buildXtendNode(EObject modelElement, IXtendOutlineContext context) {
	IXtendOutlineContext resultedContext = super.buildXtendNode(modelElement, context);
	
	if (!context.isShowInherited()) {
		EclipseXtendOutlineContext eclipseXtendOutlineContext = (EclipseXtendOutlineContext) context;
		IOutlineNode parentNode = eclipseXtendOutlineContext.getParentNode();
		if (parentNode instanceof DocumentRootNode) {
			if (modelElement instanceof JvmDeclaredType) {
				JvmDeclaredType jvmDeclaredType = (JvmDeclaredType) modelElement;
				String packageName = jvmDeclaredType.getPackageName();
				if (packageName != null) {
					EObject rootElement = modelElement.eResource().getContents().get(0);
					if (rootElement instanceof XtendFile) {
						XtendFile xtendFile = (XtendFile) rootElement;
						String primaryPackage = xtendFile.getPackage();
						if (!packageName.equals(primaryPackage)) {
							EObjectNode typeNode = (EObjectNode) ((EclipseXtendOutlineContext) resultedContext).getParentNode();
							if (typeNode.getText() instanceof StyledString) {
								typeNode.setText(((StyledString) typeNode.getText()).append(new StyledString(" - "
										+ packageName, StyledString.QUALIFIER_STYLER)));
							}
						}
					}
				}
			}
		}
	}
	return resultedContext;
}
 
Example 23
protected Set<JvmFeature> getAllFeatures(LightweightTypeReference extensionType, IResolvedFeatures.Provider resolvedFeaturesProvider) {
	Set<JvmFeature> allFeatures = Sets.newLinkedHashSet();
	List<JvmType> types = extensionType.getRawTypes();
	for (JvmType type : types) {
		if (type instanceof JvmDeclaredType) {
			IResolvedFeatures resolvedFeatures = resolvedFeaturesProvider.getResolvedFeatures(type).getParameterizedView(extensionType);
			List<JvmFeature> features = resolvedFeatures.getAllFeatures();
			allFeatures.addAll(features);
		}
	}
	return allFeatures;
}
 
Example 24
Source Project: sarl   Source File: ScriptBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** Finalize the script.
 *
 * <p>The finalization includes: <ul>
 * <li>The import section is created.</li>
 * </ul>
 */
public void finalizeScript() {
	if (this.isFinalized) {
		throw new IllegalStateException("already finalized");
	}
	this.isFinalized = true;
	ImportManager concreteImports = new ImportManager(true);
	XImportSection importSection = getScript().getImportSection();
	if (importSection != null) {
		for (XImportDeclaration decl : importSection.getImportDeclarations()) {
			concreteImports.addImportFor(decl.getImportedType());
		}
	}
	for (String importName : getImportManager().getImports()) {
		JvmType type = findType(getScript(), importName).getType();
		if (concreteImports.addImportFor(type) && type instanceof JvmDeclaredType) {
			XImportDeclaration declaration = XtypeFactory.eINSTANCE.createXImportDeclaration();
			declaration.setImportedType((JvmDeclaredType) type);
			if (importSection == null) {
				importSection = XtypeFactory.eINSTANCE.createXImportSection();
				getScript().setImportSection(importSection);
			}
			importSection.getImportDeclarations().add(declaration);
		}
	}
	Resource resource = getScript().eResource();
	if (resource instanceof DerivedStateAwareResource) {
		((DerivedStateAwareResource) resource).discardDerivedState();
	}
}
 
Example 25
Source Project: xtext-xtend   Source File: DispatchHelper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected List<JvmOperation> getAllDispatchMethods(DispatchSignature signature, JvmDeclaredType type,
		ContextualVisibilityHelper contextualVisibilityHelper) {
	List<JvmOperation> allOperations = Lists.newArrayListWithExpectedSize(5);
	Iterable<JvmFeature> allFeatures = type.findAllFeaturesByName(signature.getDispatchCaseName());
	for(JvmFeature feature: allFeatures) {
		if (feature instanceof JvmOperation) {
			JvmOperation operationByName = (JvmOperation) feature;
			if (signature.isDispatchCase(operationByName) && contextualVisibilityHelper.isVisible(operationByName)) {
				allOperations.add(operationByName);
			}
		}
	}
	sort(allOperations);
	return allOperations;
}
 
Example 26
Source Project: xtext-xtend   Source File: NestedTypesScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
	if (type instanceof JvmDeclaredType) {
		JvmDeclaredType declarator = innermost;
		while(declarator != null) {
			if (declarator != type && EcoreUtil.isAncestor(declarator, type)) {
				doGetDescriptions(type, declarator, 0, result);
			}
			declarator = EcoreUtil2.getContainerOfType(declarator.eContainer(), JvmDeclaredType.class);
		}
	}
	super.doGetElements(type, result);
}
 
Example 27
@Test
public void testAnnotationType_01() throws Exception {
	String typeName = TestAnnotation.class.getName();
	JvmType type = getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type instanceof JvmAnnotationType);
	assertTrue(((JvmDeclaredType) type).isAbstract());
	assertFalse(((JvmDeclaredType) type).isStatic());
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
}
 
Example 28
Source Project: xtext-extras   Source File: OverrideHelper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected JvmOperation findOverriddenOperation(JvmOperation operation, LightweightTypeReference declaringType,
		TypeParameterSubstitutor<?> substitutor, ITypeReferenceOwner owner, IVisibilityHelper visibilityHelper) {
	int parameterSize = operation.getParameters().size();
	List<LightweightTypeReference> superTypes = declaringType.getSuperTypes();
	for(LightweightTypeReference superType: superTypes) {
		if (superType.getType() instanceof JvmDeclaredType) {
			JvmDeclaredType declaredSuperType = (JvmDeclaredType) superType.getType();
			if (declaredSuperType != null) {
				Iterable<JvmFeature> equallyNamedFeatures = declaredSuperType.findAllFeaturesByName(operation.getSimpleName());
				for(JvmFeature feature: equallyNamedFeatures) {
					if (feature instanceof JvmOperation) {
						JvmOperation candidate = (JvmOperation) feature;
						if (parameterSize == candidate.getParameters().size()) {
							if (visibilityHelper.isVisible(feature)) {
								boolean matchesSignature = true;
								for(int i = 0; i < parameterSize && matchesSignature; i++) {
									JvmFormalParameter parameter = operation.getParameters().get(i);
									JvmFormalParameter candidateParameter = candidate.getParameters().get(i);
									matchesSignature = isMatchesSignature(parameter, candidateParameter, substitutor, owner);
								}
								if (matchesSignature) {
									return candidate;
								}
							}
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 29
protected String createSimpleMemberLink(EObject type) {
	String label = "";
	if (type instanceof JvmDeclaredType)
		label = ((JvmDeclaredType) type).getSimpleName();
	else if (type instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) type;
		label = operation.getSimpleName();
		if (operation.getParameters().size() > 0) {
			label += "(...)";
		}
	}
	return createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, EcoreUtil.getURI(type), label);
}
 
Example 30
@Override
public boolean doCheckUniqueName(QualifiedName name, JvmDeclaredType type) {
	if (!super.doCheckUniqueName(name, type)) {
		return false;
	}

	try {
		return doCheckUniqueInProject(name, type);
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist()) {
			LOG.error(e.getMessage(), e);
		}
		return true;
	}
}