Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

[eclipse/xtext#1679] ported xtend code to java #1442

Merged
merged 1 commit into from
Apr 13, 2020
Merged

[eclipse/xtext#1679] ported xtend code to java #1442

merged 1 commit into from
Apr 13, 2020

Conversation

cdietrich
Copy link
Member

[eclipse-xtext/xtext#1679] ported xtend code to java
Signed-off-by: Christian Dietrich [email protected]

@cdietrich cdietrich added this to the Release_2.22 milestone Apr 11, 2020
@cdietrich cdietrich requested review from szarnekow and tivervac April 11, 2020 18:27
@cdietrich cdietrich force-pushed the cd_idex2j branch 6 times, most recently from b1b15c5 to 3b85dbb Compare April 11, 2020 19:31
super("testlang");
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL

disposableRegistry.register(this);
}

private final Map<String, ExecutorService> instanceCache = Maps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do - private final Map<String, ExecutorService> instanceCache = new HashMap<>(3)

for (ExecutorService executorService : instanceCache.values()) {
executorService.shutdown();
}
this.instanceCache.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceCache.clear()

public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("imageIDs", imageIDs);
return b.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing the above code with something like return "imageID's :" + imageIDs.toString(), so that we can remove the reference to the ToStringBuilder type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wanted to keep the old impl for all of the toStrings


@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
Copy link
Contributor

@nbhusare nbhusare Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the reference to the ToStringBuilder if possible ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be refactored lated. i want to keep the current behaviour


public RenameContext(List<? extends RenameChange> changes, ResourceSet resourceSet,
IChangeSerializer changeSerializer, RefactoringIssueAcceptor issues) {
super();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove super()

private final boolean isFile;

public ResourceRelocationChange(final URI fromURI, final URI toURI, final boolean isFile) {
super();
Copy link
Contributor

@nbhusare nbhusare Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove super()


@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
Copy link
Contributor

@nbhusare nbhusare Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove reference to ToStringBuilder if possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to keep it as i want to keep the behaviour


def void afterBuild(List<IResourceDescription.Delta> deltas)
void afterBuild(List<IResourceDescription.Delta> deltas);

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL

if (crossLinkedEObject.eIsProxy()) {
return null;
}
IParseResult parseResult = resource.getParseResult();
Copy link
Contributor

@nbhusare nbhusare Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, we don't need this check here. The call to resolveCrossReferencedElementAt(...) on line 59 would return a null value if the XtextResource#getParseResult() is null.

disposableRegistry.register(this);
}

private final Map<String, ExecutorService> instanceCache = Maps.newHashMapWithExpectedSize(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a ConcurrentHashMap, otherwise the synchronization attempt in get(String) is completely flawed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? there is a second read in the synchronized

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread A calls get, sees nothing and enters the synchronize block, calls get again, sees still nothing and starts to put things into the map (this is not an atomic operation). While the map is being modified, Thread B calls get and sees an inconsistent map state. This can be avoided by using a ConcurrentHashMap + computeIfAbsent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry. can we do this in a separate PR. i am not able to think this properly through right now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

}

public ExecutorService get(String key) {
ExecutorService result = instanceCache.get(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceCache.computeIfAbsent(..)

private final List<String> imageIDs;

public AlternativeImageDescription(Iterable<String> imageIDs) {
this.imageIDs = ImmutableList.<String>copyOf(imageIDs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary type argument

}

public ResponseError toResponseError() {
final RefactoringIssueAcceptor.Severity maxSeverity = getMaximumSeverity();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation?

/**
* @since 2.22
*/
protected int getCodeBySeverity(final RefactoringIssueAcceptor.Severity maxSeverity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary final param

*/
public class ServerRefactoringIssueAcceptor implements RefactoringIssueAcceptor {
public static class Issue {
private RefactoringIssueAcceptor.Severity severity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary qualification I guess.

public RefactoringIssueAcceptor.Severity getMaximumSeverity() {
if (issues.size() > 0) {
ServerRefactoringIssueAcceptor.Issue minBySeverity = IterableExtensions.minBy(issues, (i) -> i.severity);
RefactoringIssueAcceptor.Severity severity = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary local var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the issues iterable is not empty, minBySeverity cannot be null.
Could be simplified to return IterableExtensions.minBy(..).severity


public RefactoringIssueAcceptor.Severity getMaximumSeverity() {
if (issues.size() > 0) {
ServerRefactoringIssueAcceptor.Issue minBySeverity = IterableExtensions.minBy(issues, (i) -> i.severity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use Ordering.min instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it as is :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants