CPD Results

The following document contains the results of PMD's CPD 6.48.0.

Duplications

File Line
de/funfried/netbeans/plugins/external/formatter/java/eclipse/EclipseJavaFormatterWrapper.java 70
de/funfried/netbeans/plugins/external/formatter/java/spring/SpringJavaFormatterWrapper.java 65
throws ConfigReadException, ProfileNotFoundException, CannotLoadConfigurationException, FormattingFailedException {
		if (code == null) {
			return null;
		}

		int codeLength = code.length();

		List<IRegion> regions = new ArrayList<>();
		if (changedElements == null) {
			regions.add(new Region(0, codeLength));
		} else if (!CollectionUtils.isEmpty(changedElements)) {
			for (Pair<Integer, Integer> changedElement : changedElements) {
				int length = (changedElement.getRight() - changedElement.getLeft()) + 1;
				if (length > codeLength) {
					length = codeLength;
				}

				regions.add(new Region(changedElement.getLeft(), length));
			}
		} else {
			// empty changed elements means nothing's left which can be formatted due to guarded sections
			return code;
		}
File Line
de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterWrapper.java 65
de/funfried/netbeans/plugins/external/formatter/java/palantir/PalantirJavaFormatterWrapper.java 57
}

		Collection<Range<Integer>> characterRanges = new ArrayList<>();
		if (changedElements == null) {
			characterRanges.add(Range.closedOpen(0, code.length()));
		} else if (!CollectionUtils.isEmpty(changedElements)) { // empty changed elements means nothing's left which can be formatted due to guarded sections
			for (Pair<Integer, Integer> changedElement : changedElements) {
				int start = changedElement.getLeft();
				int end = changedElement.getRight();

				if (start == end) {
					end++;
				}

				characterRanges.add(Range.open(start, end));
			}
		}

		if (changedElements == null || !CollectionUtils.isEmpty(changedElements)) {
			try {
				Formatter formatter = new Formatter(JavaFormatterOptions.builder().style(codeStyle).build());
File Line
de/funfried/netbeans/plugins/external/formatter/java/palantir/PalantirJavaFormatterService.java 176
de/funfried/netbeans/plugins/external/formatter/xml/jsoup/JsoupXmlFormatterService.java 152
}
		}

		return ret;
	}

	/**
	 * {@inheritDoc}
	 */
	@CheckForNull
	@Override
	public Boolean isExpandTabToSpaces(Document document) {
		if (document == null) {
			return null;
		}

		return isExpandTabToSpaces(document, Settings.getActivePreferences(document));
	}

	private Boolean isExpandTabToSpaces(Document document, Preferences preferences) {
		if (document == null || preferences == null) {
			return null;
		}

		Boolean ret = null;

		if (isUseFormatterIndentationSettings(preferences)) {
			ret = true;
		}

		return ret;
	}

	/**
	 * Returns {@code true} if using the formatter indentation settings from the external
	 * formatter is activated, otherwise {@code false}.
	 *
	 * @param prefs the {@link Preferences} where to check
	 *
	 * @return {@code true} if using the formatter indentation settings from the external
	 *         formatter is activated, otherwise {@code false}
	 */
	private boolean isUseFormatterIndentationSettings(Preferences prefs) {
		return prefs.getBoolean(Settings.ENABLE_USE_OF_INDENTATION_SETTINGS, true);
	}
File Line
de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterService.java 130
de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterService.java 181
public Integer getIndentSize(Document document) {
		if (document == null) {
			return null;
		}

		Integer ret = null;

		Preferences preferences = Settings.getActivePreferences(document);
		if (isUseFormatterIndentationSettings(preferences)) {
			String codeStylePref = preferences.get(GoogleJavaFormatterSettings.CODE_STYLE, JavaFormatterOptions.Style.GOOGLE.name());
			JavaFormatterOptions.Style codeStyle = JavaFormatterOptions.Style.valueOf(codeStylePref);
			if (JavaFormatterOptions.Style.GOOGLE.equals(codeStyle)) {
				// see: https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
				ret = 2;
			} else {
				// see: https://source.android.com/setup/contribute/code-style#use-spaces-for-indentation
				ret = 4;
			}
		}

		return ret;
	}

	/**
	 * {@inheritDoc}
	 */
	@CheckForNull
	@Override
	public Integer getRightMargin(Document document) {
File Line
de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/DBeaverFormatterService.java 50
de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/JSQLFormatterService.java 52
de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/SQLFormatterService.java 50
private final DBeaverFormatterWrapper formatter = new DBeaverFormatterWrapper();

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean format(StyledDocument document, SortedSet<Pair<Integer, Integer>> changedElements) throws BadLocationException, FormattingFailedException {
		if (!canHandle(document)) {
			throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported");
		}

		getFormatJob(document, changedElements).format();

		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<MimeType> getSupportedMimeTypes() {
		return Collections.singletonList(MimeType.SQL);
	}

	/**
	 * {@inheritDoc}
	 */
	@NonNull
	@Override
	public String getDisplayName() {
		return NbBundle.getMessage(DBeaverFormatterService.class, "FormatterName");