Skip to content

Commit

Permalink
Merge branch 'v0.14.x_bugfix' into v0.14.x
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Apr 8, 2015
2 parents 5b090f8 + e521040 commit f1a7f31
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public NamedResultContainer multiResultFixture(@FixtureParameter(name = "param")
return new NamedResultContainer(aParam, 100);
}

@FixtureMethod()
public TestEnum returnFixedEnum() {
return TestEnum.VALUE_ONE;
}

@FixtureMethod()
public TestEnum returnEnum(@FixtureParameter(name = "enum") TestEnum anEnum) {
return anEnum;
}

private void pause() {
try {
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ packagedef mypackage with
calldef extendedResult uses de.gebit.integrity.experiments.fixtures.ExtendedResultTestFixture#returnExtendedStuff
testdef extendedResultTest uses de.gebit.integrity.experiments.fixtures.ExtendedResultTestFixture#returnExtendedStuff

calldef returnEnumCall uses de.gebit.integrity.experiments.fixtures.AdditionFixture#returnEnum
testdef returnEnumTest uses de.gebit.integrity.experiments.fixtures.AdditionFixture#returnEnum

calldef returnFixedEnumCall uses de.gebit.integrity.experiments.fixtures.AdditionFixture#returnFixedEnum
testdef returnFixedEnumTest uses de.gebit.integrity.experiments.fixtures.AdditionFixture#returnFixedEnum


variable dummy initially 2

packageend
Expand Down
1 change: 1 addition & 0 deletions de.gebit.integrity.dsl.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Import-Package: org.apache.log4j,
org.eclipse.jdt.core.util,
org.eclipse.jdt.internal.core,
org.eclipse.jdt.launching,
org.eclipse.jdt.ui.text.java,
org.eclipse.jface.text.contentassist,
org.eclipse.jface.viewers,
org.eclipse.swt.graphics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.formatting.IWhitespaceInformationProvider;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.contentassist.IContentProposalPriorities;
import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher;
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
import org.eclipse.xtext.ui.editor.preferences.LanguageRootPreferencePage;
import org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;

import de.gebit.integrity.ui.contentassist.DSLContentProposalPriorities;
import de.gebit.integrity.ui.contentassist.IntegrityPrefixMatcher;
import de.gebit.integrity.ui.documentation.IntegrityEObjectDocumentationProvider;
import de.gebit.integrity.ui.documentation.IntegrityEObjectHoverProvider;
Expand Down Expand Up @@ -145,4 +147,12 @@ public Class<? extends IWhitespaceInformationProvider> bindIWhitespaceInformatio
return DSLWhitespaceInformationProvider.class;
}

/**
* Defines the {@link IContentProposalPriorities} implementation.
*
* @return
*/
public Class<? extends IContentProposalPriorities> bindContentProposalPriorities() {
return DSLContentProposalPriorities.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others.
* 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
*******************************************************************************/
package de.gebit.integrity.ui.contentassist;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.common.types.JvmEnumerationLiteral;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.ui.editor.contentassist.ContentProposalPriorities;

import com.google.common.base.CharMatcher;

/**
* A custom proposal priority implementation in order to adjust proposal priorities.
*
* @author Rene Schneider - initial API and implementation
*
*/
public class DSLContentProposalPriorities extends ContentProposalPriorities {

/**
* Priority for enumeration literals.
*/
private static final int ENUM_LITERAL_PRIORITY = 600;

/**
* Maximum score bonus awarded because of "distance". Distance is measured in dots required to reference the element
* in the shortest way - that is, after considering package imports. So if you need to write
* "anotherpackage.element" to access an element, it has a distance of one, while "element" would have a distance of
* zero and "outerpackage.anotherpackage.element" would be two.
*/
private static final int CROSS_REFERENCE_DISTANCE_BONUS_MAX = 10;

/**
* Bonus awarded to the distance score if the element is in the local suite.
*/
private static final int CROSS_REFERENCE_IN_LOCAL_SUITE_BONUS = 50;

/**
* Bonus awarded to the distance score if the element is in the local package.
*/
private static final int CROSS_REFERENCE_IN_LOCAL_PACKAGE_BONUS = 25;

@Override
protected void adjustPriority(ICompletionProposal aProposal, String aPrefix, int aPriority) {
super.adjustPriority(aProposal, aPrefix, aPriority);

if (aProposal instanceof IntegrityConfigurableCompletionProposal) {
IntegrityConfigurableCompletionProposal tempProposal = (IntegrityConfigurableCompletionProposal) aProposal;

EObject tempAdditionalInfo = tempProposal.getAdditionalProposalInfoObject();

// issue #84: enum literals should be prioritized
if (tempAdditionalInfo instanceof JvmEnumerationLiteral) {
tempProposal.setPriority(ENUM_LITERAL_PRIORITY);
}

// Only do the following if we have an element of our DSL model. Don't know any other way to find this out
// other than checking whether we NOT have a JVM element reference.
if (!(tempAdditionalInfo instanceof JvmIdentifiableElement)) {
// Prioritize primarily by "distance" to the local position. This is done by calculating a distance
// score (higher is better) and adding it to the priority.
int tempCrossReferenceDistance = CharMatcher.is('.').countIn(tempProposal.getReplacementString());
int tempCrossReferenceDistanceScore = CROSS_REFERENCE_DISTANCE_BONUS_MAX - tempCrossReferenceDistance;
if (tempCrossReferenceDistanceScore < 0) {
tempCrossReferenceDistanceScore = 0;
}

if (tempProposal.isReferencingObjectInLocalPackage()) {
if (tempProposal.isReferencingObjectInLocalSuite()) {
tempCrossReferenceDistanceScore += CROSS_REFERENCE_IN_LOCAL_SUITE_BONUS;
} else {
tempCrossReferenceDistanceScore += CROSS_REFERENCE_IN_LOCAL_PACKAGE_BONUS;
}
}

tempProposal.setPriority(tempProposal.getPriority() + tempCrossReferenceDistanceScore);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package de.gebit.integrity.ui.contentassist;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.internal.text.html.BrowserInformationControl;
import org.eclipse.jface.resource.JFaceResources;
Expand All @@ -25,9 +26,11 @@
import com.google.inject.Provider;

import de.gebit.integrity.dsl.CallDefinition;
import de.gebit.integrity.dsl.PackageDefinition;
import de.gebit.integrity.dsl.SuiteDefinition;
import de.gebit.integrity.dsl.TestDefinition;
import de.gebit.integrity.dsl.VariableOrConstantEntity;
import de.gebit.integrity.utils.IntegrityDSLUtil;

/**
* A context-aware configurable completion proposal. This proposal knows its content assist context and uses this in
Expand Down Expand Up @@ -59,6 +62,21 @@ public class IntegrityConfigurableCompletionProposal extends ConfigurableComplet
*/
private boolean useHtmlAdditionalProposalInfo;

/**
* The additional proposal info object. Stored here because the superclass one is private.
*/
private Object additionalProposalInfoObject;

/**
* The resolved {@link #additionalProposalInfoObject} is cached here.
*/
private EObject resolvedAdditionalProposalInfoObject;

/**
* The context resource. Stored here because the superclass one is private.
*/
private Resource proposalContextResource;

public void setUseHtmlAdditionalProposalInfo(boolean aUseHtmlAdditionalProposalInfoFlag) {
this.useHtmlAdditionalProposalInfo = aUseHtmlAdditionalProposalInfoFlag;
}
Expand Down Expand Up @@ -111,9 +129,45 @@ public EObject get() {
setReplacementString(tempReplacementStringParts[tempReplacementStringParts.length - 1]);
}

additionalProposalInfoObject = tempAdditionalProposalInfo;
super.setAdditionalProposalInfo(tempAdditionalProposalInfo);
}

@Override
public void setProposalContextResource(Resource aContextResource) {
proposalContextResource = aContextResource;
super.setProposalContextResource(aContextResource);
}

/**
* Returns the additional proposal info object, if possible. This only returns the plain object (but attempts to
* resolve it, if necessary).
*
* @return the object or null
*/
public EObject getAdditionalProposalInfoObject() {
if (resolvedAdditionalProposalInfoObject == null) {
EObject tempResult = null;
if (additionalProposalInfoObject instanceof EObject) {
tempResult = (EObject) additionalProposalInfoObject;
} else {
if (additionalProposalInfoObject instanceof Provider) {
Object tempObject = ((Provider<?>) additionalProposalInfoObject).get();
if (tempObject instanceof EObject) {
tempResult = (EObject) tempObject;
}
}
}
if (tempResult != null && tempResult.eIsProxy()) {
tempResult = EcoreUtil.resolve(tempResult, proposalContextResource);
}

resolvedAdditionalProposalInfoObject = tempResult;
}

return resolvedAdditionalProposalInfoObject;
}

private boolean requiresResolvingForContentAssist(EObject anObject) {
return (anObject instanceof TestDefinition || anObject instanceof CallDefinition);
}
Expand Down Expand Up @@ -141,4 +195,42 @@ public IInformationControl createInformationControl(Shell aParent) {
return super.getInformationControlCreator();
}
}

/**
* Checks whether the proposed element is in the "local" suite.
*
* @return
*/
public boolean isReferencingObjectInLocalSuite() {
if (getAdditionalProposalInfoObject() != null) {
SuiteDefinition tempContainingSuite = IntegrityDSLUtil.findUpstreamContainer(SuiteDefinition.class,
(EObject) getAdditionalProposalInfoObject());
if (tempContainingSuite != null) {
SuiteDefinition tempCurrentSuite = IntegrityDSLUtil.findUpstreamContainer(SuiteDefinition.class,
context.getCurrentModel());
return tempCurrentSuite == tempContainingSuite;
}
}

return false;
}

/**
* Checks whether the proposed element is in the "local" package.
*
* @return
*/
public boolean isReferencingObjectInLocalPackage() {
if (getAdditionalProposalInfoObject() != null) {
PackageDefinition tempContainingPackage = IntegrityDSLUtil.findUpstreamContainer(PackageDefinition.class,
(EObject) getAdditionalProposalInfoObject());
if (tempContainingPackage != null) {
PackageDefinition tempCurrentPackage = IntegrityDSLUtil.findUpstreamContainer(PackageDefinition.class,
context.getCurrentModel());
return tempCurrentPackage == tempContainingPackage;
}
}

return false;
}
}

0 comments on commit f1a7f31

Please sign in to comment.